cram
Use when a project has a cram.toml or builds with `cram build`, when publishing, promoting or rolling back a cram app version, when an update channel or `.well-known/cram` pointer is missing or stale, or when an installed cram app resolves the wrong version.
Synopsis
The YAML description states when to use this skill. disable-model-invocation is unset.
Source file: skills/cram/SKILL.md.
Front matter
- name
cram- description
- Use when a project has a cram.toml or builds with `cram build`, when publishing, promoting or rolling back a cram app version, when an update channel or `.well-known/cram` pointer is missing or stale, or when an installed cram app resolves the wrong version.
- disable-model-invocation
- unset
Full contents
---
name: cram
description: Use when a project has a cram.toml or builds with `cram build`, when publishing, promoting or rolling back a cram app version, when an update channel or `.well-known/cram` pointer is missing or stale, or when an installed cram app resolves the wrong version.
---
# cram
`cram` packs a Nix flake or devenv output into one self-extracting Linux file. The
file updates itself from `https://<domain>/.well-known/cram`, where a **pointer** is a
small file whose body is the artifact URL:
```
.well-known/cram/channels/stable https://gitlab.example/api/v4/projects/slopkit%2Fpot/packages/generic/pot/0.5.0/pot-linux-amd64
.well-known/cram/versions/0.5.0 same URL, one line, no trailing newline
```
CI writes both pointers. A release that needs a hand-written pointer is a release with
broken wiring.
## Manifest
```toml
[[app]]
name = "pot"
version = "0.5.0" # also in the product's own manifest (Cargo.toml, package.json)
domain = "pot.slopkit.dev"
channels = ["stable"] # first entry is the one a release moves
flake = ".#cram"
bin = "bin/pot"
```
`cram bump --config cram.toml <app> <major|minor|patch>` rewrites only `cram.toml`. Bump
the product's own version files by hand. A tag `<app>-v<version>` must agree with all of
them; the project's CI usually enforces it.
## Check the wiring before the tag
Wired means all three hold:
1. `.gitlab-ci.yml` includes `slopkit/cram/release@main` with the website inputs:
```yaml
include:
- component: $CI_SERVER_FQDN/slopkit/cram/release@main
inputs:
app: pot
config: cram.toml
website_project: slopkit/pot-website
website_token: CRAM_WEBSITE_TOKEN # the variable's name; no $
```
2. The CI variable named by `website_token` exists on the product project or its group
(names and scope only, never values):
```console
$ glab api "projects/slopkit%2Fpot/variables?per_page=100" | jq -r '.[].key'
$ glab api "groups/slopkit/variables?per_page=100" | jq -r '.[].key'
```
The token behind it has not expired. An expired token fails the next release job
with a push error, long after anyone set it up:
```console
$ glab api "projects/slopkit%2Fpot-website/access_tokens" | jq -c '.[]|{name,expires_at,active}'
```
3. The website's `deploy.nix` serves every file under `.well-known/cram/channels` and
`versions`. Push uploads files, not directories, so the list is read from disk:
```nix
files = dir: map (n: "${dir}/${n}") (builtins.attrNames (builtins.readDir (./. + "/${dir}")));
# staticPaths = [ ... ] ++ files ".well-known/cram/channels" ++ files ".well-known/cram/versions";
```
Each missing piece is a fix in its own commit on the right repo, landed before the
tag. A missing or expired token is replaced by a project access token on the **website**
project (`write_repository`, Maintainer, under a year) stored masked on the product
project. It creates a credential, so a user who has not already asked for it confirms
the command first:
```console
$ exp=$(date -d '+364 days' +%F)
$ jq -n --arg e "$exp" '{name:"cram-pointer",scopes:["write_repository"],access_level:40,expires_at:$e}' \
| glab api -X POST "projects/slopkit%2Fpot-website/access_tokens" --input - -H 'Content-Type: application/json' \
| jq -r .token | glab variable set CRAM_WEBSITE_TOKEN --masked -R slopkit/pot
```
The value goes from the API into the variable and nowhere else: do not print or store
it. Tell the user the expiry date, so the next renewal is on someone's calendar.
An app with no update domain sets `website_optional: "true"` on the component.
## Release
Push the tag `<app>-v<version>`. Job `cram:release` builds, signs, uploads
`packages/generic/<app>/<version>/<app>-linux-amd64`, and commits both pointers to
`website_project`. Read the pipeline, not the local build:
```console
$ glab ci status --branch pot-v0.5.0 --live
```
Orange with exit code 42 means the artifact is published and no pointer moved: the
wiring is broken. Fix it, then run `cram:promote` (below) for the same version.
## Promote and roll back
`cram:promote` is a manual job that moves one channel to a version already published,
with no rebuild. Rolling back is promoting the previous version.
```console
$ glab ci run --branch main --variables CRAM_PROMOTE_VERSION:0.4.0 --variables CRAM_PROMOTE_CHANNEL:stable
$ glab ci trigger cram:promote --branch main
```
## Verify a published version
Resolve the pointer the way an installed app does, then run the file in a scratch store:
```console
$ curl -fsS https://pot.slopkit.dev/.well-known/cram/channels/stable
$ url=$(curl -fsS https://pot.slopkit.dev/.well-known/cram/versions/0.5.0)
$ curl -fsSL "$url" -o /tmp/pot-0.5.0 && chmod +x /tmp/pot-0.5.0 && sha256sum /tmp/pot-0.5.0
$ CRAM_DATA_HOME=$(mktemp -d) /tmp/pot-0.5.0 --version
$ CRAM_DATA_HOME=$(mktemp -d) /tmp/pot-0.5.0 info
```
Done when the channel and the version pointer both name `0.5.0`, the download succeeds,
`--version` prints `0.5.0`, and the sha256 is written down for the install script.
`cram verify <file> --pubkey <key>` checks the signature when the CLI is installed.
An installed app reads its channel with `./app channel`, switches with
`./app channel beta`, updates with `./app update`, and honours `CRAM_CHANNEL` and
`CRAM_VERSION` over its saved choice.