Baseline storage
A bucket of your own keeps the saved baseline where your organisation already keeps build data, shared by every branch and every CI, out of reach of whoever can open a pull request.
A baseline store is a bucket or a folder of your own that keeps the saved baseline. It needs the secret key.
Name a store #
Name the store in one of these places:
| CI | Where to name it |
|---|---|
| GitHub Actions | The baseline-store input |
| Jenkins | The baselineStore parameter |
| GitLab CI, Azure Pipelines and any other CI | NK_CI_BASELINE_STORE |
| Every CI at once | The app file, as below |
In the app file:
x-nk:
baseline_store: s3://ci-cache/myappThe input or variable wins over the app file. The URL names a place and holds no secret.
Which URL to use #
| Store | URL | Also set |
|---|---|---|
| AWS S3 | s3:// |
baseline-store-region |
| Cloudflare R2 | s3:// |
baseline-store-endpoint: https://, region auto |
| MinIO, Backblaze B2 and other S3-compatible stores | s3:// |
baseline-store-endpoint |
| Google Cloud Storage | gs:// |
Nothing more. |
| Azure Blob Storage | az:// |
RCLONE_AZUREBLOB_ACCOUNT in the job's environment |
| A folder | file:/// |
For a network share mounted on every runner. |
How it moves the baseline #
With a store set, the Action skips the Actions cache. The restore and save steps of nk-ci.sh move the baseline instead.
Restore #
Restore takes the newest object under <prefix>/nk-baseline/<key>/. If there is none yet, or one it cannot read, the compare runs in full.
Save #
Save runs only when Nikasa built, extended, checked or marked the baseline (what each means). It uploads the baseline as one new object.
Nothing is ever overwritten. Two jobs saving at once both land, and the next restore takes the newer.
Encryption #
Each object is encrypted on the runner before upload, with rclone's crypt. Its passwords are worked out from the secret key, so there is no new secret. A leaked bucket is unreadable without the CI secret.
Object names stay readable, because restore picks the newest by name.
When the store fails #
A restore or save that fails prints an nk-ci: warning: line. It never changes the job's exit status.
When the baseline did not reach the store:
- the script's last line is
nk-ci: the baseline was not saved; the warning above says why; - the Jenkins step adds that to the build description;
- the GitHub Action opens its job summary with it.
rclone #
The script moves objects with rclone. It is:
- downloaded once from rclone's GitHub release;
- unpacked with unzip, which the runner needs for that, and which the warning names when it is missing;
- run only when it matches a checksum pinned in the script.
NK_CI_RCLONE names a copy already on the runner instead.
Sign in to the store #
rclone signs in from the job's environment, the way that cloud's own CLI does.
Set the region explicitly on S3, and never rclone's role_arn, as the login step has already assumed the role.
On GitHub Actions #
| Store | How to sign in |
|---|---|
| AWS S3 | aws-actions/ exports AWS_*. |
| Google Cloud Storage | google-github-actions/ sets GOOGLE_APPLICATION_CREDENTIALS. |
| Azure Blob | azure/, then RCLONE_AZUREBLOB_USE_AZ=true. |
| Cloudflare R2 | There is no federation. Use a bucket-scoped R2 API token in secrets, as AWS_ACCESS_KEY_ID (the token id) and AWS_SECRET_ACCESS_KEY (the SHA-256 of the token). This works the same on every CI. |
On other CIs #
Use your CI's own route to the cloud:
| CI | How to sign in |
|---|---|
| GitLab CI | id_tokens: with AWS_WEB_IDENTITY_TOKEN_FILE and AWS_ROLE_ARN for S3, workload identity federation for Google, federated credentials for Azure. |
| Jenkins | The OpenID Connect Provider plugin, with a web identity file, for S3. |
| Azure Pipelines | AWS Toolkit with OIDC for S3, a workload identity federation service connection for Azure. |
| CircleCI | CIRCLE_OIDC_TOKEN_V2 for S3. |
| Bitbucket and Buildkite | oidc: true and BITBUCKET_STEP_OIDC_TOKEN, or buildkite-agent oidc request-token, for S3. |
Set up the bucket #
Use a dedicated private bucket, or a prefix per repository in one. Block public access, and allow TLS only.
Grant the CI's role list, get and put on the prefix, and no delete. On S3, a bucket policy can require If-None-Match: * on every write.
Remove old baselines #
Removing old baselines is the bucket's job. Set a lifecycle rule that does two things:
- deletes objects under
<prefix>/nk-baseline/after 30 days, which is well past the default check age of 7 days (see Saved baselines); - drops unfinished uploads.
Your cloud's docs show how.
Next steps #
- Saved baselines: how a baseline is kept and when it is used again.
- GitHub Actions: the Action's inputs, including the store's.
- Security and your data: what a saved baseline holds and who can read it.
Written for nk 0.3.14. Something wrong or unclear? Write to hello@nikasa.dev.