services:
  app:
    build:
      context: ./apps/sample-website
      dockerfile: Dockerfile
      args:
        NEXT_PUBLIC_BASE_URL: ${NEXT_PUBLIC_BASE_URL:-http://localhost:3000}
        NEXT_PUBLIC_UMAMI_WEBSITE_ID: ${NEXT_PUBLIC_UMAMI_WEBSITE_ID}
        NEXT_PUBLIC_UMAMI_SCRIPT_URL: ${NEXT_PUBLIC_UMAMI_SCRIPT_URL}
        NEXT_PUBLIC_TARGET: ${TARGET:-development}
    restart: always
    networks:
      - infra
    environment:
      - DIRECTUS_URL=${DIRECTUS_URL:-http://directus:8055}
    env_file:
      - .env
    ports:
      - "3000:3000"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.sample-website.rule=Host(`${TRAEFIK_HOST:-sample-website.localhost}`)"
      - "traefik.http.services.sample-website.loadbalancer.server.port=3000"

  directus:
    image: registry.infra.mintel.me/mintel/directus:${IMAGE_TAG:-latest}
    healthcheck:
      test: [ "CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:8055/server/health" ]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 5s
    restart: always
    networks:
      - infra
    env_file:
      - .env
    environment:
      KEY: ${DIRECTUS_KEY:-mintel-key}
      SECRET: ${DIRECTUS_SECRET:-mintel-secret}
      ADMIN_EMAIL: ${DIRECTUS_ADMIN_EMAIL:-admin@mintel.me}
      ADMIN_PASSWORD: ${DIRECTUS_ADMIN_PASSWORD:-mintel-admin}
      DB_CLIENT: 'pg'
      DB_HOST: 'at-mintel-directus-db'
      DB_PORT: '5432'
      DB_DATABASE: ${DIRECTUS_DB_NAME:-directus}
      DB_USER: ${DIRECTUS_DB_USER:-directus}
      DB_PASSWORD: ${DIRECTUS_DB_PASSWORD:-mintel-db-pass}
      WEBSOCKETS_ENABLED: 'true'
      PUBLIC_URL: ${DIRECTUS_URL:-http://localhost:8055}
    ports:
      - "8055:8055"
    volumes:
      - ./directus/uploads:/directus/uploads
      - ./directus/extensions:/directus/extensions
      - ./directus/schema:/directus/schema
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.sample-website-directus.rule=Host(`${DIRECTUS_HOST:-cms.sample-website.localhost}`)"
      - "traefik.http.services.sample-website-directus.loadbalancer.server.port=8055"

  at-mintel-directus-db:
    image: postgres:15-alpine
    restart: always
    networks:
      - infra
    environment:
      POSTGRES_DB: ${DIRECTUS_DB_NAME:-directus}
      POSTGRES_USER: ${DIRECTUS_DB_USER:-directus}
      POSTGRES_PASSWORD: ${DIRECTUS_DB_PASSWORD:-mintel-db-pass}
    volumes:
      - directus-db-data:/var/lib/postgresql/data

networks:
  infra:
    external: true

volumes:
  directus-db-data:
