Files
Vector/apps/api/Dockerfile
T
josh acf6fc1103
CI / Lint · Typecheck · Test · Build (push) Failing after 43s
CI / Playwright (smoke) (push) Has been skipped
CI / Build & push images (push) Has been skipped
feat(deploy): containerize api + web for single-host docker-compose
- apps/api/Dockerfile: multi-stage build, runs prisma migrate deploy on
  boot. Workspace package.json "main/exports" rewritten to dist so Node
  ESM resolves compiled JS at runtime.
- apps/web/Dockerfile + nginx.conf: static build served by nginx with
  SPA fallback, gzip, cache-bust on hashed assets, and /api reverse
  proxy to the internal api service.
- docker-compose.yml: production-oriented stack — api (SQLite on a
  named volume), web (exposes WEB_PORT), redis (for the upcoming
  worker). Postgres dropped since schema still targets SQLite.
- .dockerignore: keep build context lean.
- ci: add docker job gated on push-to-main that builds and pushes both
  images to ${{ vars.REGISTRY_URL }} using ${{ secrets.REGISTRY_TOKEN }}.
  Tags :latest + :${github.sha}.
2026-04-16 21:10:04 -04:00

51 lines
1.9 KiB
Docker

# syntax=docker/dockerfile:1.7
# ---------- build ----------
FROM node:22-alpine AS build
RUN apk add --no-cache openssl
RUN corepack enable && corepack prepare pnpm@10.33.0 --activate
WORKDIR /repo
# Manifests first for cache-friendly installs.
COPY pnpm-workspace.yaml pnpm-lock.yaml package.json ./
COPY apps/api/package.json ./apps/api/
COPY apps/web/package.json ./apps/web/
COPY apps/e2e/package.json ./apps/e2e/
COPY packages/db/package.json ./packages/db/
COPY packages/shared/package.json ./packages/shared/
COPY packages/ui/package.json ./packages/ui/
COPY packages/config/package.json ./packages/config/
RUN pnpm install --frozen-lockfile
COPY . .
RUN pnpm -C packages/shared build \
&& pnpm -C packages/db build \
&& pnpm -C packages/db exec prisma generate \
&& pnpm -C apps/api build
# Point workspace package.json "main/exports" at compiled JS so Node
# (ESM) resolves dist/ at runtime instead of the original .ts sources.
RUN for p in packages/db packages/shared; do \
node -e "const fs=require('fs');const j=JSON.parse(fs.readFileSync('$p/package.json'));j.main='./dist/index.js';j.types='./dist/index.d.ts';j.exports={'.':{types:'./dist/index.d.ts',default:'./dist/index.js'}};fs.writeFileSync('$p/package.json',JSON.stringify(j,null,2));" ; \
done
# ---------- runtime ----------
FROM node:22-alpine
RUN apk add --no-cache openssl wget
RUN corepack enable && corepack prepare pnpm@10.33.0 --activate
WORKDIR /app
COPY --from=build /repo /app
ENV NODE_ENV=production
ENV PORT=3001
EXPOSE 3001
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
CMD wget -qO- http://localhost:3001/healthz || exit 1
WORKDIR /app/apps/api
# Apply pending migrations before booting. Prisma reads DATABASE_URL from env.
CMD ["sh", "-c", "pnpm -C ../../packages/db exec prisma migrate deploy && node dist/index.js"]