name: skg-marketing-studio

services:
  postgres:
    image: postgres:16-alpine
    container_name: skg-marketing-postgres
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-skg_marketing}
      POSTGRES_USER: ${POSTGRES_USER:-skg_marketing}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD is required}
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
    restart: unless-stopped
    networks:
      - skg-marketing-internal
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-skg_marketing} -d ${POSTGRES_DB:-skg_marketing}"]
      interval: 10s
      timeout: 5s
      retries: 10

  api:
    build:
      context: .
      dockerfile: Dockerfile.api
    container_name: skg-marketing-api
    env_file:
      - ./deploy/.env.production
    environment:
      JOBS_DIR: /data/jobs
      AGENT_RUNS_DIR: /data/agent_runs
      ASSET_LIBRARY_DIR: /data/asset_library
      PROMPT_LIBRARY_DIR: /data/prompt_library
      DATABASE_URL: ${DATABASE_URL:?DATABASE_URL is required}
      CORS_ORIGINS: https://marketing.skg.com
    volumes:
      - ./data/jobs:/data/jobs
      - ./data/agent_runs:/data/agent_runs
      - ./data/asset_library:/data/asset_library
      - ./data/prompt_library:/data/prompt_library
      - ./data/_trash:/data/_trash
      - ./secrets/tiktok_cookies.txt:/run/secrets/tiktok_cookies.txt
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
    networks:
      - skg-marketing-internal

  web:
    build:
      context: .
      dockerfile: Dockerfile.web
      args:
        NEXT_PUBLIC_API_BASE: /api
    container_name: skg-marketing-web
    depends_on:
      - api
    restart: unless-stopped
    networks:
      - skg-marketing-internal
      - coolify
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=coolify"
      - "traefik.http.middlewares.skg-marketing-gzip.compress=true"
      - "traefik.http.middlewares.skg-marketing-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.skg-marketing-http.entryPoints=http"
      - "traefik.http.routers.skg-marketing-http.rule=Host(`marketing.skg.com`) && PathPrefix(`/`)"
      - "traefik.http.routers.skg-marketing-http.middlewares=skg-marketing-redirect"
      - "traefik.http.routers.skg-marketing-http.service=skg-marketing-http"
      - "traefik.http.routers.skg-marketing-https.entryPoints=https"
      - "traefik.http.routers.skg-marketing-https.rule=Host(`marketing.skg.com`) && PathPrefix(`/`)"
      - "traefik.http.routers.skg-marketing-https.middlewares=skg-marketing-gzip"
      - "traefik.http.routers.skg-marketing-https.tls=true"
      - "traefik.http.routers.skg-marketing-https.tls.certresolver=letsencrypt"
      - "traefik.http.routers.skg-marketing-https.service=skg-marketing-https"
      - "traefik.http.services.skg-marketing-http.loadbalancer.server.port=80"
      - "traefik.http.services.skg-marketing-https.loadbalancer.server.port=80"

networks:
  skg-marketing-internal:
    name: skg-marketing-internal
  coolify:
    external: true
