> This page is for Remediation Orchestrator.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/remediation-orchestrator/llms.txt.

# Deploying Scripts from CI

> Set up a script repository whose CI validates, plans, and deploys tenant bundles with maestroctl, using GitLab CI as the example

This guide sets up a script repository for one or more Remediation Orchestrator deployments.
Each tenant's scripts live in their own directory, and CI turns them into
bundles and deploys them with `maestroctl`, the Remediation Orchestrator
command-line tool for script repositories:

- A merge request validates every changed bundle and shows a plan of what would
  change on each server.
- A merge to the default branch deploys the changed bundles.

The example pipeline uses GitLab CI, which the Remediation Orchestrator team
used for its own script repositories. The `maestroctl` commands don't depend on
GitLab and run in any CI system. To use another CI system, replace the
GitLab-specific parts: the environment-scoped CI/CD variables, the `id_tokens`
that Teleport jobs use to join, the `resource_group` that runs one deploy at a
time, and the `glab` command in step 8. The example pipeline needs GitLab 17.7
or later.

Adding a deployment or tenant is a new directory. The pipeline finds it on its
own.

## 1. Before you start

- Create two OAuth2 clients for CI that can use the client-credentials grant:
  one for plan, mapped to the `viewer` role, and one for deploy, mapped to the
  `script-uploader` role, in each tenant. Plan only reads, so a merge request
  never holds a credential that can deploy. See
  [Authorization](/remediation-orchestrator/guides/authorization). Teleport deployments use Teleport bot
  identities instead. A Teleport identity carries its Teleport role names in the
  JWT `roles` claim. In each tenant, map the plan bot's role to `viewer` and the
  deploy bot's role to `script-uploader` with `[[rbac.role_mappings]]`
  `claim_role`.
- Add two masked CI/CD variables, both named
  `MAESTRO_SCRIPT_MANAGER_CLIENT_SECRET`: one holding the plan client's secret
  with environment scope `maestro-script-plan`, and one holding the deploy
  client's secret with environment scope `maestro-script-deploy`, marked
  protected. GitLab gives each job the variable whose scope matches the job's
  `environment`.
- Run the jobs on a glibc-based image such as `ubuntu:24.04`. `maestroctl` does
  not run on Alpine.

## 2. Create the repository

Create a repository with this layout. The next steps fill it in.

```text
maestro-repository.yaml
template_registry.bzl         templates only
_templates/                   templates only
_configs/                     templates only
_shared/
  shared_*.star
deployments/
  site-a/
    deployment.yaml           authentication: bearer
    tenants/
      default/
        maestro.yaml
        scripts/
          *.star
  site-b/
    deployment.yaml           authentication: bearer
    tenants/
      team-x/
        maestro.yaml
        scripts/
          *.star
      team-y/
        maestro.yaml
        scripts/
          *.star
  site-c/
    deployment.yaml           authentication: teleport
    tenants/
      default/
        maestro.yaml
        scripts/
          *.star
ci/
  with-teleport-app.sh
  install-maestroctl.sh
  install-tbot.sh             Teleport only
.gitlab-ci.yml
.gitignore
```

The directory path names each bundle: `deployments/<deployment>/tenants/<tenant-id>/`
holds the scripts for one tenant on one Remediation Orchestrator deployment.

Add `maestro-repository.yaml` at the root. It marks the repository root, and
every `maestroctl scripts` command reads the repository at `-repository` (the
current directory by default) and fails when the file is not there:

```yaml
schema_version: 1
```

Add a `.gitignore`:

```text
.ci-bin/
.prepared-bundles/
selected-tenants
base-registry
results/
```

## 3. Add a deployment

For each Remediation Orchestrator server, create `deployments/<deployment>/deployment.yaml`. It
says how CI reaches the server, with one of the following authentication methods.
Unknown, missing, or mixed fields fail the pipeline.

### 3.1 bearer

`bearer` gets an OAuth2 access token and sends it in the `Authorization`
header:

```yaml
schema_version: 1
authentication: bearer
maestro_url: https://maestro.site-a.example.com
maestro_api_scope: api://maestro-site-a/.default
```

`maestroctl` exchanges the client credentials in `MAESTRO_TOKEN_URL`,
`MAESTRO_SCRIPT_MANAGER_CLIENT_ID`, and `MAESTRO_SCRIPT_MANAGER_CLIENT_SECRET`
for one token per deployment, requesting `maestro_api_scope`. Without those
variables, such as on a developer's machine, it sends your own token from
`MAESTRO_TOKEN` instead. A token fits one server, so `-deployments` must then
select a single deployment.

#### In-cluster ServiceAccount tokens

Kubernetes authentication is disabled by default. Enable it on the Remediation
Orchestrator server with `MAESTRO_ENABLE_KUBERNETES_AUTH=true`, set
`MAESTRO_KUBERNETES_AUTH_ISSUER` to the cluster's ServiceAccount token issuer, and set
`MAESTRO_KUBERNETES_AUTH_AUDIENCE` to the audience requested by the caller's
projected token. `MAESTRO_KUBERNETES_AUTH_REVIEW_TIMEOUT` defaults to `5s`.
The server uses its own in-cluster credentials to call TokenReview and needs
Kubernetes RBAC permission to `create` `authentication.k8s.io/tokenreviews`.

Set `MAESTRO_DISABLE_NVPROXY_AUTH=true` and leave `MAESTRO_ENABLE_OIDC_AUTH`
disabled. The provider chain rejects Kubernetes authentication combined with
NVProxy or OIDC bearer authentication. Dex and Teleport authentication remain
supported.

The provider authenticates identity only. With Remediation Orchestrator RBAC
enabled, configure the caller's permissions in each tenant, for example:

```toml
[[rbac.client_mappings]]
client_id = "kubernetes:system:serviceaccount:automation:script-uploader"
role = "script-uploader"
```

For a short-lived upload job, read the projected token immediately before
invoking `maestroctl`:

```sh
export MAESTRO_TOKEN="$(cat /var/run/maestro/token)"
maestroctl scripts plan -deployments site-a -tenants default
maestroctl scripts deploy -deployments site-a -tenants default
```

Use a `bearer` deployment with an HTTPS URL. `maestro_api_scope` is still
required by the deployment schema, but is not used when `MAESTRO_TOKEN` supplies
the credential and client-credentials environment variables are unset. A
long-running uploader must reread the projected token as Kubernetes rotates it.
Enabling this provider does not enable HTTPS or Remediation Orchestrator
authorization.

### 3.2 teleport

`teleport` reaches the server through a local Teleport application tunnel,
which carries the identity, so `maestroctl` sends no token:

```yaml
schema_version: 1
authentication: teleport
teleport_app: maestro-site-c
```

## 4. Add a tenant

For each tenant on the server, create
`deployments/<deployment>/tenants/<tenant-id>/maestro.yaml`:

```yaml
schema_version: 1
scripts:
  root: scripts
```

`scripts.root` must be `scripts`, its default, so `maestro.yaml` can omit it.
Every `.star` file in `scripts/` or one of its folders belongs to the tenant's
bundle unless excluded by `scripts.exclude`; other files are ignored. A script's
name is its path from `scripts/`, so `scripts/plans/network/healthcheck.star` is named
`plans/network/healthcheck.star`, and `load()` uses that name. Under
`deployments/`, a `.star` file anywhere else fails the pipeline. A bundle
needs at least one script, and a script name must end in `.star` and contain
exactly one period, so folder names cannot contain periods.

To keep tests alongside tenant scripts without uploading them, add exclusions:

```yaml
schema_version: 1
scripts:
  root: scripts
  exclude:
    - "**/__tests__/**"
    - "**/*_test.star"
```

Patterns use forward slashes and match paths relative to `scripts.root`.
`*` matches within one path component; `**` matches across directories.
A matching directory and its contents are excluded. Patterns must be valid
relative globs without `.` or `..` path components. Unmatched patterns are allowed.

Exclusions apply before scripts are parsed and their shared dependencies are
resolved. A retained script that loads an excluded tenant script fails validation.
Shared scripts referenced by retained scripts are still included.

Preparation retains excluded files, and `scripts test` can still discover and run
them. Validation, planning, deployment, and manifest-based test environments use
the filtered bundle. Exclusions are local source-selection settings and are not
sent to the server, so existing servers need no update. Scripts already stored on
the server remain governed by `uploads_remove_omitted_scripts`: excluding a local
file does not bypass the tenant's policy for retaining omitted scripts.

Add a first script, such as `scripts/greet.star` from
[Your First Script](/remediation-orchestrator/guides/first-scripts-checklist):

```starlark
def greet(name):
    """Greet someone by name.

    Args:
        name: string, the name to greet

    Returns:
        string: the greeting
    """
    return "Hello, " + name + "!"

register_workflow(greet)
```

## 5. Optional: share scripts and templates

### 5.1 Shared scripts

To share scripts between tenants, put them in `_shared/` and name them
`shared_*.star`. Tenant scripts must not use the `shared_` prefix. A bundle includes the shared scripts its `load()`
statements reach, including shared scripts loaded by other shared scripts.
Shared scripts cannot load tenant scripts.

### 5.2 Template registry

Templates let one script run on several tenants with different settings. The pipeline renders them into each tenant's bundle with
`maestroctl scripts prepare`, so a repository without templates needs no
changes.

List the templates and the tenants each renders for in
`template_registry.bzl`. A variant names one rendering, and
`VARIANT_SCRIPT_DIRS` maps it to a tenant's `scripts/` directory:

```starlark
TEMPLATE_NAMES = ["health_check"]

# Variants for templates that TEMPLATE_VARIANTS does not list.
VARIANTS_DEFAULT = ["site-a", "site-b-team-x"]

TEMPLATE_VARIANTS = {}

VARIANT_SCRIPT_DIRS = {
    "site-a": "deployments/site-a/tenants/default/scripts",
    "site-b-team-x": "deployments/site-b/tenants/team-x/scripts",
}
```

### 5.3 Templates and configs

`_templates/health_check.template.star` uses UPPER_CASE settings it does not
define:

```starlark
def health_check():
    """Report this site's failure threshold.

    Returns:
        string: the site and its threshold
    """
    return SITE_NAME + " drains after " + str(FAILURE_THRESHOLD) + " failures"

register_workflow(health_check)
```

`_configs/health_check-default.config.star` holds the defaults:

```starlark
SITE_NAME = "unknown"
FAILURE_THRESHOLD = 3
```

Each variant's config overrides them. `_configs/health_check-site-a.config.star`:

```starlark
SITE_NAME = "site-a"
```

`_configs/health_check-site-b-team-x.config.star`:

```starlark
SITE_NAME = "site-b"
FAILURE_THRESHOLD = 5
```

### 5.4 Rendering

For each variant, `prepare` writes `<scripts directory>/health_check.star` from
the defaults the variant does not override, then the variant's config, then
the template. A variant can replace the whole template with
`_templates/health_check-<variant>.template.star` or its defaults with
`_configs/health_check-<variant>-default.config.star`. Configs may only assign
UPPER_CASE names, and every UPPER_CASE name a script uses must be assigned
before it. Do not commit the generated scripts: a file already at the output
path is an error.

## 6. Add the CI helpers

Copy these files into `ci/` and make them executable.

### 6.1 with-teleport-app.sh

`with-teleport-app.sh` runs a `maestroctl` command through Teleport. It reads
the `teleport_app` of every Teleport deployment in `.prepared-bundles/` with
[yq](https://github.com/mikefarah/yq), picks a free local port for each app,
starts one `tbot` with a tunnel per app, and adds `-tunnel APP=ADDRESS` to the
command for each one. A tunnel that is not ready within 30 seconds is left
out, so `maestroctl` fails only that deployment's tenants and still runs
the rest. Without Teleport deployments it runs the command unchanged.

<Accordion title="ci/with-teleport-app.sh">

```sh
#!/bin/sh
set -eu

if [ "$#" -eq 0 ]; then
  echo "a command is required" >&2
  exit 1
fi

apps=""
for file in .prepared-bundles/deployments/*/deployment.yaml; do
  if [ -f "${file}" ] && [ "$(yq '.authentication' "${file}")" = teleport ]; then
    app="$(yq '.teleport_app' "${file}")"
    case " ${apps} " in
      *" ${app} "*) ;;
      *) apps="${apps} ${app}" ;;
    esac
  fi
done
if [ -z "${apps}" ]; then
  exec "$@"
fi

: "${TBOT_GITLAB_JWT:?TBOT_GITLAB_JWT is required}"
: "${TELEPORT_JOIN_TOKEN:?TELEPORT_JOIN_TOKEN is required}"
: "${TELEPORT_PROXY_SERVER:?TELEPORT_PROXY_SERVER is required}"

tbot="${TBOT_BIN:-./.ci-bin/tbot}"
log_file="${TBOT_LOG_FILE:-tbot.log}"
config_file="$(mktemp)"

cleanup() {
  if [ -n "${tbot_pid:-}" ]; then
    kill "${tbot_pid}" >/dev/null 2>&1 || true
    wait "${tbot_pid}" >/dev/null 2>&1 || true
  fi
  rm -f "${config_file}"
}
trap cleanup EXIT
trap 'exit 1' HUP INT TERM

chmod 0600 "${config_file}"
cat >"${config_file}" <<EOF
version: v2
onboarding:
  token: ${TELEPORT_JOIN_TOKEN}
  join_method: gitlab
storage:
  type: memory
proxy_server: ${TELEPORT_PROXY_SERVER}
credential_ttl: 1h0m0s
renewal_interval: 20m0s
oneshot: false
services:
EOF

tunnels=""
for app in ${apps}; do
  while :; do
    port=$(( $(od -An -N2 -tu2 /dev/urandom) % 16384 + 49152 ))
    case "${tunnels} " in
      *":${port} "*) continue ;;
    esac
    if ! nc -z 127.0.0.1 "${port}" >/dev/null 2>&1; then
      break
    fi
  done
  tunnels="${tunnels} ${app}=127.0.0.1:${port}"
  cat >>"${config_file}" <<EOF
  - type: application-tunnel
    listen: tcp://127.0.0.1:${port}
    app_name: ${app}
EOF
done

"${tbot}" start -c "${config_file}" >"${log_file}" 2>&1 &
tbot_pid=$!

attempt=0
while [ "${attempt}" -lt 30 ] && kill -0 "${tbot_pid}" >/dev/null 2>&1; do
  ready=true
  for tunnel in ${tunnels}; do
    if ! nc -z 127.0.0.1 "${tunnel##*:}" >/dev/null 2>&1; then
      ready=false
    fi
  done
  if "${ready}"; then
    break
  fi
  attempt=$((attempt + 1))
  sleep 1
done

# Pass only the tunnels that are ready. maestroctl fails the tenants of a
# Teleport deployment without one and still runs every other tenant.
missing=false
for tunnel in ${tunnels}; do
  if nc -z 127.0.0.1 "${tunnel##*:}" >/dev/null 2>&1; then
    set -- "$@" -tunnel "${tunnel}"
  else
    echo "the Teleport application tunnel for ${tunnel%%=*} is not ready" >&2
    missing=true
  fi
done
if "${missing}"; then
  tail -n 100 "${log_file}" >&2 || true
fi

"$@"
```

</Accordion>

### 6.2 install-maestroctl.sh

`install-maestroctl.sh` downloads one `maestroctl` release from
`MAESTROCTL_RELEASE_URL` and checks it against a pinned checksum. A release
publishes `maestroctl-linux-amd64`, `maestroctl-darwin-arm64`, and a
`SHA256SUMS` file. Copy the checksums from `SHA256SUMS` into the script, and
update them together with the release URL. If your release location needs
authentication, add the header to the `curl` call.

<Accordion title="ci/install-maestroctl.sh">

```sh
#!/bin/sh
set -eu

: "${MAESTROCTL_RELEASE_URL:?MAESTROCTL_RELEASE_URL is required}"

case "$(uname -s)-$(uname -m)" in
  Linux-x86_64|Linux-amd64)
    asset="maestroctl-linux-amd64"
    expected_sha256="<SHA-256 of maestroctl-linux-amd64 from SHA256SUMS>"
    ;;
  Darwin-arm64)
    asset="maestroctl-darwin-arm64"
    expected_sha256="<SHA-256 of maestroctl-darwin-arm64 from SHA256SUMS>"
    ;;
  *)
    echo "unsupported CI runner platform: $(uname -s)-$(uname -m)" >&2
    exit 1
    ;;
esac

destination=".ci-bin/maestroctl"
mkdir -p "$(dirname "${destination}")"
curl --fail --silent --show-error --location \
  --output "${destination}" \
  "${MAESTROCTL_RELEASE_URL}/${asset}"

if command -v sha256sum >/dev/null 2>&1; then
  actual_sha256="$(sha256sum "${destination}" | cut -d ' ' -f 1)"
else
  actual_sha256="$(shasum --algorithm 256 "${destination}" | cut -d ' ' -f 1)"
fi
if [ "${actual_sha256}" != "${expected_sha256}" ]; then
  echo "maestroctl checksum mismatch" >&2
  exit 1
fi
chmod +x "${destination}"
```

</Accordion>

### 6.3 install-tbot.sh

`install-tbot.sh` downloads the Teleport release archive of your Teleport
version from `TBOT_ARCHIVE_URL`, checks it against a pinned checksum, and
extracts `tbot` from it. Teleport publishes the archive at
`https://cdn.teleport.dev/teleport-v<version>-linux-amd64-bin.tar.gz` and its
checksum at the same URL with `.sha256` appended. If you download it from a
mirror that needs authentication, add the header to the `curl` call.

<Accordion title="ci/install-tbot.sh">

```sh
#!/bin/sh
set -eu

: "${TBOT_ARCHIVE_URL:?TBOT_ARCHIVE_URL is required}"

expected_sha256="<SHA-256 of the archive from its .sha256 file>"

archive="$(mktemp)"
trap 'rm -f "${archive}"' EXIT
curl --fail --silent --show-error --location \
  --output "${archive}" \
  "${TBOT_ARCHIVE_URL}"
printf '%s  %s\n' "${expected_sha256}" "${archive}" | sha256sum -c -

destination=".ci-bin/tbot"
mkdir -p "$(dirname "${destination}")"
tar -xzf "${archive}" -O teleport/tbot >"${destination}"
chmod +x "${destination}"
```

</Accordion>

## 7. Add the pipeline

Add this `.gitlab-ci.yml` at the repository root. Replace the example values in
`variables`, the plan and deploy client IDs, and for Teleport the join tokens
and the `aud` of `TBOT_GITLAB_JWT`.

<Accordion title=".gitlab-ci.yml">

```yaml
stages:
  - discover
  - validate
  - plan
  - deploy

workflow:
  auto_cancel:
    on_new_commit: interruptible
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
      auto_cancel:
        on_new_commit: none
    - when: never

variables:
  GIT_DEPTH: "0"
  DEBIAN_FRONTEND: "noninteractive"
  DEPLOYMENTS: "deployments/*/deployment.yaml"
  MAESTROCTL_RELEASE_URL: "https://downloads.example.com/maestroctl/v0.1.0"
  MAESTRO_TOKEN_URL: "https://login.example.com/oauth2/token"
  # Teleport only.
  TBOT_ARCHIVE_URL: "https://cdn.teleport.dev/teleport-v18.10.6-linux-amd64-bin.tar.gz"
  TELEPORT_PROXY_SERVER: "teleport.example.com:443"

default:
  image: ubuntu:24.04
  interruptible: true
  before_script:
    - apt-get update -qq && apt-get install -qq -y --no-install-recommends ca-certificates curl git
    - ./ci/install-maestroctl.sh

.maestro-job:
  # Teleport only.
  id_tokens:
    TBOT_GITLAB_JWT:
      aud: teleport.example.com
  before_script:
    - apt-get update -qq && apt-get install -qq -y --no-install-recommends ca-certificates curl netcat-openbsd
    - ./ci/install-maestroctl.sh
    - |
      curl --fail --silent --show-error --location --output .ci-bin/yq \
        https://github.com/mikefarah/yq/releases/download/v4.47.2/yq_linux_amd64
      printf '%s\n' '1bb99e1019e23de33c7e6afc23e93dad72aad6cf2cb03c797f068ea79814ddb0  .ci-bin/yq' | sha256sum -c -
      chmod +x .ci-bin/yq
    - export PATH="${CI_PROJECT_DIR}/.ci-bin:${PATH}"
    - |
      for file in .prepared-bundles/deployments/*/deployment.yaml; do
        if [ -f "${file}" ] && [ "$(yq '.authentication' "${file}")" = teleport ]; then
          ./ci/install-tbot.sh
          break
        fi
      done

discover:
  stage: discover
  needs: []
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
      interruptible: false
    - when: on_success
  script:
    - |
      set -eu
      base="${CI_MERGE_REQUEST_DIFF_BASE_SHA:-}"
      if [ -n "${base}" ] && git cat-file -e "${base}^{commit}" 2>/dev/null &&
        git diff --quiet "${base}" HEAD -- ci/ .gitlab-ci.yml; then
        set --
        if git show "${base}:template_registry.bzl" > base-registry 2>/dev/null; then
          set -- -base-registry base-registry
        fi
        git diff --name-only --no-renames -z "${base}" HEAD |
          ./.ci-bin/maestroctl scripts discover -deployments "${DEPLOYMENTS}" -changed-files - "$@" > selected-tenants
      else
        ./.ci-bin/maestroctl scripts discover -deployments "${DEPLOYMENTS}" > selected-tenants
      fi
      cat selected-tenants
      ./.ci-bin/maestroctl scripts prepare -deployments "${DEPLOYMENTS}" $(cat selected-tenants)
  artifacts:
    expire_in: 7 days
    paths:
      - .prepared-bundles/

validate:
  stage: validate
  needs:
    - job: discover
      artifacts: true
  script:
    - ./.ci-bin/maestroctl scripts validate -repository .prepared-bundles -deployments "${DEPLOYMENTS}" -results results
  artifacts:
    when: always
    expire_in: 7 days
    paths:
      - results/

plan:
  extends: .maestro-job
  stage: plan
  needs:
    - job: discover
      artifacts: true
    - validate
  environment:
    name: maestro-script-plan
    action: verify
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
  variables:
    MAESTRO_SCRIPT_MANAGER_CLIENT_ID: "<your plan client ID>"
    # Teleport only.
    TELEPORT_JOIN_TOKEN: "<your plan join token>"
  script:
    - ./ci/with-teleport-app.sh ./.ci-bin/maestroctl scripts plan -repository .prepared-bundles -deployments "${DEPLOYMENTS}" -results results
  artifacts:
    when: always
    expire_in: 7 days
    paths:
      - results/
      - tbot.log

deploy:
  extends: .maestro-job
  stage: deploy
  needs:
    - job: discover
      artifacts: true
    - validate
  environment:
    name: maestro-script-deploy
    action: verify
  interruptible: false
  resource_group: maestro-script-bundles
  rules:
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
  variables:
    MAESTRO_SCRIPT_MANAGER_CLIENT_ID: "<your deploy client ID>"
    # Teleport only.
    TELEPORT_JOIN_TOKEN: "<your deploy join token>"
  script:
    - ./ci/with-teleport-app.sh ./.ci-bin/maestroctl scripts deploy -repository .prepared-bundles -deployments "${DEPLOYMENTS}" -results results
  artifacts:
    when: always
    expire_in: 7 days
    paths:
      - results/
      - tbot.log
```

</Accordion>

## 8. Check it end to end

1. Open a merge request that adds a tenant. The `plan` job lists, for each
   selected tenant, the scripts a deploy would create, update, or remove, and
   keeps each tenant's `plan.json` in its `results/` artifact. A deploy keeps
   live scripts that the bundle leaves out, so a tenant's first deploy adopts
   the scripts that were uploaded another way. If the tenant config sets
   `uploads_remove_omitted_scripts = true`, a deploy removes those scripts
   instead. Review a tenant's first plan before merging.
2. Merge the merge request. The `deploy` job on the default branch reconciles
   every tenant and keeps each tenant's `deploy.json` in its `results/`
   artifact.
   Every default-branch pipeline prepares every tenant so a later deployment
   also retries changes missed by an earlier failed or partially successful
   deployment. Merge request pipelines select only tenants affected by their diff.
3. The first default-branch pipeline creates the `maestro-script-bundles`
   resource group. Only one deploy runs at a time. Set the group's process mode
   to `oldest_first` so deploys also run in commit order:

   ```bash
   glab api --method PUT projects/:id/resource_groups/maestro-script-bundles -f process_mode=oldest_first
   ```

## 9. Reference

### 9.1 Commands

The pipeline runs five `maestroctl scripts` commands. Each takes the repository
with `-repository` and the deployments with `-deployments`, a glob of `deployment.yaml` files relative to the repository
such as `deployments/*/deployment.yaml`. Each match must be
`deployments/<deployment>/deployment.yaml`, and its tenants are the
`tenants/<tenant-id>/maestro.yaml` files beside it.

- `discover` prints the manifests of the tenants to act on, one per line.
  Without `-changed-files` it prints every tenant. With `-changed-files FILE`,
  or `-` for standard input, it reads the NUL-separated paths that
  `git diff --name-only -z` writes:
  - A change under a tenant directory selects that tenant.
  - A change to `deployment.yaml` selects every tenant in that deployment.
  - A change to `maestro-repository.yaml` selects every tenant.
  - A change under `_shared/` selects the tenants whose bundles load that
    script, and the tenants whose bundles fail to load.
  - A change under `_templates/` or `_configs/` selects the tenants whose
    generated scripts read that file, or would read it if it existed.
  - A change to `template_registry.bzl` selects the tenants whose generated
    scripts it adds, removes, or moves. This needs `-base-registry FILE`, the
    registry before the changes. Without it every tenant is selected.
  - Any other change selects nothing.

  A glob that matches no `deployment.yaml` is an error. Each `-skip site-b`
  or `-skip site-a/default` leaves that deployment or tenant out of the output,
  whatever selected it, and notes it on standard error. An entry that names
  no deployment or tenant the glob finds is an error.
- `prepare` writes the named tenants to `.prepared-bundles/` with their shared
  and generated scripts, their `deployment.yaml`, and
  `maestro-repository.yaml`, so the output is a repository of its own.
- `validate`, `plan`, and `deploy` act on every tenant the glob matches, in
  parallel. Run them with `-repository .prepared-bundles`. A failing tenant
  lets the others finish, and the command then fails. With `-results DIR`,
  each tenant's `validation.json`, `plan.json`, or `deploy.json` is written to
  `DIR/<deployment>/<tenant-id>/`. A glob that matches nothing leaves nothing
  to do and succeeds.
- `deploy` plans each tenant and deploys the planned bundle. A tenant's first
  deploy adopts the scripts that were uploaded another way, so review the plan
  in the merge request.
- `plan` and `deploy` take `-tunnel APP=ADDRESS` for each Teleport
  application tunnel.

### 9.2 Jobs

- `discover` pipes the files changed since the merge request base to `maestroctl scripts discover`,
  with the base commit's `template_registry.bzl` when it has one.
  Default-branch pipelines select every tenant. A merge request also selects
  every tenant when `ci/` or `.gitlab-ci.yml` changed, or its base is not usable.
  `maestroctl scripts prepare` then stages the
  selected tenants in `.prepared-bundles/` for the later jobs.
- `validate` checks each prepared bundle offline.
- `plan` runs in merge requests and shows what a deploy would change on each
  server.
- `deploy` runs on the default branch and reconciles every tenant, one
  deploy at a time.

The server validates each bundle and applies it as a unit, and deploying a
bundle that is already live changes nothing.

### 9.3 Add a deployment or tenant

For a new tenant, create `deployments/<deployment>/tenants/<tenant-id>/` with
its `maestro.yaml` and `scripts/`. For a new deployment, also add
`deployments/<deployment>/deployment.yaml`. The pipeline does not change.