# syntax=docker/dockerfile:1 # Both images, built from the repo root: # docker build --target api -t electro4ort-api . # docker build --target web --build-arg VITE_API_URL=https://api.example.com -t electro4ort-web . # docker-compose.yml does this for you. FROM node:24-alpine AS base ENV PNPM_HOME=/pnpm ENV PATH=$PNPM_HOME:$PATH # The pnpm version comes from "packageManager" in package.json. RUN corepack enable WORKDIR /repo # Everything installed and the shared packages built, once for both images. FROM base AS workspace COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ COPY apps/api/package.json apps/api/ COPY apps/web/package.json apps/web/ COPY packages/contracts/package.json packages/contracts/ COPY packages/ui/package.json packages/ui/ RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile COPY . . RUN pnpm --filter @repo/contracts build FROM workspace AS api-build RUN pnpm --filter api build # The package alone with only what it needs to run, workspace packages included. RUN --mount=type=cache,id=pnpm,target=/pnpm/store \ pnpm --filter api deploy --prod --legacy /out FROM workspace AS web-build # The API's public address is compiled into the pages. ARG VITE_API_URL RUN test -n "$VITE_API_URL" || (echo "VITE_API_URL is required: --build-arg VITE_API_URL=https://api.example.com" >&2; exit 1) ENV VITE_API_URL=$VITE_API_URL RUN pnpm --filter web build RUN --mount=type=cache,id=pnpm,target=/pnpm/store \ pnpm --filter web deploy --prod --legacy /out # The API. Before a new version starts, apply its migrations with the same # image: `node dist/db/migrate.js`. FROM node:24-alpine AS api ENV NODE_ENV=production ENV PORT=3000 # Where files are kept when STORAGE_DRIVER is "local": mount a volume here. ENV STORAGE_LOCAL_ROOT=/data/files RUN mkdir -p /data/files && chown node:node /data/files WORKDIR /app COPY --from=api-build /out/package.json ./ COPY --from=api-build /out/node_modules ./node_modules # The build output is git-ignored, which keeps it out of `pnpm deploy`. COPY --from=api-build /repo/apps/api/dist ./dist COPY --from=api-build /repo/apps/api/drizzle ./drizzle USER node EXPOSE 3000 HEALTHCHECK --interval=10s --timeout=3s --start-period=20s --retries=3 \ CMD wget -qO /dev/null http://127.0.0.1:3000/health || exit 1 CMD ["node", "dist/main.js"] # The web app: renders the first page on the server and serves the assets. FROM node:24-alpine AS web ENV NODE_ENV=production ENV PORT=3000 WORKDIR /app COPY --from=web-build /out/package.json ./ COPY --from=web-build /out/node_modules ./node_modules COPY --from=web-build /repo/apps/web/dist ./dist USER node EXPOSE 3000 HEALTHCHECK --interval=10s --timeout=3s --start-period=20s --retries=3 \ CMD wget -qO /dev/null http://127.0.0.1:3000/login || exit 1 CMD ["node_modules/.bin/srvx", "--prod", "-s", "../client", "dist/server/server.js"]