Files
Bohdan Triapitsyn f4eaa70eaa fix(docker): ship patched dependencies in the runtime image
The runtime stage copied node_modules from the deps stage, but patch-package
runs in the builder stage, so a patched server-side dependency reached the
image unpatched; only the bundled dist carried the fix. Both node_modules
copies now come from builder.

Claude-Session: https://claude.ai/code/session_01VqV56Hez25hTxXH4ipJfzH
2026-09-05 15:08:15 +03:00

79 lines
2.8 KiB
Docker

# syntax=docker/dockerfile:1
FROM oven/bun:1.3.14 AS base
WORKDIR /app
FROM base AS deps
WORKDIR /app
COPY package.json bun.lock ./
COPY bun-patches ./bun-patches
COPY packages/ui/package.json ./packages/ui/
COPY packages/web/package.json ./packages/web/
COPY packages/electron/package.json ./packages/electron/
COPY packages/vscode/package.json ./packages/vscode/
COPY packages/mobile/package.json ./packages/mobile/
RUN bun install --frozen-lockfile --ignore-scripts
FROM deps AS builder
WORKDIR /app
COPY . .
# `deps` installs with --ignore-scripts, so the root postinstall never runs there
# and the patches/ directory is not present yet. Apply patch-package here, after
# the full source copy, so the web bundle ships the patched ghostty-web.
RUN bunx patch-package
RUN bun run build:web
FROM oven/bun:1.3.14 AS runtime
WORKDIR /home/openchamber
RUN apt-get update && apt-get install -y --no-install-recommends \
bash \
ca-certificates \
git \
less \
nodejs \
npm \
openssh-client \
python3 \
&& rm -rf /var/lib/apt/lists/*
# Replace the base image's 'bun' user (UID 1000) with 'openchamber'
# so mounted volumes with 1000:1000 ownership work correctly.
RUN userdel bun \
&& groupadd -g 1000 openchamber \
&& useradd -u 1000 -g 1000 -m -s /bin/bash openchamber \
&& chown -R openchamber:openchamber /home/openchamber
# Switch to openchamber user
USER openchamber
ENV NPM_CONFIG_PREFIX=/home/openchamber/.npm-global
ENV PATH=${NPM_CONFIG_PREFIX}/bin:${PATH}
RUN npm config set prefix /home/openchamber/.npm-global && mkdir -p /home/openchamber/.npm-global && \
mkdir -p /home/openchamber/.local /home/openchamber/.config /home/openchamber/.ssh && \
npm install -g opencode-ai
# cloudflared 2026.3.0 - update digest explicitly when upgrading
COPY --from=cloudflare/cloudflared@sha256:6d91c121b803126f7a5344005d17a9324788fc09d305b6e2560ec6040a7ae283 /usr/local/bin/cloudflared /usr/local/bin/cloudflared
ENV NODE_ENV=production
# The base image ships with the POSIX locale, which makes bash readline treat
# every byte of a multibyte character separately in the built-in terminal.
ENV LANG=C.UTF-8
COPY scripts/docker-entrypoint.sh /home/openchamber/openchamber-entrypoint.sh
# From builder, not deps: builder is where patch-package ran, so a patched
# server-side dependency reaches the image instead of only the bundled dist.
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/packages/web/node_modules ./packages/web/node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/packages/web/package.json ./packages/web/package.json
COPY --from=builder /app/packages/web/bin ./packages/web/bin
COPY --from=builder /app/packages/web/server ./packages/web/server
COPY --from=builder /app/packages/web/dist ./packages/web/dist
EXPOSE 3000
ENTRYPOINT ["sh", "/home/openchamber/openchamber-entrypoint.sh"]