Nikasa, home Request an invite
DocsGet started

Get started

Install nk, watch it find three changes in a sample app, and get your own app ready for its first compare.

On this page

This guide takes you from installing nk to your own app running in Nikasa's sandbox, ready for its first compare.

You will:

  1. Install nk and check that it runs.
  2. Run the sample app and read its report.
  3. Set up Nikasa on your machine.
  4. Let nk init draft the file that starts your app.
  5. Start your app once with nk try.

Words to know #

Nikasa starts two builds of your app, an old one and a new one. Then it reports what the new one does differently.

These four words come up on every page:

Word What it means
Sandbox The private Docker Compose project that Nikasa starts your app in. It holds your app, its databases and its other services, on a network of its own.
Compare Nikasa starts your old build (the image you run today) and your new build (the image with your change) in the sandbox. It sends both the same requests and reports what differs.
Run One start of one build. A compare makes several runs of each.
Driver The container that sends the requests. By default it sends your Hurl files.

Words in a report defines the rest.

Before you begin #

You need:

  • A 64-bit Intel or AMD Linux machine with Docker and Compose v2. A Linux VM or a CI runner works too.
  • git
  • The GitHub CLI (gh), or any other way to download a release file.
  • About 10 GB of free disk space.
  • An invite to Nikasa, and the GitHub token it names.

On a Mac, a Windows PC or an Arm machine, you need a Linux machine or VM to run nk on. Where it runs explains the options.

Disk space #

The images take about 10 GB the first time. After that, each run needs at least 5 GB free.

When space runs short, a compare deletes the captures of the runs it has already made. It may also stop early. See When a compare stops early.

Your invite and token #

Nikasa is shared by invite. Your invite gives you:

  • the name of the repository that holds Nikasa's releases, as an owner/name pair. These pages write it as <nikasa-repo>, so put that name wherever you see it.
  • which GitHub token to use.

The token reads the repository's releases. It also reads Nikasa's images for nk demo, the sample app below. Set up Nikasa and every step after it need no login to read those images.

No invite? Request one on the home page, or write to hello@nikasa.dev and say which CI you use. Getting access has the details.

Install nk #

nk is a single Linux file. You download it from the release with a file of checksums, check it, and put it on your path.

Any way of downloading works. These steps use GitHub's gh command.

  1. Log gh in with the token from your invite:

    shell
    gh auth login
  2. Download the Linux file and the checksums. Replace <nikasa-repo> with the repository from your invite:

    shell
    gh release download v0.3.14 --repo <nikasa-repo> \
      --pattern nk-x86_64-unknown-linux-gnu --pattern SHA256SUMS
  3. Check the file against the checksums:

    shell
    sha256sum -c --ignore-missing SHA256SUMS

    This shows that the file is whole and is the one the release holds. It does not show who published the release, so download only from the repository your invite names.

  4. Make the file executable and move it onto your path:

    shell
    chmod +x nk-x86_64-unknown-linux-gnu
    sudo mv nk-x86_64-unknown-linux-gnu /usr/local/bin/nk
  5. Check that it runs:

    shell
    nk --version

    It prints the version, 0.3.14, and the commit it was built from.

What downloading involves lists every download Nikasa makes.

Try the sample app #

nk demo compares two versions of a small sample shop app and prints the report. There is nothing to write or configure, and it does not need nk setup.

The sample's images are on ghcr.io, so Docker needs a token that can read them.

  1. Log Docker in to ghcr.io with your GitHub username and the token from your invite. You do this once on each machine.

    shell
    docker login ghcr.io
  2. Run the demo:

    shell
    nk demo

    It pulls the sample app in two versions, and Nikasa's capture image. Then it runs the old build and the new build, and prints the report. This takes a few minutes.

If a pull is refused, see A pull is refused.

Read the sample report #

The new build makes three changes, and no test was written for any of them:

  • It renames a field in a response.
  • It reads each order's lines in a query of its own.
  • It calls a fraud check service.

Here is the part of the report that shows them. The ... lines mark what is cut from this page:

output
13 changes in responses and requests (8 in responses, 5 in calls during requests), listed in brief as 7 lines
...
SHAPE  /response/body  1 field added: total_cents 4800; 1 removed: total
...
in short:
  now calls, in 0000 POST /api/orders: app -> fraud-check:8000
  now calls, in 0001 POST /api/orders: app -> fraud-check:8000
  calls per request, 0003 GET /api/orders: 5 calls to postgres:5432, was 1 ("SELECT customer FROM orders WHERE id = $1" ran 2 times, and 1 more)

Each change has its own line:

Change in the new build Where the report shows it
The renamed field The SHAPE line: total is gone and total_cents is new.
The fraud check The now calls lines, one for each order placed.
The query per order The calls per request line: the request that lists orders now makes 5 calls to Postgres, where it made 1.

A few more things to read in that output:

  • The parenthesis at the end names the query that ran most often, 2 times. and 1 more means that one more query repeated.
  • Numbers such as 0003 count the sample's requests in the order they were sent, starting at 0000. So 0003 is the fourth request. The report calls each request a scenario, as Words in a report explains.
  • listed in brief as 7 lines counts the SHAPE, NEW and GONE lines in the full report. This cut shows one of them, and the in short: block sums up the others.

How Nikasa counts changes #

The report counts 13 changes for these three causes. That is because Nikasa counts each place and each value that moved, so one cause can make several changes.

Nikasa counts a change only when two things hold. All the old runs agreed at that point, and the new build does something different in every new run.

Some lines only tell you something, such as which outside hosts were reached. They carry the words told, never counted, and they add nothing to the count.

The sample report shows the whole report and how the count adds up. For results on real upgrades of publicly available apps, see the home page.

Where the demo puts its files #

Folder What it holds
nk-demo/sample The sample's compose file and requests. It is a working example of what Nikasa needs from your app.
nk-demo/compare The reports.

Set up Nikasa #

nk setup prepares the tools Nikasa uses to read your app's traffic. Run it once on each machine:

shell
nk setup

It does two things:

  • It builds the small tools that read TLS, the encryption on your app's connections. It builds them inside Docker, so you need nothing installed besides Docker.
  • It gets the images that capture traffic. It pulls each one from ghcr.io. When a pull is refused, it builds that image on your machine from a Dockerfile that nk carries, so it needs no login.

The first time, it downloads several large images. The largest is the .NET SDK. It builds the startup hook that makes a .NET app write its TLS keys to a log. The SDK runs only inside Docker, and only .NET apps load what it builds.

To see what is there, run:

shell
nk setup --check

Before you start your own app #

You start your app with nk try, below. How you run it decides what the app can reach:

How you run it What the app can reach
nk try --offline <image> Nothing outside the sandbox. No outside host can be reached or even resolved. Use this for the first start.
nk try <image> The outside hosts its configuration names. nk try lists every one it reached. Use this once your env file holds test keys.

To allow only certain hosts, or to learn what a compare does with these calls, see Outside services.

Draft your app file #

Nikasa starts your app from a compose file, nk/app.yaml, called the app file. You do not have to write it: nk init drafts it from what your repository already has.

Run it in your repository:

shell
cd your-repository
nk init

It prints a short summary:

output
app: `myapp`, built from the repository
port: 8000, from the compose file
beside it: postgres (PostgreSQL)
nk/app.yaml drafted from docker-compose.yml
notes: nk/init.txt, all 25 lines of what nk init inferred, guessed and found missing
next: docker build -t myapp:old . && nk try myapp:old

nk init reads your compose files and CI workflows, and writes nk/app.yaml. It runs no container. It never edits your own files, and writes only under nk/.

Each line tells you one thing:

Line What it tells you
app: Which service is your app, and why.
port: The port your app listens on, and where that came from.
beside it: The services your app needs, such as a database.
nk/app.yaml drafted from The compose file the draft came from.
notes: How many lines the full notes in nk/init.txt hold. When more gaps were found than the few printed, it adds a count such as (3 more gaps there).
next: The command to run next. For the first start, add --offline to it, as Check that it starts shows.

The app and its port are what the draft most needs to get right, so check those two lines first.

When nk init is not sure #

When nk init cannot tell, it asks you. Each question is a numbered list, with the likeliest answer first. It may ask:

  • which file, when more than one compose file could be the one;
  • which service, when more than one could be your app;
  • which port, only when the places that name a port name different ones, such as the compose file's ports and the Dockerfile's EXPOSE.

Here is the question about the service, as it looks on a terminal:

output
more than one service could be your app:
  1) alpha  built here; health check on 3011
  2) beta   built here; health check on 3022
which is your app? [1]

Your repository may have a Dockerfile at its root, while the compose file runs a published image that could be the app too. Then the choices are the build of that Dockerfile first, then the image.

To answer ahead of time, give a flag:

Flag What it does
--from <file> Drafts from this compose file.
--service <name> Makes this service the app.
--port <n> Sets the port the app listens on.
--yes Takes the likeliest answer to every question.

With no terminal, or with CI set, nk init asks nothing. It exits 2 and prints the command for each choice. When nk init asks a question has the details.

When there is no compose file #

nk init tells you what it did find. To draft the app alone from an image, give the image and its port:

shell
nk init --image <ref> --port <n>

Give your app its settings #

Your app's settings come from the env file you already have. nk init finds the env file your compose file reads, the .env beside it, and records it in nk/app.yaml:

yaml
x-nk:
  env_file: ../.env

x-nk: is the block that holds Nikasa's own settings. Docker Compose ignores any top-level key that starts with x-.

The path starts from the nk/ folder, the same way Compose reads a service's env_file:.

Nikasa never copies your env file, and it makes no value up. None of the file's settings go into nk/app.yaml. The only exceptions are a health check's port and a mount's folder, when your compose file takes them from the env file.

A service may name its own file under env_file:. That file stays with the service. Nikasa reads it for the config: line below, but Compose fills no variable from it.

Create the env file, if you have none #

Many repositories ship a template, such as .env.example, next to the real .env. Nikasa calls it the example file.

Say your compose file reads APP_SECRET and SITE_ROOT, and your repository has this .env.example, but no .env:

dotenv
# 32 random characters
APP_SECRET=
SITE_ROOT=

nk init names the missing settings on a config: line. Its next: line starts with the step that creates your env file:

output
app: `myapp`, built from the repository
port: 8000, from the compose file
beside it: postgres (PostgreSQL)
config: .env does not exist yet; 2 to provide (APP_SECRET, SITE_ROOT); nk/init.txt lists each with its comment
nk/app.yaml drafted from docker-compose.yml
notes: nk/init.txt, all 31 lines of what nk init inferred, guessed and found missing
next: cp .env.example .env and fill APP_SECRET, SITE_ROOT, then docker build -t myapp:old . && nk try myapp:old

Do that step once, as you would before you run the app with docker compose up:

  1. Copy the example file:

    shell
    cp .env.example .env
  2. Fill in APP_SECRET and SITE_ROOT in .env.

With no example file, the step reads put APP_SECRET, SITE_ROOT in .env instead.

The file is yours. Nikasa reads it where it is, and keeps no copy in nk/.

What the config line can say #

Your repository What nk init prints
Has the env file, and nothing is missing config: .env read, 7 settings, nothing missing. The next: line is the build command alone.
Has an env file that leaves keys empty, as the example file does config: docker/.env read, 86 settings; nothing to provide; 41 left empty as in the example; nk/init.txt lists each with its comment. Those keys are one count, not names to provide.
Needs no settings No config: line.

Missing settings on the app file page explains every part of the line.

Use an env file somewhere else #

If your env file is not beside the compose file, name it:

shell
nk init --env-file docker/.env

nk init records it as ../docker/.env. Give the flag again for a second file. Later files win.

nk try, nk run, nk record and nk compare take the same flag. There it replaces the recorded files for that command only, and its path starts from the folder you run nk in. Env file paths lists where each path starts.

Variables in your shell win over every file, as in Compose.

Check that it starts #

Now start your app once in the sandbox, with the code you run today.

  1. Check out the code you run today, usually your main branch:

    shell
    git checkout main
  2. Build it as an image:

    shell
    docker build -t myapp:old .
  3. Start it once, with --offline to keep it inside the sandbox:

    shell
    nk try --offline myapp:old
  4. If the app cannot start without an outside service, put test keys in your env file and run it again without --offline:

    shell
    nk try myapp:old

An image from a registry works the same as one you built.

Read what nk try prints #

Without --offline, nk try also lists the outside hosts your app reached. Here is a healthy start:

output
using nk/app.yaml
healthy: the app answered its health check
driver made 1 request: 200 x1
outside the sandbox in this run (nothing blocked: nk/app.yaml has no x-nk: outside; told, never counted):
  telemetry.example.com:443 (app): reached live, HTTP Nikasa read
to allow only these hosts and block the rest, add under x-nk: in nk/app.yaml:  outside: [telemetry.example.com]
nothing to change in nk/app.yaml
next: nk compare myapp:old <new-image>
Line What it means
using nk/app.yaml The app file it started. When the draft records an env file, this line names it too.
healthy: The app answered its health check.
driver made 1 request: 200 x1 The driver sent one request and got one answer, with status 200.
outside the sandbox in this run The app really called telemetry.example.com, and Nikasa could read that call. told, never counted means Nikasa tells you this but does not count it as a change, as in the sample.
to allow only these hosts What to add to nk/app.yaml to allow only these hosts and block the rest.
nothing to change in nk/app.yaml The draft needs no edit.
next: The compare to run next.

Which env file it read #

The first line says which env file nk try read. In the example above, the app needs no settings, so the draft records no env file, and the line is plain using nk/app.yaml.

When the draft records an env file, the first line looks like one of these:

First line What it means
using nk/app.yaml with .env (7 settings) It read .env, which holds 7 settings.
using nk/app.yaml, no env file (.env from x-nk: env_file does not exist) The draft records .env, but the file is not there.
using nk/app.yaml with docker/.env (2 settings) and app.env (1 setting) It also read app.env, a file that a service reads whole under env_file:. Such a file comes last.

If it does not start #

nk try says why in at most 10 lines. Its last line names the edit to make.

Say the app listens on one port, and it is not the port in the draft. If you have not edited nk/app.yaml, nk try corrects the port for you and keeps the old file as nk/app.yaml.before. nk/app.yaml is Nikasa's file, not yours.

If the app stops on a setting that nothing gives it, nk try names the setting with your file, so you know where to add it:

output
APP_SECRET is not set: .env (x-nk: env_file) has no line for it; add APP_SECRET=... to .env, or set it in your environment
next: set the setting above, then nk try myapp:old

With no .env yet, it gives the copy step instead, and adds what the example file says of the setting, when it says anything. With the .env.example from earlier:

output
APP_SECRET is not set and .env does not exist: cp .env.example .env and fill it (the example says: "32 random characters")

Other settings are named the same way:

The setting What nk try says
Your repository has no config file at all APP_SECRET is not set: put APP_SECRET=... under environment: of the app in nk/app.yaml, or set it in your environment
The app's own env_file: leaves it empty The setting, named with that file.
It still holds a template's placeholder The setting, named as a placeholder.

What nk try tells you lists every kind of failure and what it prints.

Check your first requests #

When your app serves an OpenAPI or Swagger description, nk try also drafts your first requests:

output
wrote nk/specs/00-safe-reads.hurl: 12 GET requests from /openapi.json; read it before the first compare

Read that file before you go on.

  • safe in its name means GET only. The file holds only GET requests, and leaves out names like logout and delete.
  • The requests go to the copy of your app inside the sandbox, not to your own running servers.

Requests drafted for you says exactly what goes into the file.

Next steps #

Written for nk 0.3.14. Something wrong or unclear? Write to hello@nikasa.dev.