# Legacy location. Deploy the REST SQL adapter from
# core/deploy/docker/adapter-1c/compose.yaml to docker.cin.su.
name: adapter-1c

services:
  adapter-1c-rest:
    build:
      context: ../../../../plugins/1c
      dockerfile: connector/Dockerfile
    image: ${ADAPTER_1C_IMAGE:-adapter-1c-rest:latest}
    container_name: ${ADAPTER_1C_CONTAINER_NAME:-adapter-1c-rest}
    restart: unless-stopped
    stop_grace_period: 5m
    ports:
      - "${ADAPTER_1C_HOST_PORT:-8011}:8011"
    volumes:
      - adapter-1c-data:/data
    environment:
      ONEC_ADAPTER_HOST: 0.0.0.0
      ONEC_ADAPTER_PORT: 8011
      ONEC_ADAPTER_SERVICE_TOKEN: ${ONEC_ADAPTER_SERVICE_TOKEN:-}
      ONEC_ADAPTER_ALLOW_UNAUTHENTICATED_ADMIN: ${ONEC_ADAPTER_ALLOW_UNAUTHENTICATED_ADMIN:-true}
      ONEC_SQL_BASES_JSON: ${ONEC_SQL_BASES_JSON:-}
      ONEC_SQL_BASES_JSON_FILE: ${ONEC_SQL_BASES_JSON_FILE:-/data/onec-sql-bases.json}
      ONEC_ADAPTER_CACHE_DB: ${ONEC_ADAPTER_CACHE_DB:-/data/adapter-cache.sqlite}
      ONEC_ADAPTER_STATE_DB: ${ONEC_ADAPTER_STATE_DB:-/data/adapter-cache.sqlite}
      ONEC_ADAPTER_JOB_STORE: ${ONEC_ADAPTER_JOB_STORE:-/data/adapter-jobs.json}
      ONEC_REPOSITORY_STATE_FILE: ${ONEC_REPOSITORY_STATE_FILE:-/data/onec-repository-locks.json}
      ONEC_ADAPTER_BACKUP_DIR: ${ONEC_ADAPTER_BACKUP_DIR:-/data/adapter-apply-backups}
      ONEC_CONFIGURATION_ACTIVATION_STATE_FILE: ${ONEC_CONFIGURATION_ACTIVATION_STATE_FILE:-/data/onec-configuration-activation-requests.json}
      ONEC_CONFIGURATION_ACTIVATION_REQUEST_TTL_SECONDS: ${ONEC_CONFIGURATION_ACTIVATION_REQUEST_TTL_SECONDS:-1800}
      ONEC_ADAPTER_JOB_TIMEOUT_SECONDS: ${ONEC_ADAPTER_JOB_TIMEOUT_SECONDS:-240}
      ONEC_ADAPTER_FULL_TIMEOUT_SECONDS: ${ONEC_ADAPTER_FULL_TIMEOUT_SECONDS:-600}
      ONEC_ADAPTER_SECTION_TIMEOUT_SECONDS: ${ONEC_ADAPTER_SECTION_TIMEOUT_SECONDS:-180}
      ONEC_ADAPTER_JOB_PROCESS_ISOLATION: ${ONEC_ADAPTER_JOB_PROCESS_ISOLATION:-true}
      ONEC_ADAPTER_JOB_MEMORY_LIMIT_MB: ${ONEC_ADAPTER_JOB_MEMORY_LIMIT_MB:-0}
      ONEC_ADAPTER_JOB_CPU_LIMIT_SECONDS: ${ONEC_ADAPTER_JOB_CPU_LIMIT_SECONDS:-0}
      ONEC_ADAPTER_DEBUG_DIAGNOSTICS: ${ONEC_ADAPTER_DEBUG_DIAGNOSTICS:-false}
      ONEC_INFOBASE_USER_ADMIN_BASES_JSON: ${ONEC_INFOBASE_USER_ADMIN_BASES_JSON:-}
      ONEC_INFOBASE_USER_ADMIN_BASES_JSON_FILE: ${ONEC_INFOBASE_USER_ADMIN_BASES_JSON_FILE:-/data/onec-infobase-user-admin.json}
      ONEC_INFOBASE_USER_ADMIN_TOKEN_UPO_TEST: ${ONEC_INFOBASE_USER_ADMIN_TOKEN_UPO_TEST:-}
      ONEC_INFOBASE_USER_ADMIN_ALLOW_UNAUTHENTICATED: ${ONEC_INFOBASE_USER_ADMIN_ALLOW_UNAUTHENTICATED:-false}
      ONEC_REPOSITORY_RUNNER_TOKEN: ${ONEC_REPOSITORY_RUNNER_TOKEN:-}
      ONEC_ADAPTER_ENABLE_EXTERNAL_1C: ${ONEC_ADAPTER_ENABLE_EXTERNAL_1C:-false}
      ONEC_REPOSITORY_REQUEST_TTL_SECONDS: ${ONEC_REPOSITORY_REQUEST_TTL_SECONDS:-86400}
      ONEC_REPOSITORY_CONFIRMATION_TTL_SECONDS: ${ONEC_REPOSITORY_CONFIRMATION_TTL_SECONDS:-7200}

  adapter-1c-audit:
    image: ${ADAPTER_1C_IMAGE:-adapter-1c-rest:latest}
    container_name: ${ADAPTER_1C_AUDIT_CONTAINER_NAME:-adapter-1c-audit}
    restart: unless-stopped
    depends_on:
      - adapter-1c-rest
    volumes:
      - adapter-1c-data:/data
    environment:
      ONEC_ADAPTER_AUDIT_INTERVAL_SECONDS: ${ONEC_ADAPTER_AUDIT_INTERVAL_SECONDS:-900}
    command: >-
      sh -c 'mkdir -p /data/adapter-audit-reports;
      while true; do python /app/analyze_audit.py --log /data/adapter-audit.jsonl > /data/adapter-audit-reports/latest.json.tmp
      && mv /data/adapter-audit-reports/latest.json.tmp /data/adapter-audit-reports/latest.json;
      sleep "$${ONEC_ADAPTER_AUDIT_INTERVAL_SECONDS}"; done'

volumes:
  adapter-1c-data:
