Commit 6bea6f3df8
Verified · cmc ci/build: success ci/test: success
Layout: unified · split
cmd/gitbay-runner/env_test.go +11
| @@ -105,3 +105,14 @@ func TestPodmanUsesCgroupfs(t *testing.T) { | |||
| 105 | t.Errorf("podmanGlobal() = %v, missing the cgroupfs manager", got) | 105 | t.Errorf("podmanGlobal() = %v, missing the cgroupfs manager", got) |
| 106 | } | 106 | } |
| 107 | } | 107 | } |
| 108 | |||
| 109 | // The build home is where caches live, so the container must see it at | ||
| 110 | // the path HOME names; otherwise every containerised build starts cold. | ||
| 111 | func TestEnvHomeFindsHome(t *testing.T) { | ||
| 112 | if got := envHome([]string{"PATH=/bin", "HOME=/var/lib/gitbay-runner/work/home", "CI=true"}); got != "/var/lib/gitbay-runner/work/home" { | ||
| 113 | t.Errorf("envHome = %q", got) | ||
| 114 | } | ||
| 115 | if got := envHome([]string{"PATH=/bin"}); got != "" { | ||
| 116 | t.Errorf("envHome with no HOME = %q, want empty", got) | ||
| 117 | } | ||
| 118 | } | ||
cmd/gitbay-runner/isolate.go +16
| @@ -130,6 +130,12 @@ func (r *runner) runStepsPodman(j job, dir string, env []string, sink io.Writer, | |||
| 130 | "--name", name, | 130 | "--name", name, |
| 131 | "--env-file", envFile, | 131 | "--env-file", envFile, |
| 132 | "--volume", dir+":/workspace:rw", | 132 | "--volume", dir+":/workspace:rw", |
| 133 | // The build home holds the tool caches (Go modules, the sonar | ||
| 134 | // scanner) that must outlive a build; HOME in env points at it. | ||
| 135 | // Mounted at the same path so HOME resolves identically with and | ||
| 136 | // without a container. Only this directory — never the workdir | ||
| 137 | // above it, which holds other builds' workspaces. | ||
| 138 | "--volume", envHome(env)+":"+envHome(env)+":rw", | ||
| 133 | "--workdir", "/workspace", | 139 | "--workdir", "/workspace", |
| 134 | "--entrypoint", "sh", | 140 | "--entrypoint", "sh", |
| 135 | image, "-c", "sleep infinity")...) | 141 | image, "-c", "sleep infinity")...) |
| @@ -181,6 +187,16 @@ func (r *runner) podmanGlobal() []string { | |||
| 181 | return []string{"--cgroup-manager=cgroupfs"} | 187 | return []string{"--cgroup-manager=cgroupfs"} |
| 182 | } | 188 | } |
| 183 | 189 | ||
| 190 | // env_home returns the HOME the step environment carries. | ||
| 191 | func envHome(env []string) string { | ||
| 192 | for _, e := range env { | ||
| 193 | if strings.HasPrefix(e, "HOME=") { | ||
| 194 | return strings.TrimPrefix(e, "HOME=") | ||
| 195 | } | ||
| 196 | } | ||
| 197 | return "" | ||
| 198 | } | ||
| 199 | |||
| 184 | // podmanHome is where podman keeps its own storage: the runner's home, | 200 | // podmanHome is where podman keeps its own storage: the runner's home, |
| 185 | // not a build's. The container store is the runner's business, and a | 201 | // not a build's. The container store is the runner's business, and a |
| 186 | // build never sees this path. | 202 | // build never sees this path. |