mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-15 18:57:01 +00:00
feat: --health-* options are allowed in job.<id>.services.<id>.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.<id>.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. --- <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - features - [PR](https://code.forgejo.org/forgejo/runner/pulls/784): <!--number 784 --><!--line 0 --><!--description ZmVhdDogLS1oZWFsdGgtKiBvcHRpb25zIGFyZSBhbGxvd2VkIGluIGpvYi48aWQ+LnNlcnZpY2VzLjxpZD4ub3B0aW9ucw==-->feat: --health-* options are allowed in job.<id>.services.<id>.options<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/784 Reviewed-by: Gusted <gusted@noreply.code.forgejo.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
parent
6bff61dd7a
commit
65d762d1cc
2 changed files with 25 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -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{},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue