hammerkit

Build files

Publish, propose and yank the build files a server runs, and the versions runs are pinned to.

A run does not bring its own build file. The server keeps the build files that were published to it, and a run says which one to use and which of its tasks to execute. So whoever may run work cannot change what a task does, and what a task does is decided by whoever may publish.

POST /v1/definitions
{
  "entry": ".hammerkit.yaml",
  "files": {
    ".hammerkit.yaml": "tasks:\n  build:\n    cmds: [npm run build]\n",
    "web/.hammerkit.yaml": "..."
  }
}

A published build file is a bundle: the file that starts it (entry, the usual .hammerkit.yaml when left out) and every file it includes, as text, up to 200 files and 1 MiB. It has no name: the server answers with its version, and a run names that. The server reads the bundle the way a run would, in a directory of its own where only the bundle's files exist, so one that does not load is refused when it is published and not when somebody wants to run it (400). A bundle may not include anything outside of itself. Includes from git have to be pinned to a commit and come from an https:// or ssh:// address, and so do the git includes of the files they include, because the version below can only vouch for what is in the bundle.

Versions

Every bundle has a version, the hash of its files: sha256:<hex> of the JSON [entry, [[path, sha-256 of the content], ...]] with the paths sorted. The same files have the same version anywhere, so a client can compute it and compare it with the server's. A version is never changed; publishing other files adds a version, publishing the same files again, by anybody, answers 200 and changes nothing (the first publish answers 201).

The hash is the only name a version has. There is no latest and no line of versions one follows the other in: a name would be the publisher's choice, so a new name could always start a new line, and a comparison with the version before would prove nothing. Whoever reviews a version reads all of it, its plan and its files.

CallWhat it does
POST /v1/definitionsPublish a bundle. Needs builds: publish, else 403. With builds: propose, or when the bundle names accounts the caller does not use, it is a proposal and answers 202. The answer carries the hash.
GET /v1/definitionsEvery version, newest first, with who published (and approved) it and when, its annotations, the tasks and services it has, the accounts it uses and whether it was yanked. ?repo=github.com/corp/payments&machine=ci-7 keeps the versions with those annotations.
GET /v1/definitions/<hash>One version, with its plan and what each task works on (inputs).
GET /v1/definitions/<hash>/filesThe files of one version, to see what would run.
POST /v1/definitions/planWhat publishing the bundle would do, without storing anything. See Checking before publishing.
POST /v1/definitions/<hash>/yankPull a version back, see Yanking. The body is optional: { "reason": "..." }.
POST /v1/definitions/<hash>/unyankLet a yanked version go on. Needs builds: publish.

Reading needs a token and at least one service account or builds level. Versions are kept in the storage directory and survive a restart.

Annotations

Without names, a version says where it comes from with annotations the publisher sends next to the bundle, so the versions of one repository or one machine can be found, and cleaned up, later:

{
  "entry": ".hammerkit.yaml",
  "files": { ".hammerkit.yaml": "..." },
  "annotations": {
    "path": "web/.hammerkit.yaml",
    "repo": "github.com/corp/payments",
    "commit": "4be1a07c...",
    "machine": "ci-runner-7",
    "user": "runner"
  }
}

remote publish fills in path (the build file's path in its git repository, or on the machine outside of one), repo (the origin remote as host/path, left out when it is not an https or ssh address), commit, machine and user. When a file of the bundle differs from that commit, or is not committed, it adds dirty=true: the version has the commit's files plus changes, not the commit's files. Any other key works too: up to 20, lower case letters, digits, ., _ and -, each value up to 500 characters.

Annotations are not part of the hash, so the same files sent from two machines are one version, and it keeps the annotations of its first publish (a proposal keeps the proposer's when it is approved). The server stores them as they were sent: they identify a version, they prove nothing. Who published it is publishedBy, from the token.

Inputs

A version lists, for every task, what it works on, so a client knows which of its files a run needs without planning the build file itself:

"inputs": {
  "build": { "src": ["package.json", "src/**/*.ts", "!src/**/*.spec.ts"], "mounts": [], "deps": [], "needs": [] },
  "test": { "src": [], "mounts": [".npm"], "deps": ["build"], "needs": ["db"] }
}

src are the patterns of the task's own src as the build file writes them (environment variables are not substituted), mounts are the host paths a container task mounts, deps the tasks and needs the services it waits for. Paths are relative to the root of the bundle, which is also the root of the project's files, and a path outside of it is left out because it cannot be sent. What a task inherits from its dependencies is listed with those. Versions published before this was recorded have no inputs.

Plan and accounts

A version also carries a plan, what each task and service does as the engine reads it, and the accounts its secrets are read as. A reviewer or an agent sees deploy uses op-payments-prod before anything runs:

"accounts": ["op-payments-prod"],
"plan": {
  "deploy": {
    "kind": "task", "file": ".hammerkit.yaml", "runtime": "docker", "image": "node:22",
    "cmds": ["./deploy.sh"], "command": "./deploy.sh", "network": "open",
    "deps": [], "needs": [],
    "accounts": ["op-payments-prod"],
    "secrets": [{ "from": "gsm:kube-token", "account": "op-payments-prod", "target": "KUBE_TOKEN" }],
    "serverEnvs": [],
    "mounts": [], "ports": [], "generates": [],
    "flags": ["local-task"]
  }
}

command is the last command of a task (the cmd of a service), where a run's arguments land; null when there is none. serverEnvs are the variables of the server its envs read ($NAME, ${NAME}). network is what it reaches besides its needs, as the build file declares it (open when it declares nothing). Versions published before these were recorded have neither. file is the build file that declares it, as a path in the bundle, or the repository and the path in it for one of a git include. deps and needs name the tasks and services as the plan does (services:postgres for postgres of an include). Versions published before these were recorded have no file, and name what a task needs as its build file does. runtime is docker, local, or none for an aggregate task, which runs nothing.

The plan never holds a value of a secret, only where it is read from. flags are what a reviewer looks at first: local-task (it runs on the host, not in a container), host-port (it binds a port of the host), remote-include (it includes a file from git) and capabilities (it adds the Linux capabilities in capAdd, see Capabilities). A bundle that names an account the server does not define is refused and the message lists the accounts that exist.

Publishing and accounts

A bundle that uses an account the publisher does not use becomes a proposal even for builds: publish, and is approved by somebody who may publish and who uses the accounts the proposer lacks. So one person can not publish a task that reads the production key for somebody else to run without a second pair of eyes.

What a build file may not do

A build file is written by whoever publishes it and runs with what the operator gave the server, so a bundle is refused (400, naming the file and task) when it

  • names environments: the docker host or Kubernetes cluster is the server's to choose,
  • has a service for Kubernetes (selector, kubeconfig or context),
  • names a cache backend other than the server's own (s3, registry, or a path),
  • mounts a path outside of the bundle into a container, such as the docker socket, /etc or a home directory, or has a src or generates outside of it (the server would copy its own files into the task),
  • has a service volume whose name is a path (/var/run/docker.sock:/var/run/docker.sock), which docker would mount from the host,
  • has a task on a runtime that runtimes does not allow,
  • has a task that adds a capability (capAdd) that backend.capabilities does not allow, which is any when the server names no sandbox for them,
  • has a task or service whose network reaches more than runs.network allows,
  • declares secretProviders or secretAccounts (keep them in your host config), reads a file: secret, reads an env: secret the server does not list in runs.env.allow, or reads a secret as the account that reads repositories (see Accounts and Sources).
  • on a Kubernetes backend, reads a provider secret in a service, one with cache: true, or one in a task with a limited network.

A run checks the same paths again in its checkout, before it starts and before each task or service runs: one whose src, generates or mount goes through a symbolic link of the checkout fails, since docker and the copy into a cluster would follow the link out of it. On a docker backend, once a container has started, the server also compares each folder and file it binds with the one of the checkout, and a container that sees anything else fails before anything of its image runs: a task's before any of its commands, a service's before its own command or entrypoint. The server checks that with tools of its own, which it puts in a folder of its own in each container (/.hammerkit- and a random name), so the image needs nothing for it. They are a file in the tools folder of the server's hammerkit directory (HAMMERKIT_DIR), bound by its path, so a server that runs in a container needs that folder at the same path on the docker host, as it needs the files of its runs. No src, output, mount, volume or secret file can be at / or at or in a folder of / whose name starts with .hammerkit. A task that adds capabilities runs in a sandboxed runtime on a docker host, where what the container binds can't be compared, so there it can't bind files of the run: its src, file outputs and mounts fail the run (cache volumes are fine).

Without this a task with no secrets would still reach what the operator's machine can: a published file would be enough to send a run, or the cache, to a host of its choosing.

Only part of a build file

One build file usually holds tasks for the server and tasks only your machine runs: a watcher, a task that mounts the docker socket, a service for local development. Mark those publish: false, and the server leaves them out of the version: they are not in its tasks, not in its plan, and not checked against the rules above.

.hammerkit.yaml
includes:
  infra: { path: ./infra.yaml, publish: false } # everything of the file
services:
  db:
    image: postgres:16
    publish: false
tasks:
  build:
    image: node:22-alpine
    cmds: [npm run build]
  watch:
    cmds: [npm run watch]
    publish: false

A file left out is not checked for what the list above refuses of a published one: its environments (a local docker host or kind cluster), caches, Kubernetes services and secretProviders stay on your machine. Neither is a Kubernetes service with publish: false. A git include with publish: false is not fetched by the server, so its ref may be a branch.

Locally publish changes nothing. A published task or service that depends on, needs, extends or runs as init one that is left out is refused, naming both: test needs db, which is not published (publish: false).

publish: false belongs to the include, not to the file: a file that another published file includes too is published through that one, under that one's name.

Checking before publishing

hammerkit remote publish --dry-run

The server reads the bundle with its policy as a publish would, and says what publishing it would do: publish it, propose it (and which accounts make it a proposal), or that it is published already. A bundle the server would refuse prints why: every problem with its policy, or the first git include it may not fetch. Nothing is stored. Any builds level may check, run too, so a developer can check a build file before the account that publishes it does. As for a proposal, a caller who may not publish can't make the server fetch a git include: a build file that includes from git (and publishes that include) is checked by somebody with builds: publish. A version that is published already is not checked again, the answer says when it is yanked.

POST /v1/definitions/plan

takes the bundle as POST /v1/definitions does and answers its hash, tasks, services, plan, accounts and outcome: published, proposed, already published, or null for who may only run (missing lists the accounts the caller does not use, yanked is set for a yanked version).

A build file that is checked, proposed or published reads the variables of runs (runs.env.allow and runs.env.set) by their names: ${NAME} stands in for the value of each but PATH, HOME and CI. So a description or an image that reads one shows ${DEPLOY_REGION} in the plan, never what a run would see; a run reads the values. A version published by a server of before this keeps the plan it was published with: publish the build file again (with any change, so it gets a new hash) when its description or image reads a variable of runs.

Proposing a version

Who defines the work decides what runs, so a new version of a build file can wait for a second pair of eyes. builds: propose is the lower level of publish, like request is the lower level of use:

server.yaml
entitlements:
  - group: { iss: https://login.example.com, name: platform }
    accounts: { op-payments-prod: use }
    builds: publish
  - claims:
      iss: https://login.example.com
      match: { client: coding-agent }
    builds: propose

A caller who may only propose sends the same POST. The server reads the bundle as it does for a publish and refuses one that does not load, then keeps it as a proposal (202). A publish also ends up here when the bundle names accounts the publisher does not use (missing lists them). It is not a version: it can not be run and it is not listed with the versions. Someone who may publish, uses the accounts in missing, and did not propose it, approves it, and only then it is published, as the proposer's version with the approver recorded as approvedBy. That is the version runs refer to by hash, so what was approved is what runs.

CallWhat it does
GET /v1/proposalsThe proposals the caller made or may see, newest first, with state (waiting, approved, rejected, expired), who proposed it, the tasks and services, the accounts and the missing ones, plan and whether the caller canDecide.
GET /v1/proposals/<hash>One of them.
GET /v1/proposals/<hash>/filesIts files, to read what would be published.
POST /v1/proposals/<hash>/approvePublish it. The body is optional: { "reason": "..." }.
POST /v1/proposals/<hash>/rejectDrop it; the reason (up to 500 characters) is kept with it.

A proposal is visible to its proposer and to everyone who may publish; what the caller neither proposed nor may decide does not exist for them (404), and one that is decided or expired is 409. A proposal expires after the approvals.timeout like a requested run does, and approvals.maxWaiting limits the proposals that wait (503). Proposals are kept in memory, unlike runs: after a restart the proposer proposes again. Each proposal and decision is logged with who made it.

Whoever decides reads the proposal whole, its plan and its files (remote show does both). There is no diff against an earlier version: a proposal follows none.

No git includes

A proposal is read before anybody approved it. A bundle that includes from git would make the server fetch from the network for a caller who may only propose, so a proposal with includes or references from git is refused (400). Whoever may publish can use them.

Cooldown

After a rejection, the proposer can not propose anything, and nobody that version, for approvals.cooldown (default 10m): 429, with the time left. A proposal that only ran out of time does not start one. It keeps the people who decide from being asked again and again; like the proposals it is forgotten by a restart.

A proposal approves a new version of the build file, not the code its commands run: npm test still executes the files a run brings. Production accounts stay behind request and source: [ref].

Yanking a version

A published version is never changed, but one can be pulled back when it should not run any more (it leaks a token, it deploys to the wrong place). POST /v1/definitions/<hash>/yank is open to whoever has builds: publish, and to whoever uses an account the version works with: the people who answer for what runs as that account do not have to wait for a publisher. The body may carry a reason, up to 500 characters.

A run that names a yanked version is refused with 409 and the reason, and a run that was accepted before, and still waits for an approval or in the queue, fails when it would start. Runs that already execute are not stopped; cancel them. The version and its files stay on the server for the record, and the version list shows who yanked it and why. Without names, yanking is the only way to stop a version: every published hash stays runnable until it is yanked. unyank lets it go on, and needs builds: publish. Both are logged with who did it, and a yank survives a restart.

From the command line, remote publish publishes or proposes the build file of the working directory and prints its hash, and remote proposals, show, approve, reject, yank and unyank work with the versions.

On this page