How CI works
One added step in the pipeline you already have, after a one-time setup. Nikasa compares two images on your runner, and your CI job uploads the report.
On this page
- Your app runs for real
- Every CI does the same steps
- The first setup
- What a runner needs
- Your tests drive the compare
- The app's config
- The release token
- Nikasa's images in CI
- Jobs that share a Docker
- Report, or stop the merge
- Which images to compare
- Which download
- Runners where Nikasa is itself in a container
- Next steps
Nikasa runs in CI as one added step in the pipeline you already have. It compares two images on your runner, and your CI job uploads the report. This page covers what every CI shares. Each CI's own page has the file to copy.
The words sandbox, compare, run and driver are defined at the top of Get started.
Your app runs for real #
To keep it safe:
- Put test keys in the sandbox's environment.
- Either list the hosts you allow under
x-nk: outside, or add--offline.
The Outside services page has the detail.
Every CI does the same steps #
- Get
nkand check it. - Run
nk setup. - Optionally, record your own tests on the old build (Your tests drive the compare).
- Compare two images.
- Upload the four reports to your CI's artifacts:
report.txt,report.json,report.mdandinformation.jsonl.
One script, nk-ci.sh, does the first four steps on any Linux runner. Each CI adds its own way of uploading the reports.
Pick your CI #
| CI | How it runs | Page |
|---|---|---|
| GitHub Actions | One Action step: report on the pull request, in the job summary and as an artifact | GitHub Actions |
| GitLab CI | A plain job in ., on a runner with Docker |
GitLab CI |
| Jenkins | A shared library with one step, nkCompare |
Jenkins |
| Azure Pipelines | A pipeline with Azure's own cache, artifact and run summary | Azure Pipelines |
| CircleCI, Bitbucket Pipelines, Buildkite or your own | nk-ci., set up with variables |
Any other CI |
The first setup #
- Give the job requests to send. Either commit your requests in
nk/specs, or say where your tests are so the job records them. Every CI can also run with no requests at first. - Commit
nk/app.yaml. - If
nk initlisted settings to provide, give the job those names: see The app's config. - Add the step for your CI. Where an example says
<nikasa-repo>, put the repository your invite names. - Later, to speed compares up, add a secret key and a saved baseline. A first run does not need them.
Spelling the release #
A release is spelled two ways:
| Where | Spelling | Example |
|---|---|---|
The tag, in uses: and in @Library |
With a v |
v0.3.14 |
The version, in version:, NK_CI_VERSION and the Jenkins version parameter |
Without a v |
0.3.14 |
The v belongs to the tag only.
What a runner needs #
- A 64-bit Intel or AMD Linux machine.
- A Docker daemon Nikasa can drive, with Docker's compose plugin.
- Permission for Docker to start the capture container with the
NET_ADMINandNET_RAWcapabilities, to capture a bridge network. - Paths that the daemon sees the same way Nikasa does.
- At least 5 GB free, for a run's captures and images.
A GitHub-hosted runner has all of these, and so does any Linux VM runner with Docker.
Two kinds of runner do not work:
- Windows agents, as
nk-ci.shand the downloads are Linux only. - A pod in a Kubernetes cluster, which usually has neither a Docker daemon nor those capabilities. On pod-based CI, send the Nikasa job to a runner with its own Docker.
What the job's containers can do #
Three of the containers the job starts hold more than default rights:
| Container | Rights |
|---|---|
| The capture container | NET_ADMIN, NET_RAW and the host's network |
| The relay, the sandbox's gateway | NET_ADMIN inside its own network namespace only |
| The eBPF key reader | Privileged, with the host's PID namespace and /. It starts only when Docker allows privileged containers, and --no-ebpf turns it off |
Your app and its services run with the rights your compose file gives them. What Nikasa runs lists every container, so keep the job to a runner you trust with these.
Your tests drive the compare #
A compare with no requests sees only each build's startup and idle time. Your own tests can drive it instead:
- The job records your tests on the old build.
- The compare sends what they sent to both builds again.
- The reports open by saying how the tests went.
Say once where your tests are, under x-nk: tests in the app file:
x-nk:
tests:
driver: playwright # or cypress, newman, bruno
folder: e2e # where the suite is, from where you run nk record
env:
E2E_PASSWORD: ${E2E_PASSWORD} # taken from the job's environmentThen name the checkout to run them from in the CI's record setting. A checkout of the base branch is the folder to name, as those tests were written for the old build. Each CI page shows the line to add. Secrets your tests read come from the job's environment.
Give your tests what they need lists every key under x-nk: tests.
When nothing is recorded #
The job does not fail when nothing is recorded. That covers:
- no
x-nk: testsin the app file; - a folder that is not there;
- a tool that sent nothing;
- a failure, or the time limit.
The compare goes on as it would have, with the specs, with nk/packs/main, or with no requests. A pack is a saved recording, as Words in a report says. The reports open by saying that nothing was recorded, and why.
The job's log has what nk record said and the last lines of the test tool's log. No report repeats them, as a CI masks only the log.
Time limit #
The limit is record-minutes in the Action and Jenkins, and NK_CI_RECORD_MINUTES in the script. It is 30 by default. It stops nk record, then kills it after 30 seconds. The next run on its sandbox network removes whatever it left running.
The recording stays on the runner #
Nothing hands the recording on, and no step caches it. A job makes a new one each time. On a runner that lives on after the job, empty the job's work folder when it ends.
Saved baselines, time and room #
- No saved baseline. A new recording never matches a saved one, so with a recording the compare makes its old runs. A compare with no recording keeps its saved baseline.
- Time. Give the job 90 minutes, as the job
nk init --ciwrites does. The recording comes on top of the image builds and the compare, and a job that reaches its own limit posts no report. - Room. The test driver's image adds about 3.5 GB for Playwright.
The app's config #
Nikasa reads the app's settings the way Compose does:
- First the env file that
nk/app.yamlrecords asx-nk: env_file. That is the.envyour compose file reads, written as a path fromnk/, such as../.env, so a run from any folder finds it. - Then the job's own environment, which wins.
So a job gives the app its settings the way it gives any script a secret, or it writes the file. Give it exactly the names nk init lists as to provide on its config: line. Your own test job gets its settings the same way.
Two routes for a whole file #
| Route | How it works | Where it is used |
|---|---|---|
| Write the file where Nikasa expects it | The secret NK_ENV_FILE holds the file's text, and a step writes it to . |
GitHub |
Hand Nikasa the path with --env-file |
A variable named NK_ENV_FILE holds the path of a file the CI makes |
GitLab, Jenkins and other CIs |
The secret's name is yours. These pages use NK_ENV_FILE for both, so it means the text on GitHub and the path everywhere else. Env file paths says where a path starts.
Each CI's form #
| CI | One setting | A whole file |
|---|---|---|
| GitHub Actions | env: on the Nikasa step: APP_SECRET: ${{ secrets.APP_SECRET }} |
Keep the text in one secret. Write it with printf '%s\n' "$NK_ENV_FILE" > . from an env: mapping, never with ${{ }} inside run: |
| GitLab CI | Project variables reach the job as variables already | A File variable holds the path. nk compare ... --env-file "$NK_ENV_FILE" names it in place of the recorded file |
| Jenkins | environment { APP_SECRET = credentials('app-secret') } |
A secret file: withCredentials([file(credentialsId: 'nk-env', variable: 'NK_ENV_FILE')]) around nkCompare, whose args and recordArgs take --env-file ${env.NK_ENV_FILE} |
| Azure Pipelines | env: APP_SECRET: $(APP_SECRET) on the step |
A secure file, downloaded with DownloadSecureFile@1 and passed as --env-file in NK_CI_ARGS and NK_CI_RECORD_ARGS. See Give a whole file |
| Any other CI | export APP_SECRET=... before nk-ci. |
--env-file <path> in NK_CI_ARGS and NK_CI_RECORD_ARGS, the words it adds to the compare and to the recording |
Three more details:
-
GitLab. The
nk recordline takes--env-filethe same way. The job that runsnk-ci.shtakes it throughNK_CI_ARGSandNK_CI_RECORD_ARGS. Mark values masked: a masked value must be one line of 8 characters or more. -
Azure. The
env:line is needed because Azure does not map secret variables into a script's environment on its own. -
GitHub's
nk init --ci. It writes the job with the settings in it, by one route per draft:Situation What it writes What it prints Your app file reads settings It copies your test job's env:block as it is, and addsNAME: ${{ secrets.NAME }}for each setting that block does not setsecret: add APP_SECRET, SITE_ROOT to the repository's Actions secretsA service reads, as its env_file:, a file git does not trackIt writes that file from one secret instead, and adds no secret lines secret: NK_ENV_FILE holds the text of .env for the job, APP_SECRET, SITE_ROOT included
The release token #
Jobs on Jenkins, Azure Pipelines and other CIs download from the release, so they need a GitHub token that can read it. These pages call it NK_RELEASE_TOKEN, a name you choose, and you keep it as a CI secret.
| Question | Answer |
|---|---|
| What do I make? | A token from a GitHub account that can read the releases of <nikasa-repo>. Your invite says which kind |
| What is it for? | Those downloads and nothing else. nk-ci. passes it to curl on standard input, and it leaves the script's environment before nk runs |
On GitHub Actions, the Action's token input does this. See The step.
Nikasa's images in CI #
nk setup tries to pull Nikasa's two images from ghcr.io: the capture image and the eBPF key reader. When a pull is refused, it builds that image on the runner from a Dockerfile nk carries.
So a job needs no Docker login to ghcr.io for Nikasa, and the release token is the only token it needs for Nikasa. A job that does log Docker in, with a token that can read those images, pulls them and does not build them.
Jobs that share a Docker #
Runs on one Docker get a sandbox network each, from any home folder, machine user or CI job. Up to 16 can run at once.
A run holds its network with a small container, nk-slot-<n>. It has no network and no capabilities, and it goes when the run ends, however it ends. So a job that starts while another runs takes the next free network, and never removes the first job's containers.
What a killed run left is removed by the next run on that network, or by nk clear --slot <n>. Add --slot <n> to a compare to pick the network.
Report, or stop the merge #
By default the job passes with the report. A green job says Nikasa could compare, and what changed is in the report. A new build is expected to change things. If Nikasa could not compare, the job fails. The reports are uploaded either way.
To stop a merge on a change, add --fail-on-change. With it the job also fails when the report lists a change in every new run. Use it where a change must stop something, such as a merge queue, or an upgrade check of a dependency under an unchanged app.
| Exit status | Meaning | The job |
|---|---|---|
| 0 | Nikasa compared | Passes |
| 1 | Nikasa compared, and a change showed in every new run | Fails |
| 2 | Nikasa could not compare | Fails |
A change counts only when the new runs show it every time. Nikasa starts each build several times and adds runs to confirm a difference, as the How many runs paragraph of Commands says. Exit status has the details.
Which images to compare #
| When | What to compare |
|---|---|
| A pull request against its base branch | Build both, or pull the base's image by its tag |
| The merge queue | The queued change against the branch it merges into |
| Every night | The image you run in production against your default branch, both in the sandbox. This shows drift that no single pull request showed. It does not watch live traffic |
Which download #
A release has two Linux x86_64 downloads of nk, and no download for any other system.
| Download | Built for | Notes |
|---|---|---|
nk-x86_64-unknown-linux-gnu |
glibc 2.34 or newer: Ubuntu 22.04, Debian 12 and later, and every GitHub-hosted Ubuntu runner | The default. It is built on Ubuntu 22.04 |
nk-x86_64-unknown-linux-musl |
Any Linux x86_64, including older glibc, Alpine and the docker:28-cli image |
Static. It is slower on large compares, so use the default wherever it runs |
On an older glibc, the default stops with lines such as version `GLIBC_2.34' not found.
nk-ci.sh, and so the GitHub Action, asks the runner and picks one. Its install step prints which it took and why.
Runners where Nikasa is itself in a container #
GitLab's Docker executor, Jenkins agents in containers and similar runners start Nikasa inside a container. That container drives the host's Docker through its socket.
It works under two conditions.
Same paths on the host #
Every folder Nikasa hands to Docker must have the same path on the host. The daemon resolves bind mounts on the host and not in Nikasa's container. That covers:
- the output folder;
- the tools folder,
NK_TOOLS; $HOME/.config/nk/build, wherenk setupstages the sources of its tools;- the specs folder;
- any file the app file mounts.
To do this:
- Mount one host folder into the job container at the same path.
- Keep the checkout and the output folder under it.
- Set
NK_TOOLSthere too. - Point
HOMEat a folder under it.
Without that, nk setup fails with gcc: error: /src/nk-keys.c: No such file or directory.
Not mounted noexec #
That folder must not be mounted noexec. The libraries Nikasa loads into the app to log TLS keys come from the tools folder.
Next steps #
- GitHub Actions: the Action step, and three workflows to copy.
- Any other CI:
nk-ci.shand its variables. - Saved baselines: speed up later compares.
- Outside services: decide which hosts your app may reach.
Written for nk 0.3.14. Something wrong or unclear? Write to hello@nikasa.dev.