Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hostname in docker section of .drone.yml #720

Merged
merged 1 commit into from
Dec 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions shared/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions shared/build/script/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
29 changes: 29 additions & 0 deletions shared/build/script/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}