zerops:
  - setup: api
    build:
      os: ubuntu
      buildCommands:
        - wget -q https://github.com/zitadel/zitadel/releases/download/v4.13.1/zitadel-linux-amd64.tar.gz -O - | tar -xz
        - mv zitadel-linux-amd64/zitadel ./zitadel
        - chmod +x ./zitadel
      deployFiles:
        - ./
    run:
      os: ubuntu
      envVariables:
        ZITADEL_DATABASE_POSTGRES_HOST: db
        ZITADEL_DATABASE_POSTGRES_PORT: ${db_port}
        ZITADEL_DATABASE_POSTGRES_DATABASE: ${db_dbName}
        ZITADEL_DATABASE_POSTGRES_USER_USERNAME: ${db_superUser}
        ZITADEL_DATABASE_POSTGRES_USER_PASSWORD: ${db_superUserPassword}
        ZITADEL_DATABASE_POSTGRES_USER_SSL_MODE: disable
        ZITADEL_DATABASE_POSTGRES_ADMIN_USERNAME: ${db_superUser}
        ZITADEL_DATABASE_POSTGRES_ADMIN_PASSWORD: ${db_superUserPassword}
        ZITADEL_DATABASE_POSTGRES_ADMIN_SSL_MODE: disable
        ZITADEL_EXTERNALPORT: "443"
        ZITADEL_EXTERNALSECURE: "true"
      ports:
        - port: 8080
          httpSupport: true
      initCommands:
        - zsc execOnce zitadel-init -- ./zitadel init
        - zsc execOnce zitadel-setup-${appVersionId} -- ./zitadel setup --masterkey "${ZITADEL_MASTERKEY}" --tlsMode external
        - |
          if [ -f /tmp/login-client.pat ]; then
            cat /tmp/login-client.pat | zsc setSecretEnv ZITADEL_LOGIN_PAT -
          fi
      start: ./zitadel start --masterkey "${ZITADEL_MASTERKEY}" --tlsMode external
      healthCheck:
        httpGet:
          port: 8080
          path: /debug/healthz

  - setup: login
    build:
      os: ubuntu
      base: nodejs@22
      prepareCommands:
        - wget -q "https://github.com/google/go-containerregistry/releases/download/v0.20.3/go-containerregistry_Linux_x86_64.tar.gz" -O - | tar -xz crane
        - sudo mv crane /usr/local/bin/crane
        - sudo chmod +x /usr/local/bin/crane
      buildCommands:
        - crane export ghcr.io/zitadel/zitadel-login:latest - | tar -xf - -C /build/source app/
        - ls -la
      deployFiles:
        - ./
    run:
      os: ubuntu
      base: nodejs@22
      envVariables:
        NEXT_PUBLIC_BASE_PATH: /ui/v2/login
        ZITADEL_API_URL: https://${api_ZITADEL_EXTERNALDOMAIN}
        ZITADEL_SERVICE_USER_TOKEN: ${api_ZITADEL_LOGIN_PAT}
      ports:
        - port: 3000
          httpSupport: true
      start: node app/apps/login/server.js
      healthCheck:
        httpGet:
          port: 3000
          path: /ui/v2/login/healthy
