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.
Put job execution behind an interface
de3eec162f93a697575c8bc756bd496fe4020376 · Keenan Nemetz · 2h ago · parent f784d769
Put job execution behind an interface Job execution was container-shaped all the way into the runner: ci/agent created the network, started the services and the job container, and held *container.Container and *container.Network values directly, and `vole workflow run` kept its own copy of the same orchestration. The only abstraction was Config.Runtime, a string naming one of three flag-compatible CLIs, which is enough for docker, podman and nerdctl and nothing else. ci/execute is that seam. An Executor prepares the job's image, starts its environment, runs one step while the caller keeps the lease alive, stops it, reclaims what a killed runner left behind, and bounds its own storage. A Sandbox is one job's environment: the job, the services beside it, and the network they share. Capabilities is what a backend can honour, so a job that asks for a network or for services is refused before it starts rather than quietly given less. ci/container implements it and takes over the orchestration that was in ci/agent and cmd/vole: the per-attempt network, the service containers and their log collection, the stale-container and stale-network reclamation, and the image build and prune coordination. The isolation flags are unchanged. This is the boundary a virtual-machine backend needs: a macOS guest behind Tart (#356), a Windows guest, or a Linux microVM disagree with a container about pids limits, user namespaces, tmpfs, capabilities and mounts, so they cannot be expressed as another runtime string. Nothing about the image or workflow schema changes here. closes: 01M8Z2M9PVKPNH923S3VJ5FR5E
ci/agent/images.go +13−53
| @@ -23,79 +23,39 @@ import ( | |||
| 23 | 23 | "sync" | |
| 24 | 24 | "time" | |
| 25 | 25 | ||
| 26 | "rodent.software/vole/ci/container" | ||
| 26 | "rodent.software/vole/ci/execute" | ||
| 27 | 27 | "rodent.software/vole/internal/format" | |
| 28 | 28 | ) | |
| 29 | 29 | ||
| 30 | // imageUse is the boundary between a job acquiring an image and a prune pass. | ||
| 31 | // A job holds it from before the image is resolved (which may build it) until the | ||
| 32 | // job container is up; a prune takes it exclusively, so a tag cannot disappear | ||
| 33 | // between the resolve and the start. | ||
| 34 | type imageUse struct { | ||
| 35 | mu sync.RWMutex | ||
| 36 | } | ||
| 37 | |||
| 38 | // hold marks an image as in use and returns the release. A nil guard means the | ||
| 39 | // caller never asked for one (a hand-built runnerBox in a test), so holding and | ||
| 40 | // releasing are no-ops rather than a panic. | ||
| 41 | func (u *imageUse) hold() func() { | ||
| 42 | if u == nil { | ||
| 43 | return func() {} | ||
| 44 | } | ||
| 45 | u.mu.RLock() | ||
| 46 | return u.mu.RUnlock | ||
| 47 | } | ||
| 48 | |||
| 49 | // exclusive takes the guard for a prune pass. It does not wait: a job that is | ||
| 50 | // building or starting an image may hold it for minutes, and a trimmer that | ||
| 51 | // blocked a pass would be a goroutine waiting on a build rather than a runner | ||
| 52 | // doing work. A skipped pass costs nothing; the next beat tries again. | ||
| 53 | func (u *imageUse) exclusive() (func(), bool) { | ||
| 54 | if u == nil { | ||
| 55 | return func() {}, true | ||
| 56 | } | ||
| 57 | if !u.mu.TryLock() { | ||
| 58 | return nil, false | ||
| 59 | } | ||
| 60 | return u.mu.Unlock, true | ||
| 61 | } | ||
| 62 | |||
| 63 | 30 | // imageTrimmer applies the age policy on the cache trimmer's beat. stopped is set | |
| 64 | // after a runtime refuses: one line explains the state, and later passes stay | ||
| 31 | // after a backend refuses: one line explains the state, and later passes stay | ||
| 65 | 32 | // quiet instead of repeating it every five minutes. | |
| 33 | // | ||
| 34 | // The policy itself belongs to the executor: what "an image" is, how to measure the | ||
| 35 | // space it takes, and whether removing one is even possible are all properties of | ||
| 36 | // the backend. All this keeps is the beat and the once-only complaint. | ||
| 66 | 37 | type imageTrimmer struct { | |
| 38 | exec execute.Executor | ||
| 67 | 39 | age time.Duration | |
| 68 | all bool | ||
| 69 | 40 | mu sync.Mutex | |
| 70 | 41 | stopped bool | |
| 71 | 42 | } | |
| 72 | 43 | ||
| 73 | func newImageTrimmer(box runnerBox, age time.Duration) *imageTrimmer { | ||
| 74 | return &imageTrimmer{ | ||
| 75 | age: age, | ||
| 76 | // --container-pull never means this runner may have no network to fetch an | ||
| 77 | // image again, so every tagged image is kept. Dangling layers are still | ||
| 78 | // unreachable by any tag or container and are safe to reclaim. | ||
| 79 | all: box.Pull != "never", | ||
| 80 | } | ||
| 44 | func newImageTrimmer(exec execute.Executor, age time.Duration) *imageTrimmer { | ||
| 45 | return &imageTrimmer{exec: exec, age: age} | ||
| 81 | 46 | } | |
| 82 | 47 | ||
| 83 | 48 | func (t *imageTrimmer) enabled() bool { | |
| 84 | 49 | return t != nil && t.age > 0 | |
| 85 | 50 | } | |
| 86 | 51 | ||
| 87 | func (t *imageTrimmer) trim(ctx context.Context, box runnerBox) { | ||
| 52 | func (t *imageTrimmer) trim(ctx context.Context) { | ||
| 88 | 53 | t.mu.Lock() | |
| 89 | 54 | defer t.mu.Unlock() | |
| 90 | 55 | if t.stopped { | |
| 91 | 56 | return | |
| 92 | 57 | } | |
| 93 | release, ok := box.images.exclusive() | ||
| 94 | if !ok { | ||
| 95 | return // a job is resolving or starting an image; the next pass tries again | ||
| 96 | } | ||
| 97 | defer release() | ||
| 98 | removed, err := container.PruneImages(ctx, box.Config, t.age, t.all) | ||
| 58 | removed, err := t.exec.Prune(ctx, t.age) | ||
| 99 | 59 | if err != nil { | |
| 100 | 60 | fmt.Fprintf(os.Stderr, "vole runner: not pruning images: %v\n", err) | |
| 101 | 61 | t.stopped = true | |
| @@ -106,7 +66,7 @@ func (t *imageTrimmer) trim(ctx context.Context, box runnerBox) { | |||
| 106 | 66 | } | |
| 107 | 67 | } | |
| 108 | 68 | ||
| 109 | func (t *imageTrimmer) loop(ctx context.Context, box runnerBox) { | ||
| 69 | func (t *imageTrimmer) loop(ctx context.Context) { | ||
| 110 | 70 | ticker := time.NewTicker(cacheTrimInterval) | |
| 111 | 71 | defer ticker.Stop() | |
| 112 | 72 | for { | |
| @@ -114,7 +74,7 @@ func (t *imageTrimmer) loop(ctx context.Context, box runnerBox) { | |||
| 114 | 74 | case <-ctx.Done(): | |
| 115 | 75 | return | |
| 116 | 76 | case <-ticker.C: | |
| 117 | t.trim(ctx, box) | ||
| 77 | t.trim(ctx) | ||
| 118 | 78 | } | |
| 119 | 79 | } | |
| 120 | 80 | } | |