Skip to content

[BE-03] Production Docker Compose + GitHub Actions CI/CD Pipelines #960

Description

@mftee

⚠️ Depends on: [BE-01] TypeORM Migrations & Observability Stack — the migration entrypoint and health check must exist before the Docker setup can be finalized.

Overview

The project has no production Dockerfiles, no orchestration for all services, and no automated CI pipelines. Any deployment is currently manual and error-prone. This issue delivers production-ready Dockerfiles for backend and frontend, a docker-compose.prod.yml that runs all four services together, and GitHub Actions workflows that gate every pull request.

Technical Details

1. Backend Dockerfile (backend/Dockerfile)

Multi-stage build:

  • Stage 1 (builder): node:20-alpine, install all deps, run npm run build
  • Stage 2 (runner): node:20-alpine, copy dist/ + prod-only node_modules/, run as non-root user node
  • Entrypoint: sh -c "npm run migration:run && node dist/main.js"
  • EXPOSE 6006

2. Frontend Dockerfile (frontend/Dockerfile)

Multi-stage build:

  • Stage 1 (builder): node:20-alpine, install deps, run npm run build (Next.js standalone output — add output: 'standalone' to next.config.ts)
  • Stage 2 (runner): copy .next/standalone/ and .next/static/, run as non-root user node
  • EXPOSE 3000

3. Production Docker Compose (docker-compose.prod.yml)

Four services on a shared freightflow bridge network:

  • postgres: postgres:15-alpine, persistent named volume, health check using pg_isready
  • redis: redis:7-alpine, persistent named volume, health check using redis-cli ping
  • backend: built from ./backend/Dockerfile, depends_on both postgres and redis with condition: service_healthy, all env vars from .env.production
  • frontend: built from ./frontend/Dockerfile, depends_on backend, env NEXT_PUBLIC_API_URL
  • All services: restart: unless-stopped

4. Backend CI (.github/workflows/backend-ci.yml)

Triggers: pull_request to main
Jobs (run in order):

  1. Install deps: npm ci in backend/
  2. Lint: npm run lint
  3. Unit tests: npm run test
  4. Build: npm run build
  5. Migration dry-run: spin up a postgres:15 service container and run npm run migration:run

5. Frontend CI (.github/workflows/frontend-ci.yml)

Triggers: pull_request to main
Jobs:

  1. Install deps: npm ci in frontend/
  2. Type-check: npx tsc --noEmit
  3. Lint: npm run lint
  4. Build: npm run build

Acceptance Criteria

  • docker build -f backend/Dockerfile backend/ completes without errors
  • docker build -f frontend/Dockerfile frontend/ completes without errors
  • docker compose -f docker-compose.prod.yml up brings all 4 services up healthy
  • Backend container runs migrations before starting the API server
  • Backend CI workflow passes on a clean PR (all 5 jobs green)
  • Frontend CI workflow passes on a clean PR (all 4 jobs green)
  • No credentials are hardcoded in any Dockerfile or Compose file

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions