
services:
  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: nobelauto
      POSTGRES_USER: nobel
      POSTGRES_PASSWORD: secret
    volumes:
      - pgdata:/var/lib/postgresql/data
    ports:
      - '5432:5432'
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U nobel -d nobelauto']
      interval: 5s
      timeout: 5s
      retries: 10
    restart: unless-stopped

  api:
    build:
      context: .
      target: api-runner
    environment:
      DATABASE_URL: postgresql://nobel:secret@postgres:5432/nobelauto
      JWT_SECRET: ${JWT_SECRET:?JWT_SECRET is required}
      JWT_REFRESH_SECRET: ${JWT_REFRESH_SECRET:?JWT_REFRESH_SECRET is required}
      CORS_ORIGINS: ${CORS_ORIGINS:-}
      PORT: 4000
      NODE_ENV: production
    ports:
      - '4000:4000'
    depends_on:
      postgres:
        condition: service_healthy
    restart: unless-stopped

  ops:
    build:
      context: .
      target: ops-runner
    ports:
      - '3000:80'
    restart: unless-stopped

  web:
    build:
      context: .
      target: web-runner
    ports:
      - '3001:80'
    restart: unless-stopped

  proxy:
    image: nginx:alpine
    ports:
      - '80:80'
    volumes:
      - ./docker/nginx-proxy.conf:/etc/nginx/nginx.conf:ro
    depends_on:
      - api
      - ops
      - web
    restart: unless-stopped

volumes:
  pgdata:
