move privileged to yaml file

This commit is contained in:
Ke Zhu 2015-07-14 16:38:10 -04:00 committed by Ke Zhu
parent b7ebf89228
commit cf578b31cc
3 changed files with 25 additions and 12 deletions

View file

@ -327,7 +327,7 @@ func (b *Builder) run() error {
// configure if Docker should run in privileged mode // configure if Docker should run in privileged mode
host := docker.HostConfig{ host := docker.HostConfig{
Privileged: (b.Privileged && len(b.Repo.PR) == 0), Privileged: (b.Privileged && script.DockerPrivileged(b.Build.Docker)),
} }
if host.Privileged { if host.Privileged {

View file

@ -412,21 +412,21 @@ func TestRunPrivileged(t *testing.T) {
t.Errorf("Expected container NOT started in Privileged mode") t.Errorf("Expected container NOT started in Privileged mode")
} }
// now lets set priviliged mode // now lets try to enable priviliged mode
b.Privileged = true b.Privileged = true
b.run() b.run()
if conf.Privileged != true {
t.Errorf("Expected container IS started in Privileged mode")
}
// now lets set priviliged mode but for a pull request
b.Privileged = true
b.Repo.PR = "55"
b.run()
if conf.Privileged != false { if conf.Privileged != false {
t.Errorf("Expected container NOT started in Privileged mode when PR") t.Errorf("Expected container NOT started in Privileged mode when no setup in build script")
}
// now lets set priviliged mode in build script
b.Privileged = true
b.Build = &script.Build{Docker: &script.Docker{Privileged: true}}
b.run()
if conf.Privileged != true {
t.Errorf("Expected container IS started in Privileged mode when setup privileged mode in build script")
} }
} }

View file

@ -17,6 +17,10 @@ type Docker struct {
// Allocate a pseudo-TTY (also known as `--tty` option) // Allocate a pseudo-TTY (also known as `--tty` option)
TTY bool `yaml:"tty,omitempty"` TTY bool `yaml:"tty,omitempty"`
// Privileged means enabling all devices on the host in container
// (also known as `--privileged=true` option)
Privileged bool `yaml:"privileged,omitempty"`
} }
// DockerNetworkMode returns DefaultNetworkMode // DockerNetworkMode returns DefaultNetworkMode
@ -49,3 +53,12 @@ func DockerTty(d *Docker) bool {
} }
return d.TTY return d.TTY
} }
// DockerPrivileged returns true if the build
// should have privileged mode
func DockerPrivileged(d *Docker) bool {
if d == nil {
return false
}
return d.Privileged
}