mirror of
https://github.com/nektos/act.git
synced 2024-10-03 23:47:41 +03:00
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 <christopher.homberger@web.de>
This commit is contained in:
parent
b5ad3c4acd
commit
e4607fc791
@ -310,11 +310,17 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
|||||||
return fmt.Errorf("failed to parse service %s ports: %w", serviceID, err)
|
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)
|
serviceContainerName := createContainerName(rc.jobContainerName(), serviceID)
|
||||||
c := container.NewContainer(&container.NewContainerInput{
|
c := container.NewContainer(&container.NewContainerInput{
|
||||||
Name: serviceContainerName,
|
Name: serviceContainerName,
|
||||||
WorkingDir: ext.ToContainerPath(rc.Config.Workdir),
|
WorkingDir: ext.ToContainerPath(rc.Config.Workdir),
|
||||||
Image: rc.ExprEval.Interpolate(ctx, spec.Image),
|
Image: imageName,
|
||||||
Username: username,
|
Username: username,
|
||||||
Password: password,
|
Password: password,
|
||||||
Env: envs,
|
Env: envs,
|
||||||
|
@ -314,6 +314,7 @@ func TestRunEvent(t *testing.T) {
|
|||||||
|
|
||||||
// services
|
// services
|
||||||
{workdir, "services", "push", "", platforms, secrets},
|
{workdir, "services", "push", "", platforms, secrets},
|
||||||
|
{workdir, "services-empty-image", "push", "", platforms, secrets},
|
||||||
{workdir, "services-host-network", "push", "", platforms, secrets},
|
{workdir, "services-host-network", "push", "", platforms, secrets},
|
||||||
{workdir, "services-with-container", "push", "", platforms, secrets},
|
{workdir, "services-with-container", "push", "", platforms, secrets},
|
||||||
|
|
||||||
|
26
pkg/runner/testdata/services-empty-image/push.yaml
vendored
Normal file
26
pkg/runner/testdata/services-empty-image/push.yaml
vendored
Normal file
@ -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 }}"
|
Loading…
Reference in New Issue
Block a user