version: 1
kind: platform-infra-sub2rank

metadata:
  id: apistate-public
  owner: unidesk
  relatedIssues: []

defaults:
  targetId: NC01

webProbe:
  enabled: true
  runner:
    node: NC01
    lane: v03
  origin:
    browserProxyMode: direct
    nativeBaseUrl: http://127.0.0.1:5173
  authentication:
    path: /api/login
    usernameField: username
    passwordField: password
    passwordTargetKey: APISTATE_WEB_PASSWORD
    cookieNames:
      - apistate_session
  defaultSmokeProfile: operations
  smokeProfiles:
    operations:
      navigationTimeoutMs: 30000
      commandTimeoutSeconds: 180
      settleMs: 500
      viewport:
        width: 1920
        height: 1080
      pages:
        - id: scores
          path: /scores
          readySelector: '#score-body tr'
          screenshotName: apistate-scores.png
        - id: ranking
          path: /ranking
          readySelector: '#ranking-body tr'
          screenshotName: apistate-ranking.png
        - id: lottery
          path: /lottery
          readySelector: '#record-list li'
          screenshotName: apistate-lottery.png
      outputLimits:
        failures: 8
        network: 24

application:
  repository: pikasTech/apistate
  remote: https://github.com/pikasTech/apistate.git
  branch: master
  sourceRoot: /root/apistate
  configRef: /root/apistate/config/sub2rank.yaml
  sourceConfigPath: config/sub2rank.yaml
  dockerfile: Dockerfile
  runtimeTarget: k8s

image:
  repository: 127.0.0.1:5000/sub2rank/sub2rank
  pullPolicy: IfNotPresent

delivery:
  enabled: true
  pipeline:
    namespace: devops-infra
    name: platform-infra-sub2rank-nc01-pac
    runPrefix: sub2rank-nc01
    serviceAccountName: sub2rank-nc01-tekton-runner
    timeout: 600s
    workspaceSize: 4Gi
    toolsImage: 127.0.0.1:5000/hwlab/hwlab-ci-node-tools:node22-alpine-bun-v1
    buildkitImage: 127.0.0.1:5000/hwlab/buildkit:rootless
    sourceSnapshotPrefix: refs/unidesk/snapshots/gitea-actions/apistate-master-nc01
  build:
    networkMode: host
    proxy:
      http: http://127.0.0.1:10808
      https: http://127.0.0.1:10808
      all: http://127.0.0.1:10808
      noProxy:
        - localhost
        - 127.0.0.1
        - "::1"
        - 127.0.0.1:5000
        - localhost:5000
        - .svc
        - .svc.cluster.local
        - .cluster.local
        - hyueapi.com
        - .hyueapi.com
  gitops:
    readUrl: http://git-mirror-http.devops-infra.svc.cluster.local:8080/pikasTech/unidesk.git
    writeUrl: http://git-mirror-write.devops-infra.svc.cluster.local:8080/pikasTech/unidesk.git
    branch: unidesk-host-gitops
    manifestPath: deploy/gitops/platform-infra/sub2rank-nc01/resources.yaml
    releaseStatePath: deploy/gitops-state/platform-infra/sub2rank-nc01.json
    maxPushAttempts: 3
    author:
      name: UniDesk Sub2Rank CI
      email: sub2rank-ci@unidesk.local
    application:
      name: sub2rank-nc01
      namespace: argocd
      project: default
      path: deploy/gitops/platform-infra/sub2rank-nc01
      destinationNamespace: platform-infra
      automated: true
  profiles:
    development:
      targetId: NC01_DEV
      sourceBranch: development
      pipeline:
        namespace: devops-infra
        name: platform-infra-sub2rank-development-nc01-pac
        runPrefix: sub2rank-development-nc01
        serviceAccountName: sub2rank-development-nc01-tekton-runner
        timeout: 600s
        workspaceSize: 4Gi
        toolsImage: 127.0.0.1:5000/hwlab/hwlab-ci-node-tools:node22-alpine-bun-v1
        buildkitImage: 127.0.0.1:5000/hwlab/buildkit:rootless
        sourceSnapshotPrefix: refs/unidesk/snapshots/gitea-actions/apistate-development-nc01
      gitops:
        readUrl: http://git-mirror-http.devops-infra.svc.cluster.local:8080/pikasTech/unidesk.git
        writeUrl: http://git-mirror-write.devops-infra.svc.cluster.local:8080/pikasTech/unidesk.git
        branch: unidesk-host-gitops
        manifestPath: deploy/gitops/platform-infra/sub2rank-development-nc01/resources.yaml
        releaseStatePath: deploy/gitops-state/platform-infra/sub2rank-development-nc01.json
        maxPushAttempts: 3
        author:
          name: UniDesk Sub2Rank CI
          email: sub2rank-ci@unidesk.local
        application:
          name: sub2rank-development-nc01
          namespace: argocd
          project: default
          path: deploy/gitops/platform-infra/sub2rank-development-nc01
          destinationNamespace: platform-infra-development
          automated: true

targets:
  - id: NC01
    route: NC01:k3s
    namespace: platform-infra
    enabled: true
    replicas: 1
    manageNamespace: false
    applicationRuntimeTarget: k8s
    secretDeclarationId: sub2rank-runtime
    temporalTaskQueue: apistate
    scoreScheduleWorkflowId: apistate-score-refresh-schedule
    publicExposure:
      enabled: false
      publicBaseUrl: https://apistate.hwpod.com
      dns:
        hostname: apistate.hwpod.com
        expectedA: 152.53.229.148
        resolvers:
          - 1.1.1.1
          - 8.8.8.8
          - 223.5.5.5
          - 114.114.114.114
      frpc:
        deploymentName: sub2rank-frpc
        configMapName: sub2rank-frpc-config
        configKey: frpc.toml
        image: 127.0.0.1:5000/hwlab/frpc:v0.68.1
        serverAddr: 82.156.23.220
        serverPort: 22000
        proxyName: platform-infra-sub2rank-nc01-web
        remotePort: 22095
        localIP: sub2rank.platform-infra.svc.cluster.local
        localPort: 8080
        tokenEnvName: FRP_TOKEN
        tokenTargetKey: FRP_TOKEN
      pk01:
        route: PK01
        caddyConfigPath: /etc/caddy/Caddyfile
        caddyServiceName: caddy
        responseHeaderTimeoutSeconds: 60
    publicEdge:
      enabled: true
      hostname: apistate.hwpod.com
      upstream: sub2rank.platform-infra.svc.cluster.local:8080
      healthPath: /health
      expectedA: 152.53.229.148
  - id: NC01_DEV
    route: NC01:k3s
    namespace: platform-infra-development
    enabled: true
    replicas: 1
    manageNamespace: true
    applicationRuntimeTarget: development
    secretDeclarationId: sub2rank-development-runtime
    temporalTaskQueue: apistate-development
    scoreScheduleWorkflowId: apistate-development-score-refresh-schedule
    publicExposure:
      enabled: false
      publicBaseUrl: https://apistate-development.invalid
      dns:
        hostname: apistate-development.invalid
        expectedA: 127.0.0.1
        resolvers:
          - 1.1.1.1
      frpc:
        deploymentName: sub2rank-development-frpc
        configMapName: sub2rank-development-frpc-config
        configKey: frpc.toml
        image: 127.0.0.1:5000/hwlab/frpc:v0.68.1
        serverAddr: 127.0.0.1
        serverPort: 22000
        proxyName: platform-infra-sub2rank-development-nc01-web
        remotePort: 22096
        localIP: sub2rank.platform-infra-development.svc.cluster.local
        localPort: 8080
        tokenEnvName: FRP_TOKEN
        tokenTargetKey: FRP_TOKEN
      pk01:
        route: PK01
        caddyConfigPath: /etc/caddy/Caddyfile
        caddyServiceName: caddy
        responseHeaderTimeoutSeconds: 60
    publicEdge:
      enabled: false
      hostname: apistate-development.invalid
      upstream: sub2rank.platform-infra-development.svc.cluster.local:8080
      healthPath: /health
      expectedA: 127.0.0.1

runtime:
  sharedNetworkPolicyRef:
    name: allow-all
    managedBySub2Rank: false
  service:
    name: sub2rank
    port: 8080
  worker:
    name: sub2rank-worker
    healthPort: 8081
  temporal:
    addressEnv: APISTATE_TEMPORAL_ADDRESS
    address: temporal-frontend.temporal.svc.cluster.local:7233
  configMap:
    name: sub2rank-config
    key: sub2rank.yaml
    mountPath: /etc/sub2rank/sub2rank.yaml
  command:
    - bun
    - src/api.ts
    - --config
    - /etc/sub2rank/sub2rank.yaml
    - --runtime
    - k8s
  workerCommand:
    - bun
    - src/worker.ts
    - --config
    - /etc/sub2rank/sub2rank.yaml
    - --runtime
    - k8s
  storage:
    claimName: sub2rank-data
    size: 1Gi
    mountPath: /var/lib/sub2rank
  hostMounts:
    - source: /root/unidesk
      target: /opt/unidesk
      readOnly: true
  secret:
    configRef: config/secrets-distribution.yaml
    declarationId: sub2rank-runtime
    requiredTargetKeys:
      - APISTATE_WEB_PASSWORD
      - APISTATE_API_KEY
      - APISTATE_SESSION_SECRET
      - SUB2API_ADMIN_EMAIL
      - SUB2API_ADMIN_PASSWORD
      - FRP_TOKEN
    appEnvTargetKeys:
      - APISTATE_WEB_PASSWORD
      - APISTATE_API_KEY
      - APISTATE_SESSION_SECRET
      - SUB2API_ADMIN_EMAIL
      - SUB2API_ADMIN_PASSWORD
  probes:
    healthPath: /health
    initialDelaySeconds: 3
    periodSeconds: 10
    timeoutSeconds: 3
    failureThreshold: 6
  rollout:
    fieldManager: unidesk-platform-sub2rank
    waitTimeoutSeconds: 180
