# syntax=docker/dockerfile:1 # Build the application from the checkout supplied as the Docker build context. # No published Codeman application image is required. FROM node:22-bookworm-slim AS build RUN apt-get update \ && apt-get install -y --no-install-recommends python3 make g++ \ && rm -rf /var/lib/apt/lists/* WORKDIR /opt/codeman COPY . . RUN npm ci \ && npm run build \ && npm prune --omit=dev --ignore-scripts \ && npm cache clean --force # The Docker CLI talks to the host daemon through the socket mounted by # docker/docker-compose.yaml. It does not run a Docker daemon in this container. FROM node:22-bookworm-slim ARG CODEMAN_RUNTIME_USER=opencode ARG PUID=1000 ARG PGID=1000 RUN apt-get update \ && apt-get install -y --no-install-recommends \ ca-certificates \ curl \ git \ openssh-client \ procps \ ripgrep \ tmux \ && rm -rf /var/lib/apt/lists/* # The Docker CLI, taken from the official image rather than Debian's `docker.io`. # That package is the full ENGINE: with --no-install-recommends it still pulls 15 # packages including containerd, runc, dmsetup and iptables, none of which a # client that only talks to a mounted socket can use. Measured on top of this # base image: `docker.io` costs 266 MB and ships Docker 20.10.24 (2023), while # these two files cost 108 MB and ship the current CLI (493 MB vs 335 MB total). # # The binaries are STATIC Go builds, so they run on this glibc image even though # the image they come from is Alpine (verified: `docker --version`, `docker ps` # and `docker build` all work here against a mounted host socket). # # buildx is copied on purpose. `scripts/build-agent-image.mjs` shells out to # `docker build` — Codeman auto-builds the agent image on the first Docker case — # and without the plugin that silently falls back to the CLASSIC builder, which # Docker has deprecated and will eventually drop. `docker-compose` is NOT copied: # Codeman never shells out to it. COPY --from=docker:29-cli /usr/local/bin/docker /usr/local/bin/docker COPY --from=docker:29-cli \ /usr/local/libexec/docker/cli-plugins/docker-buildx \ /usr/local/libexec/docker/cli-plugins/docker-buildx # Keep credentials out of the image. Users authenticate these CLIs at runtime # through Codeman sessions, and the configured host bind mount retains state. RUN npm install --global \ @anthropic-ai/claude-code \ @google/gemini-cli \ @openai/codex \ opencode-ai \ && npm cache clean --force # Keep the web server and every local Codeman session unprivileged. PUID and # PGID match the host-owned application-data directory mounted by Compose. The # requested GID may not exist in the base image, and a host UID such as 1000 may # already belong to the baked `node` account, so handle both cases explicitly. RUN set -eux; \ case "${PUID}" in ''|*[!0-9]*) echo "PUID must be numeric" >&2; exit 1;; esac; \ case "${PGID}" in ''|*[!0-9]*) echo "PGID must be numeric" >&2; exit 1;; esac; \ if [ "${PUID}" -eq 0 ]; then \ echo "PUID must identify an unprivileged account, not root" >&2; \ exit 1; \ fi; \ if ! getent group "${PGID}" >/dev/null; then \ groupadd --gid "${PGID}" codeman-runtime; \ fi; \ existing_user="$(getent passwd "${PUID}" | cut -d: -f1 || true)"; \ if [ -n "${existing_user}" ]; then \ usermod \ --login "${CODEMAN_RUNTIME_USER}" \ --gid "${PGID}" \ --home "/home/${CODEMAN_RUNTIME_USER}" \ --move-home \ --shell /bin/bash \ "${existing_user}"; \ else \ useradd \ --uid "${PUID}" \ --gid "${PGID}" \ --create-home \ --home-dir "/home/${CODEMAN_RUNTIME_USER}" \ --shell /bin/bash \ "${CODEMAN_RUNTIME_USER}"; \ fi WORKDIR /opt/codeman COPY --from=build /opt/codeman /opt/codeman ENV CODEMAN_PORT=3000 \ HOME=/home/${CODEMAN_RUNTIME_USER} \ NODE_ENV=production EXPOSE 3000 USER ${CODEMAN_RUNTIME_USER} CMD ["node", "dist/index.js", "web"]