Skip to content

#294: preview image-repository override (build.image_repo) - #295

Closed
simpros wants to merge 1 commit into
mainfrom
feat-sprout-294-image-repo-override
Closed

simpros wants to merge 1 commit into
mainfrom
feat-sprout-294-image-repo-override

Conversation

@simpros

@simpros simpros commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Why the change

sprout ci preview hardcoded every app and seed push to ${CI_REGISTRY_IMAGE}:${SHA}, so adopters whose registry root only held throwaway preview tags could never retire that root; this ships an optional .sprout.yaml build.image_repo that retargets build, deploy, reseed, reset, and teardown tag deletion to one repository while leaving unset repos byte-identical.

Special things to note

  • The override is manifest config (.sprout.yaml build.image_repo), not a component input, so preview, teardown, reseed, and reset share one source and templates/preview.yml / .github/workflows/preview.yml stay unchanged; it wins over CI_REGISTRY_IMAGE, and GitHub's existing registry/image_name inputs keep working when the key is unset.
  • GitLab teardown deletes through the preview project's registry API, so the override must be a repository of that project (a sub-repository such as …/dcos/product); a cross-project override only produces the existing best-effort warnings. GHCR resolves owner/package from the ref either way.
  • resolveCiPreviewIdentity, resolveCiPushedImageRefs, and ci reseed now read the manifest before resolving the ref; with an unreadable manifest, teardown falls back to the registry root exactly as today.

Change outline

apps/cli/src/
├── yaml.ts                                  # SproutBuild.image_repo + parseBuildBlock validation
└── commands/
    ├── ci-identity.ts                       # resolveImageRef(env, identity, imageRepo?); preview/pushed refs read yaml first
    ├── ci-reseed.ts                         # yaml first, then resolveImageRef with the override
    ├── ci-preview.ts  ci-deploy.ts          # unchanged; consume identity.imageRef
    ├── ci-reset.ts    seed-image.ts         # unchanged; seed ref derives from the retargeted app ref
    ├── ci-teardown.ts image-cleanup.ts      # unchanged; deletes the refs the push produced
    ├── yaml.test.ts                         # key parse + validation cases
    ├── ci-identity.test.ts                  # override set/unset, both forges, missing SHA
    ├── ci-preview.test.ts                   # build/push/deploy under the override
    ├── ci-reset.test.ts                     # reset deploys override refs, no rebuild
    ├── ci-teardown-reseed-logs.test.ts      # reseed deploys override app image
    └── ci-teardown-tags.test.ts             # teardown deletes exactly the override tags
docs/  adopting-a-repo.md · ci-integration.md · cli-reference.md · troubleshooting.md
templates/README.md
type SproutBuild = SproutDockerfileBlock & {
  /** Full repository (registry host + path, no tag); defaults to CI_REGISTRY_IMAGE. */
  image_repo?: string;
};

// The one seam every consumer already routes through.
function resolveImageRef(
  env: NodeJS.ProcessEnv,
  identity: Pick<CiIdentity, "forge" | "commitSha">,
  imageRepo?: string,          // yaml.build?.image_repo
): Result<string>;             // `${imageRepo ?? env.CI_REGISTRY_IMAGE}:${identity.commitSha}`

Base: origin/main @ 50fd6f5. Gates run: bun install, bun run typecheck, bun run test (396 CLI tests + 135 guard tests, all green).

Closes #294

@simpros

simpros commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Round 1 · head 6b38f64a

APPROVE

build.image_repo widens the single ref seam every consumer already funnels through, so preview build/push, deploy, reseed, reset and teardown tag deletion all retarget consistently while unset manifests stay byte-identical, with matching CLI/docs coverage and green gates.

Full review report

Verdict

APPROVE

Summary: build.image_repo widens the single ref seam every consumer already funnels through, so preview build/push, deploy, reseed, reset and teardown tag deletion all retarget consistently while unset manifests stay byte-identical, with matching CLI/docs coverage and green gates.

What I reviewed

  • Base origin/main @ 50fd6f5, head 6b38f64 (matches this worktree), 14 files, +444/−45, entirely in apps/cli/src, docs/, templates/README.md.
  • Issue Preview image repository override: allow pushing app/seed tags to a sub-repository #294's acceptance criteria, mapped to the diff:
    • override pushes <override>:<SHA> (+ seed) and deploys from it — resolveCiPreviewIdentity + ci-preview/ci-deploy consume identity.imageRef; seed-image derives <repo>:<SHA>-seed from that ref, so the seed follows for free.
    • teardown deletes exactly those tags — resolveCiPushedImageRefs now reads the manifest first and hands the same refs to image-cleanup.
    • reseed and reset agree — both resolve through the widened seam (ci-reseed reads yaml first; ci-reset reuses identity.imageRef).
    • unset behaves as today — override || CI_REGISTRY_IMAGE and the old error string when unset; the new resolveCiPushedImageRefs fallback for an unreadable manifest preserves the previous registry-root + seed warning path.
    • docs where ci preview inputs are documented — manifest table, ci-integration, cli-reference, troubleshooting, component README all updated, and the new error texts are documented verbatim.
  • Design fit: one seam (resolveImageRef(env, identity, imageRepo?)), no duplicated ref string building, no workflow/component churn, BUILD_KEYS replaces the now-wrong DOCKERFILE_KEYS, yaml-only config so all four CI entry points agree without extra wiring. Comment added is a real invariant and follows CODE-STYLE.md (no ticket/history references, no restating code).

Gates I ran locally on 6b38f64

  • bun run typecheck — 5/5 packages plus docs/scripts typecheck and docs link check: pass.
  • bun test in apps/cli — 396 pass / 0 fail (29 files).
  • bun run test (turbo + guards) — including preview-db 18/18 and guards 135 pass / 0 fail; docs links OK.

New coverage is proportionate and behavioural, not tautological: yaml accept/reject cases, override set/unset/missing-SHA on both forges, preview docker argv + deploy body, reset with no rebuild, reseed deploy body, and teardown asserting the exact two override tag URLs against a GitLab repository id resolved from a nested path.

Non-blocking nits

  1. parseImageRepoField under-validates against its own contract ("no tag or digest"). Probe results on this tree:
    • https://registry.gitlab.com/team/app → accepted (scheme slips through; produces a nonsense ref and an opaque docker push failure);
    • registry.gitlab.com/team/app:v1/extra → accepted (a tag segment containing / hides from the last-segment colon check);
    • registry.gitlab.com/Team/App → accepted (uppercase repository names are rejected by Docker itself);
    • ghcr.io//app, ghcr.io/team/app#frag → accepted.
      A cheap scheme/#/uppercase guard (or reusing parseImageRef on a probe ref) would turn those into the existing one-line hint at parse time. The realistic inputs the docs show are all handled correctly, so this is robustness, not a behaviour bug.
  2. GitLab teardown only finds the override when it is a repository registered under the preview project (templates/README.md notes the token scope; docs/adopting-a-repo.md says flatly "teardown deletes from the same repository"). A cross-project or foreign-host override degrades to the documented best-effort warnings and silently leaves the tags to the expiration policy — worth one clause in the docs so the guarantee matches the implementation.
  3. GitHub + an override whose host is not inputs.registry will fail at the docker/login-action step, since the workflow keeps logging into registry. Fine as-is for a GHCR sub-repository (the common case) and the workflow is deliberately untouched, but the docs read as forge-agnostic ("overrides CI_REGISTRY_IMAGE") without that caveat.
  4. Residual coupling, pre-existing in shape: teardown re-reads .sprout.yaml at teardown time to know where to delete. If teardown checks out a tree without the key (e.g. a closed-unmerged GitHub PR where the override landed only on the PR branch), deletion targets the old root and the override tags wait for the forge policy. Same class of coupling the seed-tag cleanup already had; not introduced here.

None of the above affects the accepted-path behaviour, the backwards-compatibility claim, or the issue's acceptance criteria, so this is an approve.

@simpros

simpros commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Overkill

@simpros simpros closed this Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preview image repository override: allow pushing app/seed tags to a sub-repository

1 participant