# Publishing a channel

Publish release artifacts to any S3-compatible bucket, sign each build's manifest with AWS KMS or an OpenSSH Ed25519 key, and record every event in the channel's append-only journal. Assumes `engram` is installed on `PATH` (see [Install](https://engram.neuroplast.io/#install)).

## Export the pinned public key

Before clients can verify a channel, export the signing key as an OpenSSH `allowed_signers` line and pin it in client code, CI workflows, or host configs:

```sh
engram pubkey --kms alias/release-signing --identity release@example.org
```

To print a bare OpenSSH public key instead of an `allowed_signers` line, omit `--identity`. Replace `--kms` with `--key-file /path/to/id_ed25519` when signing with a local unencrypted key file.

## Publish a build

Each artifact argument has the form `<name>/<os>/<arch>=<local-path>`. Every artifact in a build must have a distinct base filename (and none may be named `manifest` or `manifest.sig`).

```sh
engram publish \
  --bucket my-releases \
  --kms alias/release-signing \
  --project acme \
  --channel stable \
  --retention 720h \
  --commit "$(git rev-parse HEAD)" \
  --version "$VERSION" \
  --time "$(git show -s --format=%cI HEAD)" \
  acme/linux/amd64=dist/acme_linux_amd64.tar.gz \
  acme/darwin/arm64=dist/acme_darwin_arm64.tar.gz
```

Re-running `engram publish` for a commit already recorded in the journal exits 0 without changing anything, so failed CI workflows are safe to retry.

<!-- docs:figure text=publish-flow.ans text-narrow=publish-flow-tall.ans svg-narrow=publish-flow-tall.svg -->
![Publish sequence: upload immutable artifacts, sign manifest via KMS or key file, conditionally update journal with If-Match, update head and latest/, then delete expired builds and purge CDN.](https://engram.neuroplast.io/docs/_files/docs/publish-flow.svg)

## Flags and backends

| Flag | Commands | Default | Meaning |
| --- | --- | --- | --- |
| `--project`, `--channel` | `publish`, `scrap` | required | Channel path `<project>/<channel>` |
| `--bucket` | `publish`, `scrap` | | S3-compatible bucket name (mutually exclusive with `--dir`) |
| `--endpoint` | `publish`, `scrap` | AWS S3 | Custom S3-compatible endpoint (Cloudflare R2, MinIO, etc.) |
| `--region` | `publish`, `scrap`, `pubkey` | `us-east-1` | Region for the S3 bucket and KMS key |
| `--dir` | `publish`, `scrap` | | Publish into a local directory for dry runs instead of a bucket |
| `--cloudfront` | `publish`, `scrap` | | CloudFront distribution ID to purge updated `latest/` mirrors and deleted (scrapped or expired) builds |
| `--kms` | `publish`, `pubkey` | | AWS KMS Ed25519 key ID, ARN, or `alias/<name>` (private key stays in KMS; mutually exclusive with `--key-file`) |
| `--key-file` | `publish`, `pubkey` | | Unencrypted OpenSSH Ed25519 private key file (`ssh-keygen -t ed25519 -N ""`; mutually exclusive with `--kms`) |
| `--identity` | `pubkey` | empty | Print an `allowed_signers` line for this identity instead of a bare public key |
| `--commit` | `publish`, `scrap` | required | Full 40-character Git commit SHA |
| `--version` | `publish` | required | Human-readable version string (never parsed or sorted) |
| `--time` | `publish` | required | Commit timestamp in RFC 3339 format |
| `--min-enboot` | `publish` | `1` | Minimum `enboot` protocol version required by this build |
| `--retention` | `publish` | `0` (keep all) | Expire builds superseded for longer than this duration (for example `720h`) |
| `--reason` | `scrap` | empty | Optional withdrawal reason: `broken`, `security`, or `mistake` |

The S3 backend must support conditional writes (`If-Match` and `If-None-Match`). `engram publish` retries up to 5 times on a `412 Precondition Failed` conflict so concurrent CI jobs cannot overwrite each other's journal entries. Retention counts from when a newer build supersedes an older one, so the newest live build never expires (see [Publish ordering, retention, and caching](https://engram.neuroplast.io/docs/spec#publish-ordering-retention-and-caching)).

## Credentials

`engram` reads only the standard AWS environment variables: `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and optionally `AWS_SESSION_TOKEN`. No AWS config files or credential chains are loaded.

- In GitHub Actions, `aws-actions/configure-aws-credentials` exports these variables from an OIDC role.
- On a workstation, run `eval "$(aws configure export-credentials --format env)"`.

## Cache invalidation and scrapping

Normal publishes never invalidate `builds/<commit>/` because every commit uses a new immutable path; only `latest/` is purged when `--cloudfront` is set (see [Channel specification](https://engram.neuroplast.io/docs/spec#publish-ordering-retention-and-caching) for exact `Cache-Control` lifetimes).

Withdrawing a broken or vulnerable build deletes its files from storage and records a `scrap` event in the journal:

```sh
engram scrap \
  --bucket my-releases \
  --cloudfront E1234567890ABC \
  --project acme \
  --channel stable \
  --commit <40-hex-commit> \
  --reason broken
```

Pass `--cloudfront <distribution-id>` whenever a CloudFront distribution serves the bucket so scrapped and expired `builds/<commit>/` prefixes and updated `latest/` files are purged from edge caches. Without a cache purge, edge nodes continue serving deleted immutable files until their TTL expires.

## Verify immediately after publish

After `engram publish`, confirm that the CDN serves the signed manifest and the exact uploaded bytes without re-downloading full artifacts:

```sh
engram verify \
  --url https://pkg.example.org \
  --project acme \
  --channel stable \
  --signers allowed_signers \
  --commit "$(git rev-parse HEAD)" \
  --local dist
```

See [Installing and verifying](https://engram.neuroplast.io/docs/installing) for how `--local`, `--fetch`, and `install.sh` validate builds, and [Channel specification](https://engram.neuroplast.io/docs/spec) for the exact file format and publish ordering.
