Skip to content

Commit

Permalink
fix: skip service container for empty image (#2281)
Browse files Browse the repository at this point in the history
* 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 actions/runner#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 <[email protected]>
  • Loading branch information
2 people authored and chhe committed Nov 1, 2024
1 parent 42acd7d commit aa3a16d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/runner/run_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions pkg/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},

Expand Down
26 changes: 26 additions & 0 deletions pkg/runner/testdata/services-empty-image/push.yaml
Original file line number Diff line number Diff line change
@@ -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 }}"

0 comments on commit aa3a16d

Please sign in to comment.