services:
  db:
    image: postgres:16
    container_name: nexapg-db
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${DB_NAME}
      POSTGRES_USER: ${DB_USER}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    ports:
      - "${DB_PORT}:5432"
    volumes:
      - pg_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
      interval: 10s
      timeout: 5s
      retries: 10

  backend:
    image: nesterovicit/nexapg-backend:latest
    pull_policy: always
    container_name: nexapg-backend
    restart: unless-stopped
    environment:
      APP_NAME: ${APP_NAME}
      ENVIRONMENT: ${ENVIRONMENT}
      LOG_LEVEL: ${LOG_LEVEL}
      DB_HOST: db
      DB_PORT: 5432
      DB_NAME: ${DB_NAME}
      DB_USER: ${DB_USER}
      DB_PASSWORD: ${DB_PASSWORD}
      JWT_SECRET_KEY: ${JWT_SECRET_KEY}
      JWT_ALGORITHM: ${JWT_ALGORITHM}
      JWT_ACCESS_TOKEN_MINUTES: ${JWT_ACCESS_TOKEN_MINUTES}
      JWT_REFRESH_TOKEN_MINUTES: ${JWT_REFRESH_TOKEN_MINUTES}
      ENCRYPTION_KEY: ${ENCRYPTION_KEY}
      CORS_ORIGINS: ${CORS_ORIGINS}
      POLL_INTERVAL_SECONDS: ${POLL_INTERVAL_SECONDS}
      INIT_ADMIN_EMAIL: ${INIT_ADMIN_EMAIL}
      INIT_ADMIN_PASSWORD: ${INIT_ADMIN_PASSWORD}
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "${BACKEND_PORT}:8000"

  frontend:
    image: nesterovicit/nexapg-frontend:latest
    pull_policy: always
    container_name: nexapg-frontend
    restart: unless-stopped
    depends_on:
      - backend
    ports:
      - "${FRONTEND_PORT}:80"

volumes:
  pg_data:
