From a1bb40e00d58a55c512bad290bcb41e929f7a8f1 Mon Sep 17 00:00:00 2001 From: Arumugam J Date: Tue, 26 Sep 2023 10:20:36 -0400 Subject: [PATCH] Add option in `job-run` config to set the container hostname --- core/runjob.go | 2 ++ core/runjob_test.go | 2 ++ docs/jobs.md | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/core/runjob.go b/core/runjob.go index 09b25ebb..35ed80b6 100644 --- a/core/runjob.go +++ b/core/runjob.go @@ -31,6 +31,7 @@ type RunJob struct { Image string Network string + Hostname string Container string Volume []string Environment []string @@ -171,6 +172,7 @@ func (j *RunJob) buildContainer() (*docker.Container, error) { Cmd: args.GetArgs(j.Command), User: j.User, Env: j.Environment, + Hostname: j.Hostname, }, NetworkingConfig: &docker.NetworkingConfig{}, HostConfig: &docker.HostConfig{ diff --git a/core/runjob_test.go b/core/runjob_test.go index 0395f088..802d0feb 100644 --- a/core/runjob_test.go +++ b/core/runjob_test.go @@ -40,6 +40,7 @@ func (s *SuiteRunJob) TestRun(c *C) { job.TTY = true job.Delete = "true" job.Network = "foo" + job.Hostname = "test-host" job.Name = "test" job.Environment = []string{"test_Key1=value1", "test_Key2=value2"} job.Volume = []string{"/test/tmp:/test/tmp:ro", "/test/tmp:/test/tmp:rw"} @@ -68,6 +69,7 @@ func (s *SuiteRunJob) TestRun(c *C) { c.Assert(container.Config.Env, DeepEquals, job.Environment) // this doesn't seem to be working with DockerTestServer + // c.Assert(container.Config.Hostname, Equals, job.Hostname) // c.Assert(container.HostConfig.Binds, DeepEquals, job.Volume) // stop container, we don't need it anymore diff --git a/docs/jobs.md b/docs/jobs.md index d4bf0bd3..1386d00f 100644 --- a/docs/jobs.md +++ b/docs/jobs.md @@ -92,6 +92,10 @@ This job can be used in 2 situations: - *description*: Connect the container to this network - *value*: String, e.g. `backend-proxy` - *default*: Optional field, no default. +- **Hostname** (1) + - *description*: Define the hostname of the instantiated container + - *value*: String, e.g. `test-server` + - *default*: Optional field, no default. - **Delete** (1) - *description*: Delete the container after the job is finished. Similar to `docker run --rm` - *value*: Boolean, either `true` or `false`