1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-05 18:40:59 +00:00

chore: refactor GetBindsAndMounts to have a context.Context arg

This commit is contained in:
Earl Warren 2025-08-14 10:08:50 +02:00
parent 159c6af0dd
commit f392ec4caa
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
4 changed files with 6 additions and 6 deletions

View file

@ -428,7 +428,7 @@ func newStepContainer(ctx context.Context, step step, image string, cmd, entrypo
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_ARCH", container.RunnerArch(ctx)))
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TEMP", "/tmp"))
binds, mounts, validVolumes := rc.GetBindsAndMounts()
binds, mounts, validVolumes := rc.GetBindsAndMounts(ctx)
networkMode := fmt.Sprintf("container:%s", rc.jobContainerName())
if rc.IsHostEnv(ctx) {
networkMode = "default"

View file

@ -124,7 +124,7 @@ func getDockerDaemonSocketMountPath(daemonPath string) string {
}
// Returns the binds and mounts for the container, resolving paths as appopriate
func (rc *RunContext) GetBindsAndMounts() ([]string, map[string]string, []string) {
func (rc *RunContext) GetBindsAndMounts(ctx context.Context) ([]string, map[string]string, []string) {
name := rc.jobContainerName()
if rc.Config.ContainerDaemonSocket == "" {
@ -443,7 +443,7 @@ func (rc *RunContext) prepareJobContainer(ctx context.Context) error {
envList = append(envList, fmt.Sprintf("%s=%s", "LANG", "C.UTF-8")) // Use same locale as GitHub Actions
ext := container.LinuxContainerEnvironmentExtensions{}
binds, mounts, validVolumes := rc.GetBindsAndMounts()
binds, mounts, validVolumes := rc.GetBindsAndMounts(ctx)
networkName, createAndDeleteNetwork := rc.getNetworkName(ctx)
// add service containers

View file

@ -219,7 +219,7 @@ func TestRunContext_GetBindsAndMounts(t *testing.T) {
config := testcase.rc.Config
config.Workdir = testcase.name
config.BindWorkdir = bindWorkDir
gotbind, gotmount, _ := rctemplate.GetBindsAndMounts()
gotbind, gotmount, _ := rctemplate.GetBindsAndMounts(t.Context())
// Name binds/mounts are either/or
if config.BindWorkdir {
@ -271,7 +271,7 @@ func TestRunContext_GetBindsAndMounts(t *testing.T) {
rc.Run.JobID = "job1"
rc.Run.Workflow.Jobs = map[string]*model.Job{"job1": job}
gotbind, gotmount, _ := rc.GetBindsAndMounts()
gotbind, gotmount, _ := rc.GetBindsAndMounts(t.Context())
if len(testcase.wantbind) > 0 {
assert.Contains(t, gotbind, testcase.wantbind)

View file

@ -110,7 +110,7 @@ func (sd *stepDocker) newStepContainer(ctx context.Context, image string, cmd, e
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_ARCH", container.RunnerArch(ctx)))
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TEMP", "/tmp"))
binds, mounts, validVolumes := rc.GetBindsAndMounts()
binds, mounts, validVolumes := rc.GetBindsAndMounts(ctx)
stepContainer := ContainerNewContainer(&container.NewContainerInput{
Cmd: cmd,
Entrypoint: entrypoint,