services:
  app:
    # Lighweight proxy to bridge Traefik to local host (HMR support)
    image: alpine/socat
    restart: always
    command: tcp-listen:3000,fork,reuseaddr tcp:host.docker.internal:3000
    extra_hosts:
      - "host.docker.internal:host-gateway"
    networks:
      - default
      - infra
    labels:
      - "traefik.enable=true"
      - "traefik.http.services.${PROJECT_NAME:-mintel-me}.loadbalancer.server.port=3000"
      - "traefik.docker.network=infra"
      - "caddy=http://${TRAEFIK_HOST:-mintel.localhost}"
      - "caddy.reverse_proxy={{upstreams 3000}}"

  gatekeeper:
    profiles: ["gatekeeper"]
    image: registry.infra.mintel.me/mintel/gatekeeper:v1.7.12
    restart: always
    networks:
      infra:
        aliases:
          - ${PROJECT_NAME:-mintel-me}-gatekeeper
    env_file:
      - .env
    environment:
      PORT: 3000
    labels:
      - "traefik.http.services.${PROJECT_NAME:-mintel-me}-gatekeeper.loadbalancer.server.port=3000"
      - "traefik.docker.network=infra"
      - "caddy=http://gatekeeper.${TRAEFIK_HOST:-mintel.localhost}"
      - "caddy.reverse_proxy={{upstreams 3000}}"

  directus:
    image: registry.infra.mintel.me/mintel/directus:latest
    restart: always
    networks:
      - default
      - infra
    env_file:
      - .env
    environment:
      KEY: ${DIRECTUS_KEY}
      SECRET: ${DIRECTUS_SECRET}
      DB_CLIENT: "pg"
      DB_HOST: "directus-db"
      DB_PORT: "5432"
      DB_DATABASE: ${DIRECTUS_DB_NAME:-directus}
      DB_USER: ${DIRECTUS_DB_USER:-directus}
      DB_PASSWORD: ${DIRECTUS_DB_PASSWORD:-directus}
      PUBLIC_URL: ${DIRECTUS_URL:-https://cms.mintel.me}
    volumes:
      - ./directus/uploads:/directus/uploads
      - ./directus/extensions:/directus/extensions
      - ./directus/migrations:/directus/migrations
    labels:
      - "traefik.http.services.${PROJECT_NAME:-mintel-me}-directus.loadbalancer.server.port=8055"
      - "traefik.docker.network=infra"
      - "caddy=http://${DIRECTUS_HOST:-cms.mintel.localhost}"
      - "caddy.reverse_proxy={{upstreams 8055}}"

  directus-db:
    image: postgres:15-alpine
    restart: always
    networks:
      - default
    env_file:
      - .env
    environment:
      POSTGRES_DB: ${DIRECTUS_DB_NAME:-directus}
      POSTGRES_USER: ${DIRECTUS_DB_USER:-directus}
      POSTGRES_PASSWORD: ${DIRECTUS_DB_PASSWORD:-directus}
    volumes:
      - directus-db-data:/var/lib/postgresql/data

  imgproxy:
    image: darthsim/imgproxy:latest
    restart: always
    networks:
      - default
      - infra
    extra_hosts:
      - "mintel.localhost:host-gateway"
      - "cms.mintel.localhost:host-gateway"
      - "host.docker.internal:host-gateway"
    environment:
      IMGPROXY_URL_MAPPING: "http://mintel.localhost/:http://app:3000/,http://cms.mintel.localhost/:http://directus:8055/"
      IMGPROXY_USE_ETAG: "true"
      IMGPROXY_MAX_SRC_RESOLUTION: 20
      IMGPROXY_ALLOWED_NETWORKS: "10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"
      IMGPROXY_IGNORE_SSL_ERRORS: "true"
      IMGPROXY_DEBUG: "true"
    labels:
      - "traefik.http.services.${PROJECT_NAME:-mintel-me}-imgproxy.loadbalancer.server.port=8080"
      - "traefik.docker.network=infra"
      - "caddy=http://${IMGPROXY_HOST:-img.mintel.localhost}"
      - "caddy.reverse_proxy={{upstreams 8080}}"

networks:
  default:
    name: ${PROJECT_NAME:-mintel-me}-internal
  infra:
    external: true

volumes:
  directus-db-data:
