-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
67 lines (59 loc) · 2.87 KB
/
Copy pathDockerfile
File metadata and controls
67 lines (59 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# opencode-docker: run the OpenCode coding agent in a container, on top of the
# official image, with the pieces the official image leaves out.
#
# docker build -t opencode-docker .
# docker build --build-arg OPENCODE_VERSION=1.18.22 -t opencode-docker . # pin another release
#
# Design notes:
# - FROM the official ghcr.io/anomalyco/opencode image, pinned to a version tag.
# That image is Alpine + the musl OpenCode binary + ripgrep, running as root,
# with no git, no shell tools, and no persistence story. This layer adds those.
# - Runs as a non-root user (`opencode`, UID 1000 by default). Files the agent
# writes into the bind-mounted /workspace are owned by that UID.
# - Auto-update is off through the managed config tier (/etc/opencode), which
# OpenCode loads at the highest priority on Linux. A container should be
# rebuilt deliberately, not replace its own binary mid-session.
# - All OpenCode state (credentials, sessions, config, cache) lives under
# /home/opencode, so one volume on the home directory survives rebuilds.
ARG OPENCODE_VERSION=1.18.25
FROM ghcr.io/anomalyco/opencode:${OPENCODE_VERSION}
# Match your host UID/GID so files created in /workspace are yours
# (Linux hosts; Docker Desktop on macOS/Windows maps ownership automatically).
ARG UID=1000
ARG GID=1000
# git, bash, curl, ca-certificates: what a coding agent needs day to day.
# nftables, bind-tools, jq, sudo: only for the optional egress firewall
# (init-firewall.sh), inert unless the container starts with FIREWALL=1.
RUN apk add --no-cache \
bash \
ca-certificates \
curl \
git \
openssh-client \
nftables \
bind-tools \
jq \
sudo
RUN addgroup -g "$GID" opencode \
&& adduser -D -u "$UID" -G opencode -s /bin/bash opencode \
&& mkdir -p /workspace \
&& chown opencode:opencode /workspace
# Managed config: the highest-priority config tier on Linux (/etc/opencode),
# so no user or project config can turn the auto-updater back on inside the
# container. Everything else stays configurable the normal way.
COPY opencode.managed.json /etc/opencode/opencode.json
COPY init-firewall.sh entrypoint.sh /usr/local/bin/
RUN chmod 755 /usr/local/bin/init-firewall.sh /usr/local/bin/entrypoint.sh \
# `opencode web` tries to open a browser via xdg-open and stack-traces when
# there is none. A no-op xdg-open keeps the server logs clean.
&& printf '#!/bin/sh\nexit 0\n' > /usr/local/bin/xdg-open \
&& chmod 755 /usr/local/bin/xdg-open \
# The firewall needs root for nftables; this is the ONLY thing opencode may sudo.
# SETENV lets the entrypoint pass FIREWALL_ALLOW_DOMAINS through.
&& echo "opencode ALL=(root) NOPASSWD:SETENV: /usr/local/bin/init-firewall.sh" > /etc/sudoers.d/opencode-firewall \
&& chmod 440 /etc/sudoers.d/opencode-firewall
USER opencode
ENV HOME=/home/opencode
WORKDIR /workspace
ENTRYPOINT ["entrypoint.sh"]
CMD ["opencode"]