version: '3.4'
services:
  mysql:
    image: mysql:8.0.36
    platform: linux/x86_64
    environment:
      - MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
    expose:
      - 3306
    volumes:
      - mysql_data:/var/lib/mysql
    restart: unless-stopped
    healthcheck:
      test: ["CMD", 'mysqladmin', 'ping', '-h', 'localhost', '-u', 'root', '-p$$MYSQL_ROOT_PASSWORD' ]
      interval: 5s
      timeout: 20s
      retries: 30
  redis:
    image: redis
    expose:
      - "6379"
    restart: always
    volumes:
      - redis_data:/data
  api:
    platform: linux/x86_64
    image: "ghcr.io/parcelvoy/api:${IMAGE_VERSION:-latest}"
    restart: always
    healthcheck:
      test: wget --no-verbose --tries=1 --spider http://localhost:3001/api/health || exit 1
      interval: 5s
      retries: 30
      start_period: 20s
      timeout: 10s
    ports:
      - 3001:3001
    links:
      - mysql:mysql
      - redis:redis
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_started
    environment:
      NODE_ENV: ${NODE_ENV}
      BASE_URL: ${BASE_URL}
      RUNNER: 'api'
      APP_SECRET: ${APP_SECRET}
      PORT: 3001
      LOG_LEVEL: ${LOG_LEVEL:-info}
      LOG_COMPILED_MESSAGE: ${LOG_COMPILED_MESSAGE:-true}
      DB_CLIENT: ${DB_CLIENT}
      DB_HOST: mysql
      DB_USERNAME: ${DB_USERNAME}
      DB_PASSWORD: ${DB_PASSWORD}
      DB_PORT: ${DB_PORT}
      DB_DATABASE: ${DB_DATABASE}
      STORAGE_DRIVER: ${STORAGE_DRIVER}
      STORAGE_BASE_URL: ${STORAGE_BASE_URL}
      STORAGE_S3_BUCKET: ${STORAGE_S3_BUCKET}
      STORAGE_S3_ENDPOINT: ${STORAGE_S3_ENDPOINT}
      STORAGE_S3_FORCE_PATH_STYLE: ${STORAGE_S3_FORCE_PATH_STYLE}
      AWS_S3_BUCKET: ${AWS_S3_BUCKET}
      QUEUE_DRIVER: ${QUEUE_DRIVER}
      REDIS_HOST: ${REDIS_HOST}
      REDIS_PORT: ${REDIS_PORT}
      REDIS_TLS: ${REDIS_TLS}
      REDIS_CONCURRENCY: ${REDIS_CONCURRENCY}
      REDIS_USERNAME: ${REDIS_USERNAME}
      REDIS_PASSWORD: ${REDIS_PASSWORD}
      AWS_SQS_QUEUE_URL: ${AWS_SQS_QUEUE_URL}
      AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
      AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
      AWS_REGION: ${AWS_REGION}
      AUTH_DRIVER: ${AUTH_DRIVER}
      AUTH_BASIC_EMAIL: ${AUTH_BASIC_EMAIL}
      AUTH_BASIC_PASSWORD: ${AUTH_BASIC_PASSWORD}
      AUTH_BASIC_NAME: ${AUTH_BASIC_NAME}
      AUTH_SAML_CALLBACK_URL: ${AUTH_SAML_CALLBACK_URL}
      AUTH_SAML_ENTRY_POINT_URL: ${AUTH_SAML_ENTRY_POINT_URL}
      AUTH_SAML_ISSUER: ${AUTH_SAML_ISSUER}
      AUTH_SAML_CERT: ${AUTH_SAML_CERT}
      AUTH_SAML_IS_AUTHN_SIGNED: ${AUTH_SAML_IS_AUTHN_SIGNED}
      AUTH_SAML_NAME: ${AUTH_SAML_NAME}
      AUTH_OPENID_ISSUER_URL: ${AUTH_OPENID_ISSUER_URL}
      AUTH_OPENID_CLIENT_ID: ${AUTH_OPENID_CLIENT_ID}
      AUTH_OPENID_CLIENT_SECRET: ${AUTH_OPENID_CLIENT_SECRET}
      AUTH_OPENID_REDIRECT_URI: ${AUTH_OPENID_REDIRECT_URI}
      AUTH_OPENID_DOMAIN_WHITELIST: ${AUTH_OPENID_DOMAIN_WHITELIST}
      AUTH_OPENID_RESPONSE_TYPES: ${AUTH_OPENID_RESPONSE_TYPES}
      AUTH_OPENID_NAME: ${AUTH_OPENID_NAME}
      AUTH_GOOGLE_ISSUER_URL: ${AUTH_GOOGLE_ISSUER_URL}
      AUTH_GOOGLE_CLIENT_ID: ${AUTH_GOOGLE_CLIENT_ID}
      AUTH_GOOGLE_CLIENT_SECRET: ${AUTH_GOOGLE_CLIENT_SECRET}
      AUTH_GOOGLE_NAME: ${AUTH_GOOGLE_NAME}
      ERROR_DRIVER: ${ERROR_DRIVER}
      ERROR_BUGSNAG_API_KEY: ${ERROR_BUGSNAG_API_KEY}
      ERROR_SENTRY_DSN: ${ERROR_SENTRY_DSN}
      TRACKING_LINK_WRAP: ${TRACKING_LINK_WRAP}
      TRACKING_DEEPLINK_MIRROR_URL: ${TRACKING_DEEPLINK_MIRROR_URL}
    volumes:
      - uploads:/usr/src/app/public/uploads
  worker:
    platform: linux/x86_64
    image: "ghcr.io/parcelvoy/api:${IMAGE_VERSION:-latest}"
    restart: always
    links:
      - mysql:mysql
      - redis:redis
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_started
      api:
        condition: service_healthy
    environment:
      NODE_ENV: ${NODE_ENV}
      BASE_URL: ${BASE_URL}
      RUNNER: 'worker'
      APP_SECRET: ${APP_SECRET}
      LOG_LEVEL: ${LOG_LEVEL:-info}
      LOG_COMPILED_MESSAGE: ${LOG_COMPILED_MESSAGE:-true}
      DB_CLIENT: ${DB_CLIENT}
      DB_HOST: mysql
      DB_USERNAME: ${DB_USERNAME}
      DB_PASSWORD: ${DB_PASSWORD}
      DB_PORT: ${DB_PORT}
      DB_DATABASE: ${DB_DATABASE}
      STORAGE_DRIVER: ${STORAGE_DRIVER}
      STORAGE_BASE_URL: ${STORAGE_BASE_URL}
      STORAGE_S3_BUCKET: ${STORAGE_S3_BUCKET}
      STORAGE_S3_ENDPOINT: ${STORAGE_S3_ENDPOINT}
      STORAGE_S3_FORCE_PATH_STYLE: ${STORAGE_S3_FORCE_PATH_STYLE}
      AWS_S3_BUCKET: ${AWS_S3_BUCKET}
      QUEUE_DRIVER: ${QUEUE_DRIVER}
      REDIS_HOST: ${REDIS_HOST}
      REDIS_PORT: ${REDIS_PORT}
      REDIS_TLS: ${REDIS_TLS}
      REDIS_CONCURRENCY: ${REDIS_CONCURRENCY}
      REDIS_USERNAME: ${REDIS_USERNAME}
      REDIS_PASSWORD: ${REDIS_PASSWORD}
      AWS_SQS_QUEUE_URL: ${AWS_SQS_QUEUE_URL}
      AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
      AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
      AWS_REGION: ${AWS_REGION}
      AUTH_DRIVER: ${AUTH_DRIVER}
      AUTH_BASIC_EMAIL: ${AUTH_BASIC_EMAIL}
      AUTH_BASIC_PASSWORD: ${AUTH_BASIC_PASSWORD}
      AUTH_BASIC_NAME: ${AUTH_BASIC_NAME}
      AUTH_SAML_CALLBACK_URL: ${AUTH_SAML_CALLBACK_URL}
      AUTH_SAML_ENTRY_POINT_URL: ${AUTH_SAML_ENTRY_POINT_URL}
      AUTH_SAML_ISSUER: ${AUTH_SAML_ISSUER}
      AUTH_SAML_CERT: ${AUTH_SAML_CERT}
      AUTH_SAML_IS_AUTHN_SIGNED: ${AUTH_SAML_IS_AUTHN_SIGNED}
      AUTH_SAML_NAME: ${AUTH_SAML_NAME}
      AUTH_OPENID_ISSUER_URL: ${AUTH_OPENID_ISSUER_URL}
      AUTH_OPENID_CLIENT_ID: ${AUTH_OPENID_CLIENT_ID}
      AUTH_OPENID_CLIENT_SECRET: ${AUTH_OPENID_CLIENT_SECRET}
      AUTH_OPENID_REDIRECT_URI: ${AUTH_OPENID_REDIRECT_URI}
      AUTH_OPENID_DOMAIN_WHITELIST: ${AUTH_OPENID_DOMAIN_WHITELIST}
      AUTH_OPENID_NAME: ${AUTH_OPENID_NAME}
      AUTH_GOOGLE_ISSUER_URL: ${AUTH_GOOGLE_ISSUER_URL}
      AUTH_GOOGLE_CLIENT_ID: ${AUTH_GOOGLE_CLIENT_ID}
      AUTH_GOOGLE_CLIENT_SECRET: ${AUTH_GOOGLE_CLIENT_SECRET}
      AUTH_GOOGLE_NAME: ${AUTH_GOOGLE_NAME}
      ERROR_DRIVER: ${ERROR_DRIVER}
      ERROR_BUGSNAG_API_KEY: ${ERROR_BUGSNAG_API_KEY}
      ERROR_SENTRY_DSN: ${ERROR_SENTRY_DSN}
      TRACKING_LINK_WRAP: ${TRACKING_LINK_WRAP}
      TRACKING_DEEPLINK_MIRROR_URL: ${TRACKING_DEEPLINK_MIRROR_URL}
  ui:
    platform: linux/x86_64
    image: "ghcr.io/parcelvoy/ui:${PARCELVOY_VERSION:-latest}"
    depends_on:
      api:
        condition: service_healthy
    environment:
      API_BASE_URL: ${API_BASE_URL}
    ports:
      - ${UI_PORT}:3000
volumes:
  mysql_data:
    driver: local
  redis_data:
    driver: local
  uploads:
    driver: local
