Merge pull request #720 from floatdrop/hostname-in-drone-yml
Add hostname in docker section of .drone.yml
This commit is contained in:
commit
f86e73bdbf
3 changed files with 45 additions and 0 deletions
|
@ -315,6 +315,7 @@ func (b *Builder) teardown() error {
|
|||
func (b *Builder) run() error {
|
||||
// create and run the container
|
||||
conf := docker.Config{
|
||||
Hostname: script.DockerHostname(b.Build.Docker),
|
||||
Image: b.image.ID,
|
||||
AttachStdin: false,
|
||||
AttachStdout: true,
|
||||
|
|
|
@ -10,6 +10,10 @@ type Docker struct {
|
|||
// NetworkMode (also known as `--net` option)
|
||||
// Could be set only if Docker is running in privileged mode
|
||||
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
|
||||
|
@ -22,3 +26,14 @@ func DockerNetworkMode(d *Docker) string {
|
|||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
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