From aa3a16d271ede5bbba5acadbc7c67a46ce721106 Mon Sep 17 00:00:00 2001 From: Louis Auzuret <46396559+GitBluub@users.noreply.github.com> Date: Wed, 5 Jun 2024 21:16:34 +0200 Subject: [PATCH] fix: skip service container for empty image (#2281) * fix: skip service container for empty image It is used to skip empty image name in services which is the only way to handle condition services in github action currently https://github.com/actions/runner/issues/822 * test: add testdata for empty image in services * fix: add missing test call * fix: wring test call * fix: invalid without expression --------- Co-authored-by: ChristopherHX --- pkg/runner/run_context.go | 8 +++++- pkg/runner/runner_test.go | 1 + .../testdata/services-empty-image/push.yaml | 26 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 pkg/runner/testdata/services-empty-image/push.yaml diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index edb82e11..85626a42 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -342,11 +342,17 @@ func (rc *RunContext) startJobContainer() common.Executor { return fmt.Errorf("failed to parse service %s ports: %w", serviceID, err) } + imageName := rc.ExprEval.Interpolate(ctx, spec.Image) + if imageName == "" { + logger.Infof("The service '%s' will not be started because the container definition has an empty image.", serviceID) + continue + } + serviceContainerName := createContainerName(rc.jobContainerName(), serviceID) c := container.NewContainer(&container.NewContainerInput{ Name: serviceContainerName, WorkingDir: ext.ToContainerPath(rc.Config.Workdir), - Image: rc.ExprEval.Interpolate(ctx, spec.Image), + Image: imageName, Username: username, Password: password, Cmd: interpolatedCmd, diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index 68db3fbc..48b27b2e 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -314,6 +314,7 @@ func TestRunEvent(t *testing.T) { // services {workdir, "services", "push", "", platforms, secrets}, + {workdir, "services-empty-image", "push", "", platforms, secrets}, {workdir, "services-host-network", "push", "", platforms, secrets}, {workdir, "services-with-container", "push", "", platforms, secrets}, diff --git a/pkg/runner/testdata/services-empty-image/push.yaml b/pkg/runner/testdata/services-empty-image/push.yaml new file mode 100644 index 00000000..4e9ea1fd --- /dev/null +++ b/pkg/runner/testdata/services-empty-image/push.yaml @@ -0,0 +1,26 @@ +name: services +on: push +jobs: + services: + name: Reproduction of failing Services interpolation + runs-on: ubuntu-latest + services: + postgres: + image: ${{ false || '' }} + env: + POSTGRES_USER: runner + POSTGRES_PASSWORD: mysecretdbpass + POSTGRES_DB: mydb + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + steps: + - name: Echo the Postgres service ID / Network / Ports + run: | + echo "id: ${{ job.services.postgres.id }}" + echo "network: ${{ job.services.postgres.network }}" + echo "ports: ${{ job.services.postgres.ports }}"