services:
  redis:
    image: redis:7-alpine
    command: ["redis-server", "--appendonly", "yes"]
    volumes:
      - bm_redis_data:/data
    networks:
      - bm_internal

  geocoder-worker:
    build:
      context: ../apps/geocoder
    working_dir: /app
    environment:
      DATABASE_URL: ${DATABASE_URL}
      NOMINATIM_BASE: "https://nominatim.openstreetmap.org"
      NOMINATIM_EMAIL: ${NOMINATIM_EMAIL}
      NOMINATIM_USER_AGENT: ${NOMINATIM_USER_AGENT}
      NOMINATIM_MIN_DELAY: "1.05"
      NOMINATIM_JITTER: "0.35"
      GEOCODE_MAX_PER_RUN: "5000"
    command: ["python", "src/worker.py"]
    networks:
      - bm_internal
    restart: unless-stopped
  pgadmin:
    image: dpage/pgadmin4:8
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD}
      PGADMIN_CONFIG_SERVER_MODE: "True"
    volumes:
      - pgadmin_data:/var/lib/pgadmin
    networks:
      - bm_internal
      - coolify
    labels:
      - traefik.enable=true
      - traefik.docker.network=coolify
      - traefik.http.routers.pgadmin.rule=Host(`pgadmin.bm.nicolasfryder.ovh`)
      - traefik.http.routers.pgadmin.entrypoints=https
      - traefik.http.routers.pgadmin.tls=true
      - traefik.http.routers.pgadmin.tls.certresolver=letsencrypt
      - traefik.http.services.pgadmin.loadbalancer.server.port=80

  api:
    build:
      context: ../apps/api
    environment:
      PORT: "3000"
      DATABASE_URL: ${DATABASE_URL}
      BM_IMPORT_TOKEN: ${BM_IMPORT_TOKEN}
    volumes:
      - ./overrides/api/src/server.js:/app/src/server.js:ro
    networks:
      - bm_internal
      - coolify
    labels:
      - traefik.enable=true
      - traefik.docker.network=coolify
      - traefik.http.routers.bm-api.rule=Host(`bm.nicolasfryder.ovh`)
      - traefik.http.routers.bm-api.entrypoints=https
      - traefik.http.routers.bm-api.tls=true
      - traefik.http.routers.bm-api.tls.certresolver=letsencrypt
      - traefik.http.services.bm-api.loadbalancer.server.port=3000

  web:
    build:
      context: ../apps/web
    networks:
      - coolify
    labels:
      - traefik.enable=true
      - traefik.docker.network=coolify
      - traefik.http.routers.bm-web.rule=Host(`metalfrom.eu`) || Host(`www.metalfrom.eu`)
      - traefik.http.routers.bm-web.entrypoints=https
      - traefik.http.routers.bm-web.tls=true
      - traefik.http.routers.bm-web.tls.certresolver=letsencrypt
      - traefik.http.routers.bm-web.tls.domains[0].main=metalfrom.eu
      - traefik.http.routers.bm-web.tls.domains[0].sans=www.metalfrom.eu
      - traefik.http.services.bm-web.loadbalancer.server.port=80

  worker:
    build:
      context: ../apps/worker
    environment:
      DB_DSN: ${DATABASE_URL}
      MA_LIST_URL: https://www.metal-archives.com/lists/FR
      MA_STATE_PATH: /app/ma_state.json
    volumes:
      - worker_state:/app
    networks:
      - bm_internal
    restart: "no"

networks:
  bm_internal:
    driver: bridge
  coolify:
    external: true
    name: coolify

volumes:
  bm_redis_data:
  pgadmin_data:
  worker_state:
