| 1 | # syntax=docker/dockerfile:1 |
| 2 | # Built from the repository root: the API depends on the @ghost/db workspace. |
| 3 | # docker build -f apps/api/Dockerfile . |
| 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 | RUN bun install --frozen-lockfile |
| 12 | |
| 13 | FROM deps AS build |
| 14 | WORKDIR /app |
| 15 | COPY . . |
| 16 | RUN bun run --filter @ghost/db build \ |
| 17 | && bun run --filter @ghost/api build |
| 18 | |
| 19 | # A second, clean install: the runtime needs neither the web app's dependencies |
| 20 | # nor the compilers, and pruning in place leaves Bun's package store behind. |
| 21 | FROM oven/bun:1.3.14 AS prod-deps |
| 22 | WORKDIR /app |
| 23 | COPY package.json bun.lock ./ |
| 24 | COPY apps/api/package.json apps/api/package.json |
| 25 | COPY apps/web/package.json apps/web/package.json |
| 26 | COPY packages/db/package.json packages/db/package.json |
| 27 | RUN bun install --frozen-lockfile --production \ |
| 28 | --filter '@ghost/api' --filter '@ghost/db' |
| 29 | |
| 30 | FROM node:22-slim AS runtime |
| 31 | # Every pack operation shells out to the real git binary. |
| 32 | RUN apt-get update \ |
| 33 | && apt-get install -y --no-install-recommends ca-certificates git \ |
| 34 | && rm -rf /var/lib/apt/lists/* |
| 35 | WORKDIR /app |
| 36 | ENV NODE_ENV=production |
| 37 | COPY --from=prod-deps /app ./ |
| 38 | COPY --from=build /app/apps/api/dist ./apps/api/dist |
| 39 | COPY --from=build /app/packages/db/dist ./packages/db/dist |
| 40 | COPY packages/db/drizzle ./packages/db/drizzle |
| 41 | EXPOSE 3001 |
| 42 | CMD ["node", "apps/api/dist/main.js"] |