From d92e4a8aff935896a0459c1aacef20fb03354bbd Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 22 Jan 2025 18:22:29 +0000 Subject: [PATCH] feat: --hostname is allowed in container options (#95) It is useful to set an alternative hostname when running a service such as: ```yaml services: minio: image: data.forgejo.org/oci/bitnami/minio:2024.8.17 options: >- --hostname alternate.minio ``` Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/95 Reviewed-by: Kwonunn Co-authored-by: Earl Warren Co-committed-by: Earl Warren --- act/container/docker_run.go | 5 +++++ act/container/docker_run_test.go | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/act/container/docker_run.go b/act/container/docker_run.go index 4f606a24..d7f54d35 100644 --- a/act/container/docker_run.go +++ b/act/container/docker_run.go @@ -435,6 +435,11 @@ func (cr *containerReference) mergeJobOptions(ctx context.Context, config *conta } } + if len(jobConfig.Config.Hostname) > 0 { + logger.Debugf("--hostname %v", jobConfig.Config.Hostname) + config.Hostname = jobConfig.Config.Hostname + } + return config, hostConfig, nil } diff --git a/act/container/docker_run_test.go b/act/container/docker_run_test.go index 368a5627..6b47ef6f 100644 --- a/act/container/docker_run_test.go +++ b/act/container/docker_run_test.go @@ -258,9 +258,10 @@ func TestMergeJobOptions(t *testing.T) { }{ { name: "ok", - options: "--volume /foo:/bar --volume /frob:/nitz --volume somevolume --tmpfs /tmp:exec,noatime", + options: "--volume /foo:/bar --volume /frob:/nitz --volume somevolume --tmpfs /tmp:exec,noatime --hostname alternatehost", config: &container.Config{ - Volumes: map[string]struct{}{"somevolume": {}}, + Volumes: map[string]struct{}{"somevolume": {}}, + Hostname: "alternatehost", }, hostConfig: &container.HostConfig{ Binds: []string{"/foo:/bar", "/frob:/nitz"},