services:
  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-kita_planer}
      POSTGRES_USER: ${POSTGRES_USER:-kita_planer}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?}
    volumes:
      - kita_planer_postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
      interval: 10s
      timeout: 5s
      retries: 10
    restart: unless-stopped

  app:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        NEXT_PUBLIC_SITE_URL: ${NEXT_PUBLIC_SITE_URL:?}
        NEXT_PUBLIC_UMAMI_SCRIPT_URL: ${NEXT_PUBLIC_UMAMI_SCRIPT_URL:-}
        NEXT_PUBLIC_UMAMI_WEBSITE_ID: ${NEXT_PUBLIC_UMAMI_WEBSITE_ID:-}
        NEXT_PUBLIC_UMAMI_DOMAINS: ${NEXT_PUBLIC_UMAMI_DOMAINS:-}
    environment:
      NODE_ENV: production
      PORT: 3000
      HOSTNAME: 0.0.0.0
      DATABASE_URL: postgresql://${POSTGRES_USER:-kita_planer}:${POSTGRES_PASSWORD:?}@postgres:5432/${POSTGRES_DB:-kita_planer}?schema=public
      AUTH_SECRET: ${AUTH_SECRET:?}
      AUTH_URL: ${AUTH_URL:?}
      NEXTAUTH_URL: ${NEXTAUTH_URL:?}
      NEXT_PUBLIC_SITE_URL: ${NEXT_PUBLIC_SITE_URL:?}
      NEXT_PUBLIC_UMAMI_SCRIPT_URL: ${NEXT_PUBLIC_UMAMI_SCRIPT_URL:-}
      NEXT_PUBLIC_UMAMI_WEBSITE_ID: ${NEXT_PUBLIC_UMAMI_WEBSITE_ID:-}
      NEXT_PUBLIC_UMAMI_DOMAINS: ${NEXT_PUBLIC_UMAMI_DOMAINS:-}
      RESEND_API_KEY: ${RESEND_API_KEY:?}
      EMAIL_FROM: ${EMAIL_FROM:?}
      ADMIN_EMAIL: ${ADMIN_EMAIL:?}
      UPLOAD_DIR: /app/uploads/announcements
    volumes:
      - kita_planer_uploads:/app/uploads
    depends_on:
      postgres:
        condition: service_healthy
    ports:
      - "3000"
    restart: unless-stopped

  pgadmin:
    image: dpage/pgadmin4:latest
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:?}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:?}
      PGADMIN_CONFIG_ENHANCED_COOKIE_PROTECTION: "True"
      PGADMIN_CONFIG_CONSOLE_LOG_LEVEL: 30
    volumes:
      - kita_planer_pgadmin_data:/var/lib/pgadmin
    depends_on:
      postgres:
        condition: service_healthy
    ports:
      - "80"
    restart: unless-stopped

volumes:
  kita_planer_postgres_data:
  kita_planer_uploads:
  kita_planer_pgadmin_data:
