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