|
| 1 | +# syntax=docker/dockerfile:1.4 |
| 2 | + |
| 3 | +# Installation stage. |
| 4 | +FROM node:22-alpine AS base |
| 5 | +WORKDIR /workspace |
| 6 | +RUN apk add --update --no-cache openssl python3 make g++ |
| 7 | +# Install pnpm. |
| 8 | +ADD package.json . |
| 9 | +RUN corepack enable && corepack prepare --activate |
| 10 | +# Fetch all node modules purely based on the pnpm lock file. |
| 11 | +COPY pnpm-lock.yaml . |
| 12 | +RUN --mount=type=cache,id=workspace,target=/root/.local/share/pnpm/store pnpm fetch |
| 13 | +# Copy the entire workspace into the scope and perform the actual installation. |
| 14 | +COPY . . |
| 15 | +RUN --mount=type=cache,id=workspace,target=/root/.local/share/pnpm/store pnpm install |
| 16 | + |
| 17 | +# Build stage for the server. |
| 18 | +FROM base AS build |
| 19 | +# TODO: Remove this when we switch to an actual database. |
| 20 | +ENV DATABASE_URL="file:./dev.db" |
| 21 | +RUN \ |
| 22 | + # TODO: This initalizes the database. But we should probably remove this later. |
| 23 | + pnpm --filter server prisma migrate reset --force && \ |
| 24 | + # Build the monorepo packages. |
| 25 | + pnpm build && \ |
| 26 | + # Build the server. |
| 27 | + pnpm --filter server build && \ |
| 28 | + # Create an isolated deployment for the server. |
| 29 | + pnpm --filter server deploy --prod deployment && \ |
| 30 | + # Move the runtime build artifacts into a separate directory. |
| 31 | + mkdir -p deployment/out && mv deployment/dist deployment/prisma deployment/node_modules deployment/package.json deployment/out && \ |
| 32 | + # Generate the prisma client |
| 33 | + (cd deployment/out && pnpx prisma generate) |
| 34 | + |
| 35 | +# Slim runtime image. |
| 36 | +FROM node:22-alpine AS server |
| 37 | +WORKDIR /app |
| 38 | +COPY --from=build /workspace/deployment/out . |
| 39 | +# TODO: Remove this when we switch to an actual database. |
| 40 | +ENV DATABASE_URL="file:./dev.db" |
| 41 | +EXPOSE 3030 |
| 42 | +CMD ["node", "dist/index.js"] |
0 commit comments