services:
  directus:
    build:
      context: .
      dockerfile: directus.Dockerfile
    volumes:
      - 'directus-uploads:/directus/uploads'
      - 'directus-extensions:/directus/extensions'
      - 'directus-templates:/directus/templates'
    environment:
      - SERVICE_URL_DIRECTUS_8055
      - KEY=$SERVICE_BASE64_64_KEY
      - SECRET=$SERVICE_BASE64_64_SECRET
      - 'ADMIN_EMAIL=${ADMIN_EMAIL:-admin@example.com}'
      - ADMIN_PASSWORD=$SERVICE_PASSWORD_ADMIN
      - DB_CLIENT=postgres
      - DB_HOST=postgresql
      - DB_PORT=5432
      - 'DB_DATABASE=${POSTGRESQL_DATABASE:-directus}'
      - DB_USER=$SERVICE_USER_POSTGRESQL
      - DB_PASSWORD=$SERVICE_PASSWORD_POSTGRESQL
      - CACHE_ENABLED=false
      - CACHE_STORE=memory
      - WEBSOCKETS_ENABLED=true
      - CORS_ENABLED=true
      - 'CORS_ORIGIN=https://launch.jumpstartscaling.com,http://localhost:4321'
      - CORS_METHODS=GET,POST,PATCH,DELETE
      - CORS_ALLOWED_HEADERS=Content-Type,Authorization
      - CORS_EXPOSED_HEADERS=Content-Range
      - CORS_CREDENTIALS=true
      - CORS_MAX_AGE=86400
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.directus.rule=Host(`spark.jumpstartscaling.com`)"
      - "traefik.http.routers.directus.entrypoints=https"
      - "traefik.http.routers.directus.tls.certresolver=letsencrypt"
      - "traefik.http.services.directus.loadbalancer.server.port=8055"
      - "traefik.docker.network=coolify"
      - "traefik.http.services.directus.loadbalancer.server.scheme=http"
    healthcheck:
      test:
        - CMD
        - wget
        - '-q'
        - '--spider'
        - 'http://127.0.0.1:8055/admin/login'
      interval: 5s
      timeout: 20s
      retries: 10
    depends_on:
      postgresql:
        condition: service_healthy
    networks:
      - coolify
      - default

  postgresql:
    image: 'postgis/postgis:16-3.4-alpine'
    platform: linux/amd64
    volumes:
      - 'directus-postgresql-data:/var/lib/postgresql/data'
    environment:
      - 'POSTGRES_USER=${SERVICE_USER_POSTGRESQL}'
      - 'POSTGRES_PASSWORD=${SERVICE_PASSWORD_POSTGRESQL}'
      - 'POSTGRES_DB=${POSTGRESQL_DATABASE:-directus}'
    healthcheck:
      test:
        - CMD-SHELL
        - 'pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}'
      interval: 5s
      timeout: 20s
      retries: 10

  redis:
    image: 'redis:7-alpine'
    command: 'redis-server --appendonly yes'
    volumes:
      - 'directus-redis-data:/data'
    healthcheck:
      test:
        - CMD
        - redis-cli
        - ping
      interval: 5s
      timeout: 20s
      retries: 10

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    environment:
      - PUBLIC_DIRECTUS_URL=https://spark.jumpstartscaling.com
      - DIRECTUS_ADMIN_TOKEN=${DIRECTUS_ADMIN_TOKEN:-}
      - PUBLIC_PLATFORM_DOMAIN=launch.jumpstartscaling.com
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.frontend.rule=Host(`launch.jumpstartscaling.com`)"
      - "traefik.http.routers.frontend.entrypoints=https"
      - "traefik.http.routers.frontend.tls.certresolver=letsencrypt"
      - "traefik.http.services.frontend.loadbalancer.server.port=4321"
      - "traefik.docker.network=coolify"
    depends_on:
      - directus
    networks:
      - coolify
      - default

volumes:
  directus-uploads:
  directus-extensions:
  directus-templates:
  directus-postgresql-data:
  directus-redis-data:


networks:
  coolify:
    external: true
