Repository navigation
Expand file tree
/
Copy pathContainerfile
More file actions
383 lines (343 loc) · 15.8 KB
/
Copy pathContainerfile
File metadata and controls
383 lines (343 loc) · 15.8 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# check=skip=InvalidDefaultArgInFrom
# Agentainer image. Build with scripts/build.sh, which passes every pin in versions.env
# as a build argument. BASE_IMAGE has no default because its digest lives only in
# versions.env; the check directive above silences BuildKit's warning about that
# (docs.docker.com/build/checks).
#
# Each tool is installed in its own stage that declares only that tool's pins, and the
# final stage copies the result. A pin change rebuilds one stage. When the builder
# clamps file times to SOURCE_DATE_EPOCH (BuildKit rewrite-timestamp, Podman 5.6 or
# later) and the same builder version compresses the layers, an unchanged tool produces
# a byte-identical layer, so users do not download it again.
ARG BASE_IMAGE
# The base image has no CA bundle and snapshot.ubuntu.com is https. Only the bundle
# leaves this stage; every package in the final image comes from the snapshot.
FROM ${BASE_IMAGE} AS certs
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates
# Download tools for the tool stages. Every file they download is checked against a
# pin, so the versions of these build-only packages do not reach the image.
FROM ${BASE_IMAGE} AS fetch
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
ca-certificates curl xz-utils python3-minimal \
&& rm -rf /var/lib/apt/lists/*
COPY build/fetch.sh build/install-tool.sh /usr/local/lib/agentainer-build/
FROM fetch AS go
ARG TARGETARCH
ARG GO_VERSION
ARG GO_SHA256_AMD64
ARG GO_SHA256_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh go
FROM fetch AS rust
ARG TARGETARCH
ARG RUSTUP_VERSION
ARG RUSTUP_SHA256_AMD64
ARG RUSTUP_SHA256_ARM64
ARG RUST_VERSION
ARG RUST_MANIFEST_SHA256
RUN bash /usr/local/lib/agentainer-build/install-tool.sh rust
FROM fetch AS yq
ARG TARGETARCH
ARG YQ_VERSION
ARG YQ_SHA256_AMD64
ARG YQ_SHA256_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh yq
FROM fetch AS gh
ARG TARGETARCH
ARG GH_VERSION
ARG GH_SHA256_AMD64
ARG GH_SHA256_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh gh
FROM fetch AS uv
ARG TARGETARCH
ARG UV_VERSION
ARG UV_SHA256_AMD64
ARG UV_SHA256_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh uv
FROM fetch AS trivy
ARG TARGETARCH
ARG TRIVY_VERSION
ARG TRIVY_SHA256_AMD64
ARG TRIVY_SHA256_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh trivy
FROM fetch AS gosec
ARG TARGETARCH
ARG GOSEC_VERSION
ARG GOSEC_SHA256_AMD64
ARG GOSEC_SHA256_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh gosec
FROM fetch AS gitleaks
ARG TARGETARCH
ARG GITLEAKS_VERSION
ARG GITLEAKS_SHA256_AMD64
ARG GITLEAKS_SHA256_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh gitleaks
FROM fetch AS containerssh-agent
ARG TARGETARCH
ARG CONTAINERSSH_AGENT_VERSION
ARG CONTAINERSSH_AGENT_SHA256_AMD64
ARG CONTAINERSSH_AGENT_SHA256_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh containerssh-agent
FROM fetch AS ruff
ARG TARGETARCH
ARG RUFF_VERSION
ARG RUFF_SHA256_AMD64
ARG RUFF_SHA256_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh ruff
FROM fetch AS abtop
ARG TARGETARCH
ARG ABTOP_VERSION
ARG ABTOP_SHA256_AMD64
ARG ABTOP_SHA256_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh abtop
FROM fetch AS golangci-lint
ARG TARGETARCH
ARG GOLANGCI_LINT_VERSION
ARG GOLANGCI_LINT_SHA256_AMD64
ARG GOLANGCI_LINT_SHA256_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh golangci-lint
FROM fetch AS tea
ARG TARGETARCH
ARG TEA_VERSION
ARG TEA_SHA256_AMD64
ARG TEA_SHA256_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh tea
FROM fetch AS kubectl
ARG TARGETARCH
ARG KUBECTL_VERSION
ARG KUBECTL_SHA256_AMD64
ARG KUBECTL_SHA256_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh kubectl
FROM fetch AS helm
ARG TARGETARCH
ARG HELM_VERSION
ARG HELM_SHA256_AMD64
ARG HELM_SHA256_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh helm
FROM fetch AS awscli
ARG TARGETARCH
ARG AWSCLI_VERSION
ARG AWSCLI_SHA256_AMD64
ARG AWSCLI_SHA256_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh awscli
FROM fetch AS claude
ARG TARGETARCH
ARG CLAUDE_CODE_VERSION
ARG CLAUDE_CODE_SHA256_AMD64
ARG CLAUDE_CODE_SHA256_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh claude
FROM fetch AS codex
ARG TARGETARCH
ARG CODEX_VERSION
ARG CODEX_SHA256_AMD64
ARG CODEX_SHA256_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh codex
FROM fetch AS node
ARG TARGETARCH
ARG NODE_VERSION
ARG NODE_SHA256_AMD64
ARG NODE_SHA256_ARM64
# node links libatomic.so.1, which the final image gets from apt-packages.txt. This install
# comes from the live archive only for the node --version check in this stage and is not
# copied into the image.
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends libatomic1 \
&& rm -rf /var/lib/apt/lists/*
RUN bash /usr/local/lib/agentainer-build/install-tool.sh node
FROM fetch AS agy
ARG TARGETARCH
ARG AGY_URL_AMD64
ARG AGY_URL_ARM64
ARG AGY_SHA512_AMD64
ARG AGY_SHA512_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh agy
FROM fetch AS opencode
ARG TARGETARCH
ARG OPENCODE_VERSION
ARG OPENCODE_INTEGRITY_AMD64
ARG OPENCODE_INTEGRITY_ARM64
RUN bash /usr/local/lib/agentainer-build/install-tool.sh opencode
FROM fetch AS unslop
ARG UNSLOP_COMMIT
ARG UNSLOP_SHA256
ARG UNSLOP_LICENSE_SHA256
COPY build/install-unslop.sh /usr/local/lib/agentainer-build/install-unslop.sh
RUN sh /usr/local/lib/agentainer-build/install-unslop.sh
FROM ${BASE_IMAGE}
ARG BASE_IMAGE
ARG TARGETARCH
ARG AGENT_UID=1000
ARG AGENT_GID=1000
# Podman honours SHELL only with --format docker, which scripts/build.sh passes.
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
# Stops the build unless RUN steps use bash with errexit and pipefail.
RUN [ -n "${BASH_VERSION:-}" ] && [[ $- == *e* ]] && set -o | grep -Eq '^pipefail[[:space:]]+on' \
&& mkdir -p /usr/local/share/agentainer \
&& echo "bash ${BASH_VERSION} errexit pipefail" > /usr/local/share/agentainer/build-shell.txt
COPY build/apt-packages.txt build/check-apt-snapshot.py build/apt-install.sh /tmp/agentainer-build/
# apt packages from the pinned Ubuntu snapshot.
# - Both architectures use archive.ubuntu.com: the arm64 image defaults to
# ports.ubuntu.com, which the snapshot service does not cover, while
# archive.ubuntu.com serves resolute arm64 and has snapshots.
# - A "Snapshot: <ID>" field in each source (apt sources.list(5)) pins apt.
# - upgrade brings the base image's own packages to their snapshot versions.
# Always-Include-Phased-Updates makes upgrades take the same (newest) versions
# that fresh installs already get, instead of deferring phased ones
# (apt_preferences(5), "Phased Updates").
# - The Chromium libraries and fonts come from Playwright v1.64.1,
# packages/playwright-core/src/server/registry/nativeDeps.ts, entry 'ubuntu26.04-x64'
# (its "chromium" and "tools" lists; xvfb is left out). The 'ubuntu26.04-arm64'
# entry copies the same lists. The browsers themselves are
# not in the image.
# - check-apt-snapshot.py fails the build if any installed version is not in the snapshot.
# - Failed indexes and archives get five retries. update fails if any index is
# unavailable, so installation cannot continue with missing package lists
# (apt-get(8), --error-on=any; apt.conf(5), Acquire::Retries).
# - The apt and dpkg logs hold build times and are removed.
# - build/apt-install.sh does the install. If a snapshot step fails and APT_FALLBACK=archive,
# it installs from archive.ubuntu.com instead and says so in a warning. Either way it writes
# /usr/local/share/agentainer/apt-source ("snapshot <ID>" or "archive-fallback <date> ...").
# On the fallback path a version outside the snapshot does not fail the build.
ARG APT_SNAPSHOT
# "archive" lets the build fall back to archive.ubuntu.com when the snapshot fails.
# scripts/build.sh sets it for every build it runs. Empty or any other value is strict, which
# the release build uses: it never falls back.
ARG APT_FALLBACK=
# The bootstrap bundle is available only during this RUN, outside final image layers.
# https://docs.docker.com/reference/dockerfile/#run---mounttypebind
RUN --mount=type=bind,from=certs,source=/etc/ssl/certs/ca-certificates.crt,target=/tmp/agentainer-build/ca.crt \
APT_SNAPSHOT="${APT_SNAPSHOT}" APT_FALLBACK="${APT_FALLBACK}" sh /tmp/agentainer-build/apt-install.sh
# Debian names these binaries fdfind and batcat (their package file lists).
# ping ships with the cap_net_raw file capability, which fails under runtimes that
# drop NET_RAW (Podman's default, the Kubernetes example). Without it, ping uses an
# unprivileged ICMP socket, allowed by the net.ipv4.ping_group_range sysctl that the
# launcher and the pod spec set.
# The ubuntu:26.04 base image ships Canonical's Pebble service manager in
# /usr/bin/pebble, owned by no package. Nothing here uses it, and its Go runtime
# adds scanner findings.
RUN ln -s /usr/bin/fdfind /usr/local/bin/fd \
&& ln -s /usr/bin/batcat /usr/local/bin/bat \
&& python3 -c 'import os; os.removexattr("/usr/bin/ping", "security.capability")' \
&& rm -rf /usr/bin/pebble /var/lib/pebble
# Renames the base image's ubuntu user (UID 1000) to agent. With other IDs, reuses a
# group that already has the GID (for example 20, which is "dialout" in Ubuntu and
# "staff" on macOS).
RUN if [ "${AGENT_UID}" = 1000 ] && [ "${AGENT_GID}" = 1000 ]; then \
groupmod -n agent ubuntu \
&& usermod -l agent -d /home/agent -m -c Agentainer -G "" ubuntu; \
else \
userdel -r ubuntu 2>/dev/null || true; \
getent group "${AGENT_GID}" >/dev/null || groupadd -g "${AGENT_GID}" agent; \
useradd -m -u "${AGENT_UID}" -g "${AGENT_GID}" -s /bin/bash -c Agentainer agent; \
fi \
&& printf 'agent ALL=(ALL) NOPASSWD:ALL\n' > /etc/sudoers.d/agent \
&& chmod 0440 /etc/sudoers.d/agent \
&& install -d -o agent -g "${AGENT_GID}" /workspace
ENV LANG=C.UTF-8
COPY --from=go /usr/local/go /usr/local/go
COPY --from=rust /opt/rustup /opt/rustup
COPY --from=rust /opt/cargo /opt/cargo
COPY --from=yq /usr/local/bin/yq /usr/local/bin/yq
COPY --from=gh /usr/local/bin/gh /usr/local/bin/gh
COPY --from=uv /usr/local/bin/uv /usr/local/bin/uvx /usr/local/bin/
COPY --from=ruff /usr/local/bin/ruff /usr/local/bin/ruff
COPY --from=trivy /usr/local/bin/trivy /usr/local/bin/trivy
COPY --from=gosec /usr/local/bin/gosec /usr/local/bin/gosec
COPY --from=gitleaks /usr/local/bin/gitleaks /usr/local/bin/gitleaks
COPY --from=containerssh-agent /usr/local/bin/containerssh-agent /usr/local/bin/containerssh-agent
COPY --from=abtop /usr/local/bin/abtop /usr/local/bin/abtop
COPY --from=golangci-lint /usr/local/bin/golangci-lint /usr/local/bin/golangci-lint
COPY --from=tea /usr/local/bin/tea /usr/local/bin/tea
COPY --from=kubectl /usr/local/bin/kubectl /usr/local/bin/kubectl
COPY --from=helm /usr/local/bin/helm /usr/local/bin/helm
COPY --from=awscli /usr/local/aws-cli /usr/local/aws-cli
COPY --from=claude /usr/local/bin/claude /usr/local/bin/claude
COPY --from=codex /opt/codex /opt/codex
COPY --from=node /opt/node /opt/node
COPY --from=agy /usr/local/bin/agy /usr/local/bin/agy
COPY --from=opencode /usr/local/bin/opencode /usr/local/bin/opencode
COPY --from=unslop /usr/local/share/agentainer/skills/unslop /usr/local/share/agentainer/skills/unslop
ENV RUSTUP_HOME=/opt/rustup \
GOTOOLCHAIN=local \
PATH=/usr/local/go/bin:/opt/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
COPY versions.env /usr/local/share/agentainer/versions.env
COPY build/write-versions-json.py /tmp/agentainer-build/
# COPY keeps each file's mode from the build context, so a build host with umask 077
# would make /etc 0700 and the seed files 0600. rootfs is staged first and every path
# in it gets a fixed mode before it is copied to /: directories 0755, commands in
# usr/local/bin 0755, other files 0644. The entrypoint sources its steps, so they do
# not need the execute bit. Paths that rootfs does not contain keep their modes.
COPY rootfs/ /tmp/agentainer-build/rootfs/
RUN cd /tmp/agentainer-build/rootfs \
&& find . -type d -exec chmod 0755 {} + \
&& find . -type f -exec chmod 0644 {} + \
&& find usr/local/bin -type f -exec chmod 0755 {} + \
&& find . -mindepth 1 -maxdepth 1 -exec cp -a {} / \; \
&& cd / \
&& rm -rf /tmp/agentainer-build/rootfs \
&& ln -s /opt/codex/bin/codex /usr/local/bin/codex \
&& ln -s /opt/node/bin/node /usr/local/bin/node \
&& ln -s /usr/local/bin/containerssh-agent /usr/bin/containerssh-agent \
&& ln -s /opt/node/bin/npm /usr/local/bin/npm \
&& ln -s /opt/node/bin/npx /usr/local/bin/npx \
&& ln -s /usr/local/aws-cli/v2/current/bin/aws /usr/local/bin/aws \
&& ln -s /usr/local/aws-cli/v2/current/bin/aws_completer /usr/local/bin/aws_completer \
&& test -x /usr/local/bin/codex \
&& /usr/local/bin/aws --version >/dev/null \
&& test -x /usr/local/bin/node \
&& /usr/local/bin/node --version >/dev/null \
&& test -x /usr/local/bin/agentainer-entrypoint \
&& python3 /tmp/agentainer-build/write-versions-json.py
ARG IMAGE_VERSION=dev
ENV AGENTAINER_IMAGE_VERSION="${IMAGE_VERSION}"
ARG VCS_REF=unknown
ARG BUILD_DATE
LABEL org.opencontainers.image.version="${IMAGE_VERSION}" \
org.opencontainers.image.revision="${VCS_REF}" \
org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.title="Agentainer" \
org.opencontainers.image.description="Claude Code, Codex, Antigravity CLI and OpenCode in one container" \
org.opencontainers.image.source="https://github.com/chadmayfield/agentainer" \
org.opencontainers.image.base.name="${BASE_IMAGE}" \
io.github.chadmayfield.agentainer.versions="/etc/agentainer/versions.json"
# The Claude Playwright plugin runs `npx @playwright/mcp@latest` with no arguments (its
# .mcp.json), which defaults to the chrome channel. @playwright/mcp reads
# PLAYWRIGHT_MCP_BROWSER as the --browser option (the --browser row of its CLI options
# table), and chromium selects the Playwright-managed build.
ENV DISABLE_UPDATES=1 \
AGY_CLI_DISABLE_AUTO_UPDATE=true \
OPENCODE_DISABLE_AUTOUPDATE=1 \
NPM_CONFIG_UPDATE_NOTIFIER=false \
CLAUDE_CODE_NONBLOCKING_STDOUT=1 \
CLAUDE_CODE_TMUX_TRUECOLOR=1 \
PLAYWRIGHT_MCP_BROWSER=chromium
# Named volumes copy the image's /home/agent on first use, so it carries the same
# shell defaults the entrypoint seeds into an empty PVC.
RUN install -m 0644 -o agent -g "${AGENT_GID}" /etc/agentainer/home/.profile /home/agent/.profile \
&& install -m 0644 -o agent -g "${AGENT_GID}" /etc/agentainer/home/.bashrc /home/agent/.bashrc \
&& rm -rf /tmp/agentainer-build \
&& install -d -o agent -g "${AGENT_GID}" /var/lib/agentainer /var/lib/agentainer/tools \
&& install -d /etc/agentainer/home /etc/agentainer/seed
# Tools that agents install go under /var/lib/agentainer/active, a per-container symlink
# that the entrypoint points at the ephemeral or persistent root. These are static ENV
# values because exec sessions do not inherit variables that PID 1 exports.
ENV AGENTAINER_TOOLS=ephemeral \
NPM_CONFIG_PREFIX=/var/lib/agentainer/active/npm \
CARGO_HOME=/var/lib/agentainer/active/cargo \
CARGO_INSTALL_ROOT=/var/lib/agentainer/active \
GOPATH=/var/lib/agentainer/active/go \
GOBIN=/var/lib/agentainer/active/bin \
UV_TOOL_DIR=/var/lib/agentainer/active/uv \
UV_TOOL_BIN_DIR=/var/lib/agentainer/active/bin \
PIPX_HOME=/var/lib/agentainer/active/pipx \
PIPX_BIN_DIR=/var/lib/agentainer/active/bin \
PYTHONUSERBASE=/var/lib/agentainer/active/python \
PATH=/usr/local/go/bin:/opt/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/lib/agentainer/active/bin:/var/lib/agentainer/active/npm/bin:/var/lib/agentainer/active/python/bin
USER agent
WORKDIR /workspace
HEALTHCHECK --interval=30s --timeout=5s --start-period=180s --retries=3 \
CMD ["/usr/local/bin/agentainer-healthcheck"]
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/agentainer-entrypoint"]
CMD ["sleep", "infinity"]