diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 6bc627b..925ebc6 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -310,11 +310,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, Env: envs, diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index dcd03db..13e6844 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 0000000..4e9ea1f --- /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 }}"