Add hostname in docker section of .drone.yml

This commit is contained in:
Vsevolod Strukchinsky 2014-11-20 15:18:12 +05:00
parent 7e2b03e20f
commit 78b8b7dd75
3 changed files with 45 additions and 0 deletions

View file

@ -319,6 +319,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,

View file

@ -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
}

View file

@ -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)
}
}