services:
  seed:
    image: postgres:16.1
    profiles: ["tools"]
    environment:
      PGPASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - ./dev/seed_weather.sql:/seed/seed_weather.sql:ro
    command:
      - psql
      - -h
      - postgres
      - -U
      - ${POSTGRES_USER}
      - -d
      - ${POSTGRES_DB}
      - -v
      - ON_ERROR_STOP=1
      - -f
      - /seed/seed_weather.sql
    depends_on:
      postgres:
        condition: service_healthy

  node:
    image: node:22.14.0
    working_dir: /web
    volumes:
      - ./web:/web
    command: sh -c "npm install && npm run build"

  postgres:
    image: postgres:16.1
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -d ${POSTGRES_DB} -U ${POSTGRES_USER}" ]
      interval: 5s
      timeout: 5s
      retries: 5
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - ./postgres:/var/lib/postgresql/data

  scala:
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_HOST: ${POSTGRES_HOST}
      METEO_USER: ${METEO_USER}
      METEO_PASSWORD: ${METEO_PASSWORD}
      METEO_URL: ${METEO_URL}
      LVGMC_URL: ${LVGMC_URL}
      LVGMC_USER: ${LVGMC_USER}
      LVGMC_PASSWORD: ${LVGMC_PASSWORD}
      HARMONIE_EDR_API_KEY: ${HARMONIE_EDR_API_KEY}
      HARMONIE_EDR_URL: ${HARMONIE_EDR_URL}
      HARMONIE_STAC_API_KEY: ${HARMONIE_STAC_API_KEY}
      HARMONIE_STAC_URL: ${HARMONIE_STAC_URL}
      ENABLE_SCHEDULED_JOBS: ${ENABLE_SCHEDULED_JOBS:-true}
    build:
      context: .
      dockerfile: Dockerfile.local
    restart: on-failure:10
    volumes:
      - scala-data:/data
      - ./web/dist:/web/dist
    ports:
      - "${APP_BIND_ADDRESS:-127.0.0.1}:${APP_PORT:-9090}:8080"
    depends_on:
      node:
        condition: service_completed_successfully
      postgres:
        condition: service_healthy

volumes:
  scala-data:
