From 09de42f067404a2f9dd904f3620812bf40a562bb Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Tue, 14 Mar 2023 19:37:31 +0530 Subject: [PATCH] Support for docker steps in host environment (#1674) * Support for docker steps in host environment * removed workdir changes --- pkg/runner/action.go | 7 +++++-- pkg/runner/run_context.go | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/runner/action.go b/pkg/runner/action.go index f871653..a534170 100644 --- a/pkg/runner/action.go +++ b/pkg/runner/action.go @@ -356,7 +356,10 @@ func newStepContainer(ctx context.Context, step step, image string, cmd []string envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TEMP", "/tmp")) binds, mounts := rc.GetBindsAndMounts() - + networkMode := fmt.Sprintf("container:%s", rc.jobContainerName()) + if rc.IsHostEnv(ctx) { + networkMode = "default" + } stepContainer := container.NewContainer(&container.NewContainerInput{ Cmd: cmd, Entrypoint: entrypoint, @@ -367,7 +370,7 @@ func newStepContainer(ctx context.Context, step step, image string, cmd []string Name: createContainerName(rc.jobContainerName(), stepModel.ID), Env: envList, Mounts: mounts, - NetworkMode: fmt.Sprintf("container:%s", rc.jobContainerName()), + NetworkMode: networkMode, Binds: binds, Stdout: logWriter, Stderr: logWriter, diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index dd082fd..27bbe87 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -384,14 +384,18 @@ func (rc *RunContext) interpolateOutputs() common.Executor { func (rc *RunContext) startContainer() common.Executor { return func(ctx context.Context) error { - image := rc.platformImage(ctx) - if strings.EqualFold(image, "-self-hosted") { + if rc.IsHostEnv(ctx) { return rc.startHostEnvironment()(ctx) } return rc.startJobContainer()(ctx) } } +func (rc *RunContext) IsHostEnv(ctx context.Context) bool { + image := rc.platformImage(ctx) + return strings.EqualFold(image, "-self-hosted") +} + func (rc *RunContext) stopContainer() common.Executor { return rc.stopJobContainer() }