services:
  frontend:
    build:
      context: .
      dockerfile: Dockerfile.web
    image: local-page-archiver-web:latest
    command: ["node", "src/frontend-server.mjs"]
    environment:
      PORT: "5731"
      BACKEND_URL: "http://backend:5732"
    ports:
      - "5731:5731"
    depends_on:
      backend:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:5731/healthz').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"]
      interval: 10s
      timeout: 3s
      retries: 5

  backend:
    build:
      context: .
      dockerfile: Dockerfile.web
    image: local-page-archiver-web:latest
    command: ["node", "src/backend-server.mjs"]
    environment:
      PORT: "5732"
      ARCHIVE_PATH: /archives
      ARCHIVE_WORKER_URL: "http://browser:5733"
      PUBLIC_ARCHIVES_PATH: /archives
    volumes:
      - archives:/archives
    depends_on:
      browser:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:5732/healthz').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"]
      interval: 10s
      timeout: 3s
      retries: 5

  browser:
    build:
      context: .
      dockerfile: Dockerfile
    image: local-page-archiver-browser:latest
    command: ["serve-worker"]
    environment:
      PORT: "5733"
      ARCHIVE_PATH: /archives
      ARCHIVE_WORKER_XVFB: "1"
    volumes:
      - archives:/archives
    expose:
      - "5733"
    shm_size: 1gb
    healthcheck:
      test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:5733/healthz').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"]
      interval: 10s
      timeout: 3s
      retries: 10

volumes:
  archives:
