Add w10k: deploy Puppet environments as sha-pinned git worktrees #1
Reference in New Issue
Block a user
Delete Branch "benvin/scaffold"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
g10k rewrites environments in place, so a compile during a deploy can read mixed old and new code. w10k deploys each branch as an immutable sha-pinned worktree and swaps it in atomically.
:git, os.Root writes, size caps<basedir>/<env>via symlink + rename(2); write g10k's.g10k-deploy.json--gc-grace, unmarking anything live-j; release binaries and an RPM onv*tagsurlgoes togit fetchas a bare arg; a branch Puppetfile:git => '--upload-pack=<cmd>;'runs<cmd>as the deploy user → put--beforeurl, and reject:gitvalues starting with-in parseModMkdirAll/RemoveAll/Symlinkfollow symlinks: a committed symlink used asinstall_pathdeletes and writes outside the worktree, and a nestedinstall_path(e.g.modules/thing) writes into the sharedforge//modules/cache dir that live envs use → build module paths withos.OpenRoot(target)(Root.MkdirAll/RemoveAll/Symlink), and reject module paths that sit under another module's path.g10k-deploy.jsonexists, but a branch can commit that file; if checkout fails afterworktree add, the next run treats the half-built worktree as complete and swaps it live without its modules (it also feeds a branch-controlled module list into GC's moduleRefs) → keep the completion marker outside the worktree (e.g.<target>.donein the cachedir), or delete/refuse a committed marker straight afterworktree addurlKeyis lossy (/a/m_odand/a/m/odgive the same key), so two URLs share one mirror and onefetch:once; a branch can feed tag1.0from its own URL into production's module → add a hash of the full URL to the key (<sanitized>-<sha256[:12]>)forge:/latest:once keys leave out the forge base URL; a branch'sforge 'https://evil'fillsforge/<owner>-<name>-<ver>for every env → put the forge base (hashed) in the dir and once keyscat-file/rev-parserun outsided.limit, so-jdoes not cap git processes (about 3×branches run at once) → put those calls insidelimit, or bound the env fan-out withsemgolang:1.25,almalinux9-gobuilder:20260606,almalinux9-rpmbuilder:latest→artifactapi.k8s.syd1.au.unkin.net/docker-internal/gobuilder:0.1.2-alma9/rpmbuilder:0.1.0-alma9plus the GOCACHE_* env, as in node-lookuplinkmissing between the two renames →renameat2(RENAME_EXCHANGE)the symlink with the dir, then rename the dir asidemodulediras it is at that line, but install uses the finalmoduledir; a latermoduledirlets two mods collide → store the resolved path on the Module when parsing/usr/share/fish/vendor_completions.d/writeAtomicdoesos.WriteFile(target/.g10k-deploy.json.tmp), which follows a symlink the branch committed at that path; a branch with.g10k-deploy.json.tmp -> <basedir>/production/manifests/site.pp(or a path intoforge//modules/) overwrites a live env or a shared cache file with JSON → open the tmp withO_CREATE|O_EXCL|O_NOFOLLOWafter anos.Remove, or write viaos.OpenRoot(target):git => 'http://<host that accepts and never answers>'hangsw10k deployindefinitely while it holds the cachedir flock; no env, production included, can deploy again until someone kills it → wrap each git call in a per-opcontext.WithTimeoutand pass-c http.lowSpeedLimit=1 -c http.lowSpeedTime=60linkmissing between the two renames →renameat2(RENAME_EXCHANGE)the tmp symlink with the dir, then remove the aside dir latermoduleRefsonly scans worktrees of sources that are still configured; if a source is dropped from r10k.yaml, its env links stay in basedir, but GC deletes the modules they use → scan everyworktrees/*dir, not onlyd.Sources()mod 'x', git:/:git =>at EOF:next()consumes tEOF,peek()at :176 indexes past the slice → panic in the deployEnv goroutine kills the whole run (every env + GC) from one branch → bounds-check beforenext()/peek()and return a parse error; add the case to TestParsePuppetfileErrors.:gitaccepts local paths /file://, so any branch can clone any repo readable by the w10k user into its env → run module fetches with-c protocol.file.allow=never(source remotes from r10k.yaml can stay unrestricted).git/<key>.gitmirrors are never collected once no env references the URL; worktrees/state/mirror of a source dropped from r10k.yaml are never collected either → sweep orphan mirrors and source dirs.golangci-lint:latestis unpinned → pin a version.fullis computed per source from the sharedwant, and line 273 empties it. Sow10k deploy productionwith production in the first source runs a full deploy and purge of every later source → work outfullonce inDeployand pass it todeploySource.moduleRefserrors, every mark is kept, including marks on worktrees that went live again this run. If that worktree is unreferenced later, GC deletes it in that same run with no grace → on error, keep only marks undermodules/andforge/(or keep none, which only delays deletion)..g10k-deploy.jsonwhosenameis the first env → leavenameout of the shared marker, or include the env name in the target key.Deployrunsd.GCon a targeted deploy too, sow10k deploy maindeletes past-grace worktrees and modules → run GC only whenlen(only) == 0Liveerror returns before unseen marks are dropped and state is saved; a mark on a worktree that was live in that run survives, and the next run deletes it in the same run that unreferences it → on aLiveerror skip that source's sweep and the module sweep, then drop unseen marks and write state, as themoduleRefserror path does-./sort before_: pushingfeature-xtakes envfeature_xfrom branchfeature_xand bypasses its branch protection → let the branch whose name needs no correction win, and skip corrected branches that collide with itpurgeremoves a live env once a second branch corrects to the same name (feature-xlive, pushfeature.x→feature_xdeleted); "skip" turns into "unpublish" for anyone with push → keep skipped collision names out ofpurge(return them fromEnvironments). Repro: deployfeature-x, add branchfeature.x, redeploy, assertbasedir/feature_xstill exists.forgeLatestdecodes the forge metadata body uncapped, andversionStrhas no length bound: a Puppetfileforgepointing at a server returning a 256 MiBversionis read in full and accepted (err=nil, ~2.6 GB RSS under -race), so one branch can OOM the whole run → wrap the body incapReader(e.g. 1 MiB) and bound the version length.