services:

  proxy:
    image: traefik:v3.7
    ports:
      - "80:80"
      - "8090:8080"
    # Duplicate the command from compose.yml to add --api.insecure=true
    command:
      # Enable Docker in Traefik, so that it reads labels from Docker services
      - --providers.docker
      # Do not expose all Docker services, only the ones explicitly exposed
      - --providers.docker.exposedbydefault=false
      # Create an entrypoint "http" listening on port 80
      - --entrypoints.http.address=:80
      # Enable the access log, with HTTP requests
      - --accesslog
      # Enable the Traefik log, for configurations and errors
      - --log
      # Enable debug logging for local development
      - --log.level=DEBUG
      # Enable the Dashboard and API
      - --api
      # Enable the Dashboard and API in insecure mode for local development
      - --api.insecure=true
  db:
    ports:
      - "5432:5432"

  adminer:
    ports:
      - "8080:8080"

  backend:
    ports:
      - "8000:8000"
    build:
      context: .
      dockerfile: backend/Dockerfile
    # command: sleep infinity  # Infinite loop to keep container alive doing nothing
    command:
      - fastapi
      - dev
      - --host
      - "0.0.0.0"
    develop:
      watch:
        - path: ./backend
          action: sync
          target: /app/backend
          ignore:
            - .venv
        - path: ./backend/pyproject.toml
          action: rebuild
        - path: ./frontend
          action: rebuild
          ignore:
            - ./frontend/node_modules
            - ./frontend/dist
            - ./frontend/blob-report
            - ./frontend/test-results
    # TODO: remove once coverage is done locally
    volumes:
      - ./backend/htmlcov:/app/backend/htmlcov
    environment:
      FASTAPI_ENV: "development"
      SMTP_HOST: "mailpit"
      SMTP_PORT: "1025"
      SMTP_TLS: "false"

  mailpit:
    image: axllent/mailpit
    ports:
      - "8025:8025"
      - "1025:1025"

  playwright:
    build:
      context: .
      dockerfile: frontend/Dockerfile.playwright
      args:
        - NODE_ENV=production
    ipc: host
    depends_on:
      - backend
      - mailpit
    environment:
      - FIRST_SUPERUSER=${FIRST_SUPERUSER:?Variable not set}
      - FIRST_SUPERUSER_PASSWORD=${FIRST_SUPERUSER_PASSWORD:?Variable not set}
      - PLAYWRIGHT_BASE_URL=http://backend:8000
      - VITE_API_URL=http://backend:8000
      - MAILPIT_HOST=http://mailpit:8025
      # For the reports when run locally
      - PLAYWRIGHT_HTML_HOST=0.0.0.0
      - CI=${CI:-}
    volumes:
      - ./frontend/blob-report:/app/frontend/blob-report
      - ./frontend/test-results:/app/frontend/test-results
    ports:
      - 9323:9323