Buckets:
| // Copyright (c) 2026 the Zuke contributors | |
| // SPDX-License-Identifier: MIT | |
| /** | |
| * How {@link https://jsr.io/@zuke/docker-compose dockerComposeCanary} reaches a | |
| * Compose project: the fluent settings its lambda configures, the context the | |
| * canary engine hands each call, and the seam each command is run through. | |
| * | |
| * @module | |
| */ | |
| import type { SummaryPairs, TargetStateHandle } from "@zuke/core"; | |
| import type { CommandOutput } from "@zuke/core/shell"; | |
| import type { Configure } from "@zuke/core/tooling"; | |
| import type { DockerComposeSettings } from "./settings.ts"; | |
| /** | |
| * Runs one prepared Compose command and returns its output. `env` holds the | |
| * image variables the platform already applied to `settings` — handed over | |
| * as well so a runner that executes Compose some other way, or a test, sees | |
| * them. The default runs the settings; inject another with | |
| * {@link DockerComposeCanarySettings.runner}. An output with a non-zero exit | |
| * code fails the call, as a rejection does. | |
| */ | |
| export type DockerComposeSettingsRunner = ( | |
| settings: DockerComposeSettings, | |
| env: Readonly<Record<string, string>>, | |
| ) => Promise<CommandOutput>; | |
| /** | |
| * The part of the canary engine's context the Compose platform uses: the | |
| * rollout's durable state, where the images are recorded, and the build | |
| * summary. The engine hands a richer context; this is the narrow view. | |
| */ | |
| export interface DockerComposeCanaryContext { | |
| /** The rollout's durable platform state, shared by every call. */ | |
| readonly state: TargetStateHandle; | |
| /** Add key/value pairs to the calling target's row in the build summary. */ | |
| reportSummary(pairs: SummaryPairs): void; | |
| /** | |
| * Why `abort` runs: `"rollback"` when the engine undoes a rollout, | |
| * `"hand-run"` for `rollout.abort` run on its own. An engine older than | |
| * this field leaves it out, which is treated as a hand run — the behaviour | |
| * from before the field existed. | |
| */ | |
| readonly reason?: "rollback" | "hand-run"; | |
| } | |
| /** | |
| * How {@link dockerComposeCanary} reaches the project, configured through its | |
| * lambda. | |
| */ | |
| export class DockerComposeCanarySettings { | |
| /** The service that serves the stable release (set by {@link service}). */ | |
| service_?: string; | |
| /** The service that runs the candidate (set by {@link canaryService}). */ | |
| canaryService_?: string; | |
| /** The replicas the two services share (set by {@link replicas}). */ | |
| replicas_?: number; | |
| /** The candidate's image (set by {@link image}). */ | |
| image_?: string; | |
| /** The variable the stable service's image reads (set by {@link stableImageVariable}). */ | |
| stableImageVariable_?: string; | |
| /** The variable the canary service's image reads (set by {@link canaryImageVariable}). */ | |
| canaryImageVariable_?: string; | |
| /** The image a hand-run rollback returns to (set by {@link stable}). */ | |
| stable_?: string; | |
| /** Global Compose flags for every command (set by {@link compose}). */ | |
| compose_?: Configure<DockerComposeSettings>; | |
| /** How each command is run (set by {@link runner}). */ | |
| runner_: DockerComposeSettingsRunner = (settings) => settings.run(); | |
| /** | |
| * The service that serves the stable release, e.g. `app`. It must already | |
| * be running: `stage` reads the image its replicas run, which is what a | |
| * rollback returns them to. | |
| */ | |
| service(name: string): this { | |
| this.service_ = name; | |
| return this; | |
| } | |
| /** | |
| * The service that runs the candidate, e.g. `app-canary` — a second | |
| * service in the same project, behind the same proxy, whose `image:` is | |
| * `${<canaryImageVariable>}`. Give it `scale: 0` in the Compose file so a | |
| * plain `docker compose up` does not start it. | |
| */ | |
| canaryService(name: string): this { | |
| this.canaryService_ = name; | |
| return this; | |
| } | |
| /** | |
| * How many replicas the stable and canary services share between them. A | |
| * step sets the canary to its share of this and the stable service to the | |
| * rest; `stage` and a rollback set the stable service to all of it. From 2 | |
| * to 10000. Give the stable service the same `scale:` in the Compose file: | |
| * a plain `docker compose up` sets every service back to its `scale:`. | |
| */ | |
| replicas(total: number): this { | |
| this.replicas_ = total; | |
| return this; | |
| } | |
| /** The candidate's image reference, which `stage` puts on the canary service. */ | |
| image(reference: string): this { | |
| this.image_ = reference; | |
| return this; | |
| } | |
| /** | |
| * The environment variable the stable service's `image:` is — the whole | |
| * reference, as in `image: ${APP_IMAGE}`, not just a tag. Every command the | |
| * platform runs sets it, so the project's `.env` need not: to the image the | |
| * stable replicas ran when `stage` looked, to the candidate on promotion. | |
| * Not a name Docker, Compose or the process reads as a setting — | |
| * `DOCKER_*`, `COMPOSE_*`, `BUILDKIT_*`, `BUILDX_*`, `XDG_*`, `LD_*`, | |
| * `DYLD_*`, `*_PROXY`, `PATH`, `PATHEXT`, `HOME`, `USERPROFILE`, | |
| * `SystemRoot`, `TMPDIR`, `TEMP`, `TMP`, `SSH_AUTH_SOCK`, `SSL_CERT_FILE` | |
| * or `SSL_CERT_DIR`, in any case — and not the canary's variable in | |
| * another case. | |
| */ | |
| stableImageVariable(name: string): this { | |
| this.stableImageVariable_ = name; | |
| return this; | |
| } | |
| /** | |
| * The environment variable the canary service's `image:` is, as in | |
| * `image: ${APP_CANARY_IMAGE:-${APP_IMAGE}}`. Every command that brings up | |
| * the canary sets it to the candidate. | |
| */ | |
| canaryImageVariable(name: string): this { | |
| this.canaryImageVariable_ = name; | |
| return this; | |
| } | |
| /** | |
| * The image to put the stable service back on when `rollout.abort` is run | |
| * by hand — a reference with no whitespace or control characters. Such a | |
| * run is fresh, with no record of a rollout, so it has nothing else to go | |
| * on — and the release it is undoing has usually been promoted already. A | |
| * rollback the engine runs does not use it: mid-rollout it returns to the | |
| * image ID `stage` saw the stable replicas running, and with nothing | |
| * recorded it runs nothing, since nothing was staged. | |
| */ | |
| stable(image: string): this { | |
| this.stable_ = image; | |
| return this; | |
| } | |
| /** | |
| * Global flags for every Compose command the platform runs — | |
| * `(s) => s.file("compose.yml").projectName("shop")`, or `.usePlugin()` to | |
| * skip detection. Compose 2.21 or later (`docker compose`) is required: | |
| * the project check's `{{.Label ...}}` template is not in earlier | |
| * releases, and the v1 | |
| * `docker-compose` binary has no `--wait`, `pull --policy` or | |
| * `ps --format`. Trailing `.args(...)` are refused, since they would land | |
| * after the service each command names — a guard against an accident, not | |
| * a security boundary: this lambda is the build's own code and can run | |
| * Compose however it likes. A non-zero exit fails the call even with | |
| * `.noThrow()`. | |
| * | |
| * The flags it gives select the project, so `stage` records them (as argv: | |
| * what `.env(...)` passes is never recorded) and every later call refuses | |
| * unless they are the same, in the same order. It also records the | |
| * project Compose reports the stable replicas in, and every later call | |
| * refuses unless Compose still reports the services there — which covers | |
| * whatever else resolves the project: `COMPOSE_PROJECT_NAME` in the | |
| * environment, a `.env` or `--env-file`, `.env(...)` and `.cwd(...)` here, | |
| * the working directory. Not covered: a Docker context, `DOCKER_HOST` or | |
| * `.toolPath(...)` that reaches another daemon running the same project | |
| * with the same services on the same images; a `COMPOSE_FILE` or env file | |
| * that keeps the project but changes the services' definitions, or — with | |
| * an explicit `-p` and no `-f` — a working directory or `.cwd(...)` that | |
| * loads another `compose.yml` under the same name. And `.env(...)` and | |
| * `.cwd(...)` are checked only at each call's project read, while later | |
| * commands re-check only the flags, so this lambda must give the same ones | |
| * every time it runs. | |
| */ | |
| compose(configure: Configure<DockerComposeSettings>): this { | |
| this.compose_ = configure; | |
| return this; | |
| } | |
| /** | |
| * Replace how each prepared command is run. The default runs it; this is | |
| * for a test, or for a build that executes Compose through something else. | |
| */ | |
| runner(run: DockerComposeSettingsRunner): this { | |
| this.runner_ = run; | |
| return this; | |
| } | |
| } | |
Xet Storage Details
- Size:
- 8.36 kB
- Xet hash:
- bdfff8e5f60d45377ed5098e20ac7de794a9ed826d49ca9b4ed3bff3a2bca891
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.