# documentation: https://docs.hoppscotch.io
# slogan: The Open Source API Development Platform
# category: devtools
# tags: api, development, platform
# logo: svgs/hoppscotch.png
# port: 80

services:
  backend:
    image: hoppscotch/hoppscotch:latest
    environment:
      - SERVICE_URL_HOPPSCOTCH_80
      - VITE_ALLOWED_AUTH_PROVIDERS=${VITE_ALLOWED_AUTH_PROVIDERS:-GOOGLE,GITHUB,MICROSOFT,EMAIL}
      - DATABASE_URL=postgresql://${SERVICE_USER_POSTGRES}:${SERVICE_PASSWORD_POSTGRES}@hoppscotch-db:5432/${POSTGRES_DB}
      - DATA_ENCRYPTION_KEY=${SERVICE_BASE64_DATAENCRYPTIONKEY}
      - WHITELISTED_ORIGINS=${SERVICE_URL_HOPPSCOTCH}/backend,${SERVICE_URL_HOPPSCOTCH},${SERVICE_URL_HOPPSCOTCH}/admin
      - MAILER_USE_CUSTOM_CONFIGS=${MAILER_USE_CUSTOM_CONFIGS:-true}
      - VITE_BASE_URL=${SERVICE_URL_HOPPSCOTCH}
      - VITE_SHORTCODE_BASE_URL=${SERVICE_URL_HOPPSCOTCH}
      - VITE_ADMIN_URL=${SERVICE_URL_HOPPSCOTCH}/admin
      - VITE_BACKEND_GQL_URL=${SERVICE_URL_HOPPSCOTCH}/backend/graphql
      - VITE_BACKEND_WS_URL=wss://${SERVICE_FQDN_HOPPSCOTCH}/backend/graphql
      - VITE_BACKEND_API_URL=${SERVICE_URL_HOPPSCOTCH}/backend/v1
      - VITE_APP_TOS_LINK=https://docs.hoppscotch.io/support/terms
      - VITE_APP_PRIVACY_POLICY_LINK=https://docs.hoppscotch.io/support/privacy
      - ENABLE_SUBPATH_BASED_ACCESS=true
    depends_on:
      db-migration:
        condition: service_completed_successfully
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:80/"]
      interval: 5s
      timeout: 20s
      retries: 10

  hoppscotch-db:
    image: postgres:latest
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=${SERVICE_USER_POSTGRES}
      - POSTGRES_PASSWORD=${SERVICE_PASSWORD_POSTGRES}
      - POSTGRES_DB=${POSTGRES_DB:-hoppscotch}
    healthcheck:
      test:
        - CMD-SHELL
        - 'pg_isready -h localhost -U $${POSTGRES_USER} -d $${POSTGRES_DB}'
      interval: 5s
      timeout: 10s
      retries: 10

  db-migration:
    exclude_from_hc: true
    image: hoppscotch/hoppscotch:latest
    depends_on:
      hoppscotch-db:
        condition: service_healthy
    command: 'pnpx prisma migrate deploy'
    restart: on-failure
    environment:
      - POSTGRES_USER=${SERVICE_USER_POSTGRES}
      - POSTGRES_PASSWORD=${SERVICE_PASSWORD_POSTGRES}
      - POSTGRES_DB=${POSTGRES_DB:-hoppscotch}
      - DATABASE_URL=postgres://${SERVICE_USER_POSTGRES}:${SERVICE_PASSWORD_POSTGRES}@hoppscotch-db:5432/${POSTGRES_DB:-hoppscotch}
