version: "3.9"

services:
  molva-api-gateway:
    image: molvaapp/test_deploy:${VERSION}
    ports:
      - target: 8000
        published: 8001
        protocol: tcp
    environment:
      APP_VERSION: ${VERSION}
      APP_COMMIT: ${APP_COMMIT}
      APP_BUILD_DATE: ${APP_BUILD_DATE}

      KEYCLOAK_BASE_URL: ${KEYCLOAK_BASE_URL}
      KEYCLOAK_REALM: ${KEYCLOAK_REALM}
      KEYCLOAK_CLIENT_ID: ${KEYCLOAK_CLIENT_ID}
      KEYCLOAK_CLIENT_SECRET: ${KEYCLOAK_CLIENT_SECRET}

      BROKER_HOST: ${BROKER_HOST}
      BROKER_PORT: ${BROKER_PORT}
      BROKER_USERNAME: ${BROKER_USERNAME}
      BROKER_PASSWORD: ${BROKER_PASSWORD}

      SHORTENER_SECRET_KEY: ${SHORTENER_SECRET_KEY}

      CACHE_ADDRS: ${CACHE_ADDRS}
      CACHE_PASSWORD: ${CACHE_PASSWORD}

      DB_HOSTS: ${DB_HOSTS}
      DB_PORT: ${DB_PORT}
      DB_USERNAME: ${DB_USERNAME}
      DB_PASSWORD: ${DB_PASSWORD}
      DB_DBNAME: ${DB_DBNAME}

      INTEGRATION_VKUSVILL_API_TOKEN: ${INTEGRATION_VKUSVILL_API_TOKEN}
    volumes:
      - /opt/molva:/opt/molva
      - /opt/molva/object_storage/credentials:/root/.aws/credentials:ro
      - /opt/molva/object_storage/config:/root/.aws/config:ro
    networks:
      - molva
    deploy:
      mode: replicated
      replicas: 1
      restart_policy:
        condition: none
        delay: 20s
        window: 120s
      update_config:
        parallelism: 1
        failure_action: rollback
        monitor: 30s
        max_failure_ratio: 0.3
        order: start-first
      rollback_config:
        parallelism: 0
        failure_action: continue
        order: start-first
      placement:
        constraints:
          - node.labels.env == stg
          - node.labels.app == true
        preferences:
          - spread: node.labels.TZ

networks:
  molva:
    driver: overlay
    attachable: true