services:
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password
      POSTGRES_DB: openccb
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data

  studio:
    build:
      context: .
      dockerfile: web/studio/Dockerfile
      network: host
      args:
        NEXT_PUBLIC_CMS_API_URL: ${NEXT_PUBLIC_CMS_API_URL:-http://localhost:3001}
    dns:
      - 8.8.8.8
    ports:
      - "3000:3000"
      - "3001:3001"
    environment:
      DATABASE_URL: postgresql://user:password@db:5432/openccb_cms
      JWT_SECRET: ${JWT_SECRET:-openccb_secret_key_2025_production}
      NEXT_PUBLIC_CMS_API_URL: ${NEXT_PUBLIC_CMS_API_URL:-http://localhost:3001}
      RUST_LOG: debug
      LMS_INTERNAL_URL: http://experience:3002
    volumes:
      - uploads_data:/app/uploads
    env_file: .env
    extra_hosts:
      - "host.docker.internal:host-gateway"
      - "t-800:192.168.0.5"
    depends_on:
      - db

  experience:
    build:
      context: .
      dockerfile: web/experience/Dockerfile
      network: host
      args:
        NEXT_PUBLIC_LMS_API_URL: ${NEXT_PUBLIC_LMS_API_URL:-http://localhost:3002}
        NEXT_PUBLIC_CMS_API_URL: ${NEXT_PUBLIC_CMS_API_URL:-http://localhost:3001}
    dns:
      - 8.8.8.8
    ports:
      - "3003:3003"
      - "3002:3002"
    environment:
      DATABASE_URL: postgresql://user:password@db:5432/openccb_lms
      JWT_SECRET: ${JWT_SECRET:-openccb_secret_key_2025_production}
      RUST_LOG: debug
      NEXT_PUBLIC_LMS_API_URL: ${NEXT_PUBLIC_LMS_API_URL:-http://localhost:3002}
      NEXT_PUBLIC_CMS_API_URL: ${NEXT_PUBLIC_CMS_API_URL:-http://localhost:3001}
    env_file: .env
    extra_hosts:
      - "host.docker.internal:host-gateway"
      - "t-800:192.168.0.5"
    depends_on:
      - db

  e2e:
    build:
      context: ./e2e
    environment:
      - STUDIO_URL=http://studio:3000
      - EXPERIENCE_URL=http://experience:3003
    depends_on:
      - studio
      - experience
    volumes:
      - ./e2e/tests:/e2e/tests
      - ./e2e/playwright-report:/e2e/playwright-report
    profiles: [ "test" ]

volumes:
  postgres_data:
  uploads_data:
