services:
  app:
    image: registry.infra.mintel.me/mintel/mintel.me:${IMAGE_TAG:-latest}
    restart: always
    networks:
      - infra
    env_file:
      - ${ENV_FILE:-.env}
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.${PROJECT_NAME}.rule=Host(`${TRAEFIK_HOST}`)"
      - "traefik.http.routers.${PROJECT_NAME}.entrypoints=websecure"
      - "traefik.http.routers.${PROJECT_NAME}.tls.certresolver=le"
      - "traefik.http.routers.${PROJECT_NAME}.tls=true"
      - "traefik.http.services.${PROJECT_NAME}.loadbalancer.server.port=3000"
      - "traefik.http.routers.${PROJECT_NAME}.middlewares=${AUTH_MIDDLEWARE:-compress}"
      - "traefik.docker.network=infra"

      # Gatekeeper Router
      - "traefik.http.routers.${PROJECT_NAME}-gatekeeper.rule=Host(`${TRAEFIK_HOST}`) && PathPrefix(`/gatekeeper`)"
      - "traefik.http.routers.${PROJECT_NAME}-gatekeeper.entrypoints=websecure"
      - "traefik.http.routers.${PROJECT_NAME}-gatekeeper.tls.certresolver=le"
      - "traefik.http.routers.${PROJECT_NAME}-gatekeeper.tls=true"
      - "traefik.http.routers.${PROJECT_NAME}-gatekeeper.service=${PROJECT_NAME}-gatekeeper"

      - "traefik.http.middlewares.${PROJECT_NAME}-auth.forwardauth.address=http://${PROJECT_NAME}-gatekeeper:3000/api/verify"
      - "traefik.http.middlewares.${PROJECT_NAME}-auth.forwardauth.trustForwardHeader=true"
      - "traefik.http.middlewares.${PROJECT_NAME}-auth.forwardauth.authResponseHeaders=X-Auth-User"
      - "traefik.docker.network=infra"

  gatekeeper:
    image: registry.infra.mintel.me/mintel/gatekeeper:latest
    container_name: ${PROJECT_NAME:-mintel-me}-gatekeeper
    restart: always
    networks:
      infra:
        aliases:
          - ${PROJECT_NAME:-mintel-me}-gatekeeper
    env_file:
      - ${ENV_FILE:-.env}
    environment:
      PORT: 3000
      PROJECT_NAME: ${PROJECT_NAME:-Mintel.me}
      PROJECT_COLOR: ${PROJECT_COLOR:-#ff00ff}
    labels:
      - "traefik.enable=true"
      - "traefik.http.services.${PROJECT_NAME}-gatekeeper.loadbalancer.server.port=3000"
      - "traefik.docker.network=infra"

  directus:
    image: registry.infra.mintel.me/mintel/directus:latest
    restart: always
    networks:
      - infra
    env_file:
      - ${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
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.${PROJECT_NAME}-directus.rule=Host(`${DIRECTUS_HOST}`)"
      - "traefik.http.routers.${PROJECT_NAME}-directus.entrypoints=websecure"
      - "traefik.http.routers.${PROJECT_NAME}-directus.tls.certresolver=le"
      - "traefik.http.routers.${PROJECT_NAME}-directus.tls=true"
      - "traefik.http.routers.${PROJECT_NAME}-directus.middlewares=${AUTH_MIDDLEWARE:-compress}"
      - "traefik.http.services.${PROJECT_NAME}-directus.loadbalancer.server.port=8055"
      - "traefik.docker.network=infra"

  directus-db:
    image: postgres:15-alpine
    restart: always
    networks:
      - infra
    env_file:
      - ${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

networks:
  infra:
    external: true

volumes:
  directus-db-data:
