From 143676fcfb1daeb3d9f5c365a5141077a804bd40 Mon Sep 17 00:00:00 2001 From: Casey Lee Date: Mon, 9 Mar 2020 17:43:24 -0700 Subject: [PATCH] fix #141 - use host network to match GitHub Actions runners (#142) --- pkg/container/docker_run.go | 26 +++++++++++++------------ pkg/runner/run_context.go | 8 ++++---- pkg/runner/step_context.go | 7 ++++--- pkg/runner/testdata/issue-141/main.yaml | 13 +++++++++++++ 4 files changed, 35 insertions(+), 19 deletions(-) create mode 100644 pkg/runner/testdata/issue-141/main.yaml diff --git a/pkg/container/docker_run.go b/pkg/container/docker_run.go index 1ed52e0c..639d94b9 100644 --- a/pkg/container/docker_run.go +++ b/pkg/container/docker_run.go @@ -24,16 +24,17 @@ import ( // NewContainerInput the input for the New function type NewContainerInput struct { - Image string - Entrypoint []string - Cmd []string - WorkingDir string - Env []string - Binds []string - Mounts map[string]string - Name string - Stdout io.Writer - Stderr io.Writer + Image string + Entrypoint []string + Cmd []string + WorkingDir string + Env []string + Binds []string + Mounts map[string]string + Name string + Stdout io.Writer + Stderr io.Writer + NetworkMode string } // FileEntry is a file to copy to a container @@ -221,8 +222,9 @@ func (cr *containerReference) create() common.Executor { } resp, err := cr.cli.ContainerCreate(ctx, config, &container.HostConfig{ - Binds: input.Binds, - Mounts: mounts, + Binds: input.Binds, + Mounts: mounts, + NetworkMode: container.NetworkMode(input.NetworkMode), }, nil, input.Name) if err != nil { return errors.WithStack(err) diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 260af163..d3c72441 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -107,10 +107,10 @@ func (rc *RunContext) startJobContainer() common.Executor { "act-toolcache": "/toolcache", "act-actions": "/actions", }, - - Binds: binds, - Stdout: logWriter, - Stderr: logWriter, + NetworkMode: "host", + Binds: binds, + Stdout: logWriter, + Stderr: logWriter, }) return common.NewPipelineExecutor( diff --git a/pkg/runner/step_context.go b/pkg/runner/step_context.go index fbd13d7c..fabcca3e 100644 --- a/pkg/runner/step_context.go +++ b/pkg/runner/step_context.go @@ -177,9 +177,10 @@ func (sc *StepContext) newStepContainer(ctx context.Context, image string, cmd [ "act-toolcache": "/toolcache", "act-actions": "/actions", }, - Binds: binds, - Stdout: logWriter, - Stderr: logWriter, + NetworkMode: fmt.Sprintf("container:%s", rc.jobContainerName()), + Binds: binds, + Stdout: logWriter, + Stderr: logWriter, }) return stepContainer } diff --git a/pkg/runner/testdata/issue-141/main.yaml b/pkg/runner/testdata/issue-141/main.yaml new file mode 100644 index 00000000..d1f50c33 --- /dev/null +++ b/pkg/runner/testdata/issue-141/main.yaml @@ -0,0 +1,13 @@ +name: "Create cluster using KinD" +on: push + +jobs: + kind: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: engineerd/setup-kind@v0.3.0 + - name: Testing + run: | + kubectl cluster-info + kubectl get pods -n kube-system