From 65d762d1cc29d9e502cb7114e9bf497ba39b2a15 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Sat, 2 Aug 2025 23:51:09 +0000 Subject: [PATCH] feat: --health-* options are allowed in job..services..options (#784) they override any similar options from the configuration file since it would not make much sense to define a health check that applies to all containers, it is only ever meaningful for services. ```yaml jobs: mysql: runs-on: ubuntu-latest container: mysql:8 services: maindb: image: mysql:8 env: MYSQL_DATABASE: dbname MYSQL_USER: dbuser MYSQL_PASSWORD: dbpass MYSQL_RANDOM_ROOT_PASSWORD: yes options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 ``` they are also allowed in job..container.options although they are not useful because they are harmless See also the [associated documentation](https://codeberg.org/forgejo/docs/pulls/1366) pull request. --- - features - [PR](https://code.forgejo.org/forgejo/runner/pulls/784): feat: --health-* options are allowed in job..services..options Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/784 Reviewed-by: Gusted Co-authored-by: Earl Warren Co-committed-by: Earl Warren --- act/container/docker_run.go | 5 +++++ act/container/docker_run_test.go | 23 ++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/act/container/docker_run.go b/act/container/docker_run.go index 73672325..1c790d6a 100644 --- a/act/container/docker_run.go +++ b/act/container/docker_run.go @@ -412,6 +412,11 @@ func (cr *containerReference) mergeJobOptions(ctx context.Context, config *conta logger := common.Logger(ctx) + if jobConfig.Config.Healthcheck != nil && len(jobConfig.Config.Healthcheck.Test) > 0 { + logger.Debugf("--health-* options %+v", jobConfig.Config.Healthcheck) + config.Healthcheck = jobConfig.Config.Healthcheck + } + if len(jobConfig.Config.Volumes) > 0 { logger.Debugf("--volume options (except bind) %v", jobConfig.Config.Volumes) err = mergo.Merge(&config.Volumes, jobConfig.Config.Volumes, mergo.WithOverride, mergo.WithAppendSlice) diff --git a/act/container/docker_run_test.go b/act/container/docker_run_test.go index 53a812f6..1069f895 100644 --- a/act/container/docker_run_test.go +++ b/act/container/docker_run_test.go @@ -338,11 +338,18 @@ func TestMergeJobOptions(t *testing.T) { hostConfig *container.HostConfig }{ { - name: "ok", - options: "--volume /frob:/nitz --volume somevolume --tmpfs /tmp:exec,noatime --hostname alternatehost", + name: "Ok", + options: `--volume /frob:/nitz --volume somevolume --tmpfs /tmp:exec,noatime --hostname alternatehost --health-cmd "healthz one" --health-interval 10s --health-timeout 5s --health-retries 3 --health-start-period 30s`, config: &container.Config{ Volumes: map[string]struct{}{"somevolume": {}}, Hostname: "alternatehost", + Healthcheck: &container.HealthConfig{ + Test: []string{"CMD-SHELL", "healthz one"}, + Interval: 10 * time.Second, + Timeout: 5 * time.Second, + StartPeriod: 30 * time.Second, + Retries: 3, + }, }, hostConfig: &container.HostConfig{ Binds: []string{"/frob:/nitz"}, @@ -350,7 +357,17 @@ func TestMergeJobOptions(t *testing.T) { }, }, { - name: "ignore", + name: "DisableHealthCheck", + options: `--no-healthcheck`, + config: &container.Config{ + Healthcheck: &container.HealthConfig{ + Test: []string{"NONE"}, + }, + }, + hostConfig: &container.HostConfig{}, + }, + { + name: "Ignore", options: "--pid=host --device=/dev/sda", config: &container.Config{}, hostConfig: &container.HostConfig{},