version: 1
kind: platform-infra-nginx

metadata:
  name: nginx

defaults:
  target: PK01

artifacts:
  image:
    buildTarget: NC01
    image: nginx-lb-logger:1.0.0
    imageId: sha256:a0d4cef22b9e9e602f853da17bf965408d4cbb5c0a06e272bff1342038ef9343
    localPath: /root/demo/nginx-lb-logger/artifacts/nginx-lb-logger-1.0.0.tar.gz
    remotePath: /opt/unidesk/nginx/artifacts/nginx-lb-logger-1.0.0.tar.gz
    sha256: af4bb6a5ad4ae9c49e63133be6249c1b3401aa6e9f2c4cfa92b56e8f66660471
    bytes: 65078179
  composePlugin:
    localPath: /root/demo/nginx-lb-logger/artifacts/docker-compose-linux-x86_64
    remotePath: /usr/local/lib/docker/cli-plugins/docker-compose
    sha256: 2f61856d1b8c9de29ffdaedaa1c6d0a5fc5c79da45068f1f4310feed8d3a3f61
  distribution:
    mode: local-http
    workDir: /tmp/unidesk-nginx-artifacts
    bindHost: 0.0.0.0
    port: 19191
    publicBaseUrl: http://152.53.229.148:19191

targets:
  PK01:
    route: PK01
    runtime:
      workDir: /opt/unidesk/nginx
      composePath: /opt/unidesk/nginx/compose.yaml
      envPath: /opt/unidesk/nginx/runtime.env
      projectName: nginx
      containerName: nginx
      networkMode: host
      restart: unless-stopped
      resources:
        cpus: "0.25"
        memory: 64m
        pidsLimit: 64
      logDir: /opt/unidesk/nginx/logs
      routes:
        - listenPort: 19080
          upstreams:
            - host: 127.0.0.1
              port: 19081
            - host: 127.0.0.1
              port: 19082
      environment:
        NGINX_ADMIN_PORT: "19089"
        NGINX_LOAD_BALANCE_METHOD: round_robin
        NGINX_UPSTREAM_KEEPALIVE: "4"
        NGINX_UPSTREAM_MAX_FAILS: "1"
        NGINX_UPSTREAM_FAIL_TIMEOUT: 5s
        NGINX_CLIENT_MAX_BODY_SIZE: 1m
        NGINX_CLIENT_BODY_BUFFER_SIZE: 1m
        NGINX_PROXY_CONNECT_TIMEOUT: 2s
        NGINX_PROXY_READ_TIMEOUT: 10s
        NGINX_PROXY_SEND_TIMEOUT: 10s
        NGINX_PROXY_HOST: $host
        NGINX_BACKEND_ID_HEADER: X-Backend
        LOGGER_PATH: /var/log/logger/requests.jsonl
        LOGGER_MAX_BYTES: "10485760"
        LOGGER_CHECK_INTERVAL_SECONDS: "60"
        LOGGER_ADMIN_PREFIX: /_logger
        LOGGER_TAIL_DEFAULT_LINES: "100"
        LOGGER_TAIL_MAX_LINES: "1000"
        LOGGER_TAIL_MAX_BYTES: "1048576"
        LOGGER_DOWNLOAD_FILENAME: requests.jsonl
        NGINX_WORKER_PROCESSES: "1"
    apiKey:
      sourceRef: .state/secrets/platform-infra/nginx.env
      sourceKey: LOGGER_API_KEY
      targetKey: LOGGER_API_KEY
      requestHeader: X-API-Key
    validation:
      requestCount: 4
      cleanupAfterSuccess: true
      backendScriptPath: /opt/unidesk/nginx/test-backend.py
      backends:
        - id: backend-1
          bindHost: 127.0.0.1
          port: 19081
          unit: nginx-test-backend-1.service
        - id: backend-2
          bindHost: 127.0.0.1
          port: 19082
          unit: nginx-test-backend-2.service
