mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-29 21:31:02 +00:00
Add hostname in docker section of .drone.yml
This commit is contained in:
parent
7e2b03e20f
commit
78b8b7dd75
3 changed files with 45 additions and 0 deletions
|
@ -319,6 +319,7 @@ func (b *Builder) teardown() error {
|
||||||
func (b *Builder) run() error {
|
func (b *Builder) run() error {
|
||||||
// create and run the container
|
// create and run the container
|
||||||
conf := docker.Config{
|
conf := docker.Config{
|
||||||
|
Hostname: script.DockerHostname(b.Build.Docker),
|
||||||
Image: b.image.ID,
|
Image: b.image.ID,
|
||||||
AttachStdin: false,
|
AttachStdin: false,
|
||||||
AttachStdout: true,
|
AttachStdout: true,
|
||||||
|
|
|
@ -10,6 +10,10 @@ type Docker struct {
|
||||||
// NetworkMode (also known as `--net` option)
|
// NetworkMode (also known as `--net` option)
|
||||||
// Could be set only if Docker is running in privileged mode
|
// Could be set only if Docker is running in privileged mode
|
||||||
NetworkMode *string `yaml:"net,omitempty"`
|
NetworkMode *string `yaml:"net,omitempty"`
|
||||||
|
|
||||||
|
// Hostname (also known as `--hostname` option)
|
||||||
|
// Could be set only if Docker is running in privileged mode
|
||||||
|
Hostname *string `yaml:"hostname,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DockerNetworkMode returns DefaultNetworkMode
|
// DockerNetworkMode returns DefaultNetworkMode
|
||||||
|
@ -22,3 +26,14 @@ func DockerNetworkMode(d *Docker) string {
|
||||||
}
|
}
|
||||||
return *d.NetworkMode
|
return *d.NetworkMode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DockerNetworkMode returns empty string
|
||||||
|
// when Docker.NetworkMode is empty.
|
||||||
|
// DockerNetworkMode returns Docker.NetworkMode
|
||||||
|
// when it is not empty.
|
||||||
|
func DockerHostname(d *Docker) string {
|
||||||
|
if d == nil || d.Hostname == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return *d.Hostname
|
||||||
|
}
|
||||||
|
|
|
@ -38,3 +38,32 @@ func TestDockerNetworkMode(t *testing.T) {
|
||||||
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDockerHostname(t *testing.T) {
|
||||||
|
var d *Docker
|
||||||
|
var expected string
|
||||||
|
|
||||||
|
expected = ""
|
||||||
|
d = nil
|
||||||
|
if actual := DockerHostname(d); actual != expected {
|
||||||
|
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = ""
|
||||||
|
d = &Docker{}
|
||||||
|
if actual := DockerHostname(d); actual != expected {
|
||||||
|
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = ""
|
||||||
|
d = &Docker{Hostname: nil}
|
||||||
|
if actual := DockerHostname(d); actual != expected {
|
||||||
|
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = "host"
|
||||||
|
d = &Docker{Hostname: &expected}
|
||||||
|
if actual := DockerHostname(d); actual != expected {
|
||||||
|
t.Errorf("The result is invalid. [expected: %s][actual: %s]", expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue