GitNexus/.devcontainer/Dockerfile
Gergő Magyar b3b3ec0471
fix(devcontainer): trust host CA during image builds (#4305)
* fix(devcontainer): trust host CA during image builds

* fix(devcontainer): verify installers and repair ARM64 setup

* fix(devcontainer): address remaining SonarCloud findings

* fix(devcontainer): simplify npm subprocess output option
2026-11-29 18:11:03 +00:00

124 lines
6 KiB
Docker

# syntax=docker/dockerfile:1
# Base image: Microsoft's TypeScript+Node devcontainer image. It works on both
# linux/amd64 and linux/arm64, gets monthly security patches, and ships the
# non-root `node` user (UID 1000, i.e. user ID 1000), zsh + Oh My Zsh, eslint
# global, and the `gh` CLI.
#
# We pin the image by digest, not by tag. That way a silent upstream retag can't
# change the build under us. This matches the Dockerfile.cli /
# gitnexus/Dockerfile.test convention and issue #1451.
#
# We pin it as a bare `name@digest` with NO `:tag` prefix on purpose. The
# production Dockerfiles use plain `docker build`, but this one is built by
# `@devcontainers/cli` / the VS Code Dev Containers resolver. That resolver's
# image-name parser rejects the combined `name:tag@sha256:...` form.
#
# The digest below is for `5.2.3-22-trixie` (Node 22.23.3). Workspace
# dependencies require at least Node 22.22.2 on the Node 22 line. It is the
# multi-arch manifest-list digest, so it still picks the right platform.
# Debian 13's libstdc++ supplies GLIBCXX_3.4.31, required by the packaged
# tree-sitter runtime. Debian 12's runtime is too old even with g++ installed.
# To refresh it when bumping the readable tag, run:
# docker buildx imagetools inspect \
# mcr.microsoft.com/devcontainers/typescript-node:5.2.3-22-trixie \
# --format '{{json .Manifest.Digest}}'
FROM mcr.microsoft.com/devcontainers/typescript-node@sha256:e17cfac65d32af8e488fb00ee7b51b1e508b21958c05c8b652224a1f739deb08
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# Bun's release version is pinned. The four official installer scripts are
# pinned by SHA-256 below.
ARG BUN_VERSION
ARG TZ=UTC
ARG USERNAME=node
ARG INSTALL_BROWSER_DEPS=false
ARG PLAYWRIGHT_VERSION
# Copy the build-only ARGs into runtime ENV so shells and lifecycle scripts can
# read them. We deliberately do not set CLAUDE_CONFIG_DIR here. Its one true
# value lives in devcontainer.json `containerEnv`, and the runtime value wins
# anyway.
ENV BUN_VERSION=${BUN_VERSION} \
BUN_INSTALL=/home/${USERNAME}/.bun \
TZ=${TZ} \
DEVCONTAINER=true \
POWERLEVEL9K_DISABLE_GITSTATUS=true
# Native build toolchain that gitnexus/postinstall needs. It compiles
# tree-sitter native bindings, the vendored Dart/Proto/Swift grammars, and the
# @ladybugdb/core N-API addon (a native Node add-on). python3, make, and g++ are
# required; libstdc++6 provides the C++ runtime for shipped native prebuilds.
# util-linux supplies findmnt/mount for the 9p helper; the remaining diagnostic
# tools support investigating process, memory and filesystem delays.
# This mirrors the apt block in the existing Dockerfile.cli /
# gitnexus/Dockerfile.test images.
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
python3 make g++ libstdc++6 git curl ca-certificates bash unzip util-linux procps lsof strace time jq ripgrep \
&& rm -rf /var/lib/apt/lists/*
# UI profile: install OS dependencies at image-build time as root. Runtime
# browser downloads use the project's locked Playwright and a persistent volume.
COPY build-ca.sh /usr/local/share/gitnexus-devcontainer/build-ca.sh
RUN --mount=type=cache,target=/root/.npm \
--mount=type=secret,id=NODE_EXTRA_CA_CERTS,uid=1000 \
if [ "${INSTALL_BROWSER_DEPS}" = true ]; then \
source /usr/local/share/gitnexus-devcontainer/build-ca.sh \
&& test -n "${PLAYWRIGHT_VERSION}" \
&& npm exec --yes --package="@playwright/test@${PLAYWRIGHT_VERSION}" -- playwright install-deps chromium \
&& rm -rf /var/lib/apt/lists/*; \
fi
COPY bootstrap-native.cjs /usr/local/share/gitnexus-devcontainer/bootstrap-native.cjs
# Create and chown the named-volume mount points (~/.npm, ~/.local,
# /commandhistory) up front. That way an empty volume inherits `node:node`
# ownership the first time it is mounted. post-create.sh handles ownership on
# the CLI config volumes (~/.claude, ~/.codex, ~/.cursor), including reused ones.
RUN mkdir -p \
/home/${USERNAME}/.npm \
/home/${USERNAME}/.local/bin \
/commandhistory \
&& chown -R ${USERNAME}:${USERNAME} \
/home/${USERNAME}/.npm \
/home/${USERNAME}/.local \
/commandhistory
USER ${USERNAME}
# Native CLI installers use this directory for their launchers.
ENV PATH=/home/${USERNAME}/.local/bin:${BUN_INSTALL}/bin:${PATH}
# Verify the official installers before executing them. Claude Code, Codex,
# and Cursor select the current native release. Bun receives its release tag.
# Keep the standalone Codex package seed outside ~/.codex so post-create.sh
# can restore it when the runtime config volume hides the image's package.
RUN --mount=type=secret,id=NODE_EXTRA_CA_CERTS,uid=1000 \
source /usr/local/share/gitnexus-devcontainer/build-ca.sh \
&& installer_dir=$(mktemp -d) \
&& cd "$installer_dir" \
&& curl --proto '=https' --proto-redir '=https' --fail-early -fsSL --retry 3 --max-time 120 \
https://claude.ai/install.sh -o claude.sh \
https://chatgpt.com/codex/install.sh -o codex.sh \
https://cursor.com/install -o cursor.sh \
https://bun.sh/install -o bun.sh \
&& printf '%s\n' \
'2c5506d110560bf618bbe88f678f2c2a0047c86a9c6585fc84976120b1de0b44 claude.sh' \
'b698d8eb50c0fbe0214ea57b5bf2af439054108404c6d2b872989db02f4bd574 codex.sh' \
'fb7f6ea92bbfad8bc40ffd705bd4d02f3ae378c93ffd143495d6a44e9d810647 cursor.sh' \
'04882bf41679d49d9af108657a1e5515bf04fdf2940d12c0d0b1e5d79dc53be8 bun.sh' \
| sha256sum --check --strict \
&& bash ./claude.sh \
&& "/home/${USERNAME}/.local/bin/claude" --version \
&& CODEX_NON_INTERACTIVE=1 sh ./codex.sh \
&& "/home/${USERNAME}/.local/bin/codex" --version \
&& mkdir -p "/home/${USERNAME}/.local/share" \
&& mv "/home/${USERNAME}/.codex/packages/standalone" "/home/${USERNAME}/.local/share/codex-standalone" \
&& bash ./cursor.sh \
&& "/home/${USERNAME}/.local/bin/cursor-agent" --version \
&& bash ./bun.sh "bun-v${BUN_VERSION}" \
&& [[ -x "${BUN_INSTALL}/bin/bun" ]] \
&& rm claude.sh codex.sh cursor.sh bun.sh \
&& cd / \
&& rmdir "$installer_dir"