Deployment
Docker
Dockerfiles for each CodePilot service and multi-stage build configuration.
Each CodePilot application has its own Dockerfile optimized for production builds. All Dockerfiles use multi-stage builds to minimize image size.
Application Dockerfiles
| Service | Dockerfile Location | Base Image |
|---|---|---|
| API | apps/api/Dockerfile | node:20-alpine |
| Worker | apps/worker/Dockerfile | node:20-alpine |
| Web | apps/web/Dockerfile | node:20-alpine |
Dockerfile Structure
Each Dockerfile follows a multi-stage pattern:
# Stage 1: Install dependencies
FROM node:20-alpine AS deps
WORKDIR /app
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY apps/api/package.json ./apps/api/
COPY packages/database/package.json ./packages/database/
COPY packages/shared/package.json ./packages/shared/
RUN corepack enable && pnpm install --frozen-lockfile
# Stage 2: Build
FROM node:20-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN pnpm --filter @repo/db run db:generate
RUN pnpm --filter api run build
# Stage 3: Production
FROM node:20-alpine AS runner
WORKDIR /app
COPY --from=builder /app/apps/api/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 8080
CMD ["node", "dist/index.js"]Multi-Stage Builds
Multi-stage builds keep the final image small by only including production dependencies and compiled output. Build tools, TypeScript sources, and dev dependencies are excluded.
Building Images
Build individual service images:
# Build API image
docker build -f apps/api/Dockerfile -t codepilot-api .
# Build worker image
docker build -f apps/worker/Dockerfile -t codepilot-worker .
# Build web image
docker build -f apps/web/Dockerfile -t codepilot-web .Build Context
All Dockerfiles use the monorepo root as the build context (.). This is necessary because they need access to shared packages in packages/.
# Build from the monorepo root
docker build -f apps/api/Dockerfile -t codepilot-api .
# ^ root context.dockerignore
The root .dockerignore excludes unnecessary files from the build context:
node_modules
.git
.next
dist
*.log
.env*