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