| 1 | # syntax=docker/dockerfile:1 |
| 2 | # Built from the repository root: |
| 3 | # docker build -f apps/web/Dockerfile --build-arg NEXT_PUBLIC_API_URL=... \ |
| 4 | # --build-arg NEXT_PUBLIC_DOCS_URL=... . |
| 5 | |
| 6 | FROM oven/bun:1.3.14 AS deps |
| 7 | WORKDIR /app |
| 8 | COPY package.json bun.lock ./ |
| 9 | COPY apps/api/package.json apps/api/package.json |
| 10 | COPY apps/web/package.json apps/web/package.json |
| 11 | COPY apps/docs/package.json apps/docs/package.json |
| 12 | COPY packages/db/package.json packages/db/package.json |
| 13 | COPY packages/languages/package.json packages/languages/package.json |
| 14 | RUN bun install --frozen-lockfile |
| 15 | |
| 16 | # @ghost/languages is bundled with `bun build`, which the Node build stage below |
| 17 | # does not have, so it is built here and carried over. |
| 18 | FROM deps AS shared |
| 19 | WORKDIR /app |
| 20 | COPY packages/languages packages/languages |
| 21 | RUN bun run --filter @ghost/languages build |
| 22 | |
| 23 | # Bun installs the workspace, but `next build` runs on Node: the Bun runtime |
| 24 | # segfaults on this build. |
| 25 | FROM node:22-slim AS build |
| 26 | WORKDIR /app |
| 27 | COPY --from=deps /app ./ |
| 28 | COPY . . |
| 29 | COPY --from=shared /app/packages/languages/dist packages/languages/dist |
| 30 | # NEXT_PUBLIC_* is inlined at build time, so the browser's API origin has to be |
| 31 | # known here, not at boot. |
| 32 | ARG NEXT_PUBLIC_API_URL |
| 33 | ARG NEXT_PUBLIC_DOCS_URL |
| 34 | ARG NEXT_PUBLIC_SSH_CLONE_HOST |
| 35 | ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL |
| 36 | ENV NEXT_PUBLIC_DOCS_URL=$NEXT_PUBLIC_DOCS_URL |
| 37 | ENV NEXT_PUBLIC_SSH_CLONE_HOST=$NEXT_PUBLIC_SSH_CLONE_HOST |
| 38 | ENV NEXT_TELEMETRY_DISABLED=1 |
| 39 | ENV PATH=/app/node_modules/.bin:/app/apps/web/node_modules/.bin:$PATH |
| 40 | # `src/lib/api/v1.d.ts` is committed, so the openapi codegen step is skipped. |
| 41 | RUN cd packages/db && tsc -p tsconfig.json |
| 42 | RUN cd apps/web && next build |
| 43 | |
| 44 | FROM node:22-slim AS runtime |
| 45 | WORKDIR /app |
| 46 | ENV NODE_ENV=production |
| 47 | ENV NEXT_TELEMETRY_DISABLED=1 |
| 48 | # `standalone` ships its own pruned node_modules; static assets are not in it. |
| 49 | COPY --from=build /app/apps/web/.next/standalone ./ |
| 50 | COPY --from=build /app/apps/web/.next/static ./apps/web/.next/static |
| 51 | COPY --from=build /app/apps/web/public ./apps/web/public |
| 52 | EXPOSE 3000 |
| 53 | # The standalone server binds to $HOSTNAME, which container runtimes set to the |
| 54 | # container id: that is a single interface, so a platform proxy arriving on any |
| 55 | # other one is refused. Overriding it here beats a runtime-injected value, which |
| 56 | # an `ENV` line would not. |
| 57 | CMD ["sh", "-c", "export HOSTNAME=0.0.0.0; exec node apps/web/server.js"] |