services:
  postgres:
    image: postgres:16-alpine
    container_name: wetterstation_db_prod
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${DB_NAME}
      POSTGRES_USER: ${DB_USER}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - internal
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
      interval: 10s
      timeout: 5s
      retries: 5

  collector:
    image: docker.citysensor.de/wetterstation-collector:latest
    container_name: wetterstation_collector_prod
    restart: unless-stopped
    env_file:
      - ./.env
    environment:
      DB_HOST: postgres
    depends_on:
      postgres:
        condition: service_healthy
    networks:
      - internal
      - proxy
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=dockge_default"
      - "traefik.http.routers.wetterstation-collector.rule=Host(`stwwetter.fuerst-stuttgart.de`) && PathPrefix(`/collector`)"
      - "traefik.http.routers.wetterstation-collector.entrypoints=https"
      - "traefik.http.routers.wetterstation-collector.tls=true"
      - "traefik.http.routers.wetterstation-collector.tls.certresolver=letsencrypt"
      - "traefik.http.middlewares.wetterstation-collector-stripprefix.stripprefix.prefixes=/collector"
      - "traefik.http.routers.wetterstation-collector.middlewares=wetterstation-collector-stripprefix"
      - "traefik.http.services.wetterstation-collector.loadbalancer.server.port=8001"

  api:
    image: docker.citysensor.de/wetterstation-api:latest
    container_name: wetterstation_api_prod
    restart: unless-stopped
    env_file:
      - ./.env
    environment:
      DB_HOST: postgres
    depends_on:
      postgres:
        condition: service_healthy
    networks:
      - internal
      - proxy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=dockge_default"
      - "traefik.http.routers.wetterstation-api.rule=Host(`stwwetter.fuerst-stuttgart.de`) && PathPrefix(`/api`)"
      - "traefik.http.routers.wetterstation-api.entrypoints=https"
      - "traefik.http.routers.wetterstation-api.tls=true"
      - "traefik.http.routers.wetterstation-api.tls.certresolver=letsencrypt"
      - "traefik.http.middlewares.wetterstation-api-stripprefix.stripprefix.prefixes=/api"
      - "traefik.http.routers.wetterstation-api.middlewares=wetterstation-api-stripprefix"
      - "traefik.http.services.wetterstation-api.loadbalancer.server.port=8000"

  frontend:
    image: docker.citysensor.de/wetterstation-frontend:latest
    container_name: wetterstation_frontend_prod
    restart: unless-stopped
    depends_on:
      api:
        condition: service_healthy
    networks:
      - internal
      - proxy
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=dockge_default"
      - "traefik.http.routers.wetterstation.rule=Host(`stwwetter.fuerst-stuttgart.de`)"
      - "traefik.http.routers.wetterstation.entrypoints=https"
      - "traefik.http.routers.wetterstation.tls=true"
      - "traefik.http.routers.wetterstation.tls.certresolver=letsencrypt"
      - "traefik.http.services.wetterstation.loadbalancer.server.port=80"

  pgadmin:
    image: dpage/pgadmin4:latest
    container_name: wetterstation_pgadmin_prod
    restart: unless-stopped
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD}
      PGADMIN_CONFIG_SERVER_MODE: 'True'
    volumes:
      - pgadmin_data:/var/lib/pgadmin
    depends_on:
      - postgres
    networks:
      - internal
    labels:
      - "traefik.enable=false"

  monitor:
    image: docker.citysensor.de/wetterstation-monitor:latest
    container_name: wetterstation_monitor_prod
    restart: unless-stopped
    env_file:
      - ./.env

volumes:
  postgres_data:
    name: wetterstation_postgres_data_prod
  pgadmin_data:
    name: wetterstation_pgadmin_data_prod

networks:
  internal:
    name: wetterstation_internal
    driver: bridge
  proxy:
    name: dockge_default
    external: true
