vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Bound the runner's image storage by age
3455902aa415e013b0e5525e3fd2271a2b1a4e9a · Keenan Nemetz · 3d ago · parent 1a9b3838
Bound the runner's image storage by age The job cache and saved checkouts have caps, but image storage belonged to the runtime and grew two ways: a changed `.vole/images` definition left a permanent new digest tag behind, and a moved registry tag left the previous layers dangling. `--disk-reserve` could not reclaim either; it stops a job instead. Add `--image-max-age` (default 168h; 0 keeps every image), threaded through agent.Options. At startup and on the cache trimmer's beat the runner asks the runtime to prune unused images older than the age, using the filter docker, podman, and nerdctl all express. A job holds an image guard from resolution until its container is up, so a pass that races a lease gives way. A runner with `--container-pull never` keeps every tagged image and prunes dangling layers only, because it may have no network to fetch an evicted image again. A runtime that will not prune is reported once and then left alone: the runner keeps serving. The primitive lives in ci/container so `vole workflow run` can use it later; the policy and its beat live in ci/agent beside the two existing trimmers. closes: 01M8CR0RN88JF14PKAZ0D387ND
ci/agent/agent.go +33
| @@ -315,6 +315,14 @@ type Options struct { | |||
| 315 | 315 | // again, so the cap trades disk for network. Negative means the default, and zero | |
| 316 | 316 | // keeps every checkout; see DefaultGitCacheBytes and gitcache.go. | |
| 317 | 317 | GitCacheMaxBytes int64 | |
| 318 | |||
| 319 | // ImageMaxAge bounds the OCI runtime's image storage by age. Images no container | ||
| 320 | // uses that are older than this are pruned at startup and on the cache trimmer's | ||
| 321 | // beat; zero keeps every image. Image sizes are not Vole's to count — layers are | ||
| 322 | // shared — so the runtime's own age filter is the unit. With ContainerPull | ||
| 323 | // "never", tagged images are kept and only dangling layers are pruned, because | ||
| 324 | // an offline runner cannot fetch an evicted image again. | ||
| 325 | ImageMaxAge time.Duration | ||
| 318 | 326 | } | |
| 319 | 327 | ||
| 320 | 328 | // Run leases and executes CI jobs until the context ends, a slot is told to stop, | |
| @@ -372,6 +380,18 @@ func Run(ctx context.Context, opts Options) error { | |||
| 372 | 380 | gitCacheMax = DefaultGitCacheBytes | |
| 373 | 381 | } | |
| 374 | 382 | maintainTrustedCaches(cache, gitCacheMax, "") | |
| 383 | // Image storage lives in the runtime, not under cache, so it is bounded through | ||
| 384 | // the runtime's own prune. Do it before the first lease for the reason the caches | ||
| 385 | // above are bounded here: a host that filled up while nobody was watching should | ||
| 386 | // reclaim before it fails a job, not after. | ||
| 387 | imageTrim := newImageTrimmer(box, opts.ImageMaxAge) | ||
| 388 | if imageTrim.enabled() { | ||
| 389 | if box.Pull == "never" { | ||
| 390 | fmt.Fprintln(os.Stderr, "vole runner: --container-pull never keeps every tagged image; pruning dangling layers only") | ||
| 391 | } | ||
| 392 | imageTrim.trim(ctx, box) | ||
| 393 | go imageTrim.loop(ctx, box) | ||
| 394 | } | ||
| 375 | 395 | ||
| 376 | 396 | // The directory is mounted whether or not it is reused: an image that sets | |
| 377 | 397 | // GOCACHE=/cache/go-build must work under --no-cache too, and a non-root job | |
| @@ -988,6 +1008,16 @@ func (s *runnerSession) run(remote, cache string, job *runnerJob, lease time.Dur | |||
| 988 | 1008 | fmt.Fprintf(log, "vole: %s is not set for this repository, so this job runs without it.\n", issue.Name) | |
| 989 | 1009 | } | |
| 990 | 1010 | ||
| 1011 | // Hold the image in use from before it is resolved until the job container is | ||
| 1012 | // up: a prune pass takes the same guard exclusively, so a tag this job is about to | ||
| 1013 | // run cannot disappear between the two. A running container already protects its | ||
| 1014 | // image from the runtime's own prune; this closes the gap before one exists. | ||
| 1015 | releaseImages := box.images.hold() | ||
| 1016 | defer func() { | ||
| 1017 | if releaseImages != nil { | ||
| 1018 | releaseImages() | ||
| 1019 | } | ||
| 1020 | }() | ||
| 991 | 1021 | image, err := s.resolveImage(job, box, log, lease) | |
| 992 | 1022 | if err != nil { | |
| 993 | 1023 | if errors.Is(err, errLeaseLost) { | |
| @@ -1139,6 +1169,9 @@ func (s *runnerSession) run(remote, cache string, job *runnerJob, lease time.Dur | |||
| 1139 | 1169 | return | |
| 1140 | 1170 | } | |
| 1141 | 1171 | jobBox.job = sandbox | |
| 1172 | // The container now holds the image itself, so the prune pass may run again. | ||
| 1173 | releaseImages() | ||
| 1174 | releaseImages = nil | ||
| 1142 | 1175 | ||
| 1143 | 1176 | steps = make([]runs.StepResult, 0, len(job.Steps)) | |
| 1144 | 1177 | // The job's budget starts with its first step. An image build has its own cap, so a | |