2014-02-11 23:04:39 -05:00
|
|
|
package runconfig
|
|
|
|
|
|
|
|
import (
|
2014-05-02 19:59:28 -04:00
|
|
|
"strings"
|
|
|
|
|
2014-02-11 23:04:39 -05:00
|
|
|
"github.com/dotcloud/docker/engine"
|
|
|
|
"github.com/dotcloud/docker/nat"
|
2014-03-13 12:03:09 -04:00
|
|
|
"github.com/dotcloud/docker/utils"
|
2014-02-11 23:04:39 -05:00
|
|
|
)
|
|
|
|
|
2014-05-02 19:59:28 -04:00
|
|
|
type NetworkMode string
|
|
|
|
|
|
|
|
func (n NetworkMode) IsHost() bool {
|
|
|
|
return n == "host"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n NetworkMode) IsContainer() bool {
|
|
|
|
parts := strings.SplitN(string(n), ":", 2)
|
|
|
|
return len(parts) > 1 && parts[0] == "container"
|
|
|
|
}
|
|
|
|
|
2014-02-11 23:04:39 -05:00
|
|
|
type HostConfig struct {
|
2014-05-02 17:06:05 -04:00
|
|
|
Binds []string
|
|
|
|
ContainerIDFile string
|
|
|
|
LxcConf []utils.KeyValuePair
|
|
|
|
Privileged bool
|
|
|
|
PortBindings nat.PortMap
|
|
|
|
Links []string
|
|
|
|
PublishAllPorts bool
|
|
|
|
Dns []string
|
|
|
|
DnsSearch []string
|
|
|
|
VolumesFrom []string
|
2014-05-02 19:59:28 -04:00
|
|
|
NetworkMode NetworkMode
|
2014-02-11 23:04:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func ContainerHostConfigFromJob(job *engine.Job) *HostConfig {
|
|
|
|
hostConfig := &HostConfig{
|
|
|
|
ContainerIDFile: job.Getenv("ContainerIDFile"),
|
|
|
|
Privileged: job.GetenvBool("Privileged"),
|
|
|
|
PublishAllPorts: job.GetenvBool("PublishAllPorts"),
|
2014-05-02 19:59:28 -04:00
|
|
|
NetworkMode: NetworkMode(job.Getenv("NetworkMode")),
|
2014-02-11 23:04:39 -05:00
|
|
|
}
|
|
|
|
job.GetenvJson("LxcConf", &hostConfig.LxcConf)
|
|
|
|
job.GetenvJson("PortBindings", &hostConfig.PortBindings)
|
|
|
|
if Binds := job.GetenvList("Binds"); Binds != nil {
|
|
|
|
hostConfig.Binds = Binds
|
|
|
|
}
|
|
|
|
if Links := job.GetenvList("Links"); Links != nil {
|
|
|
|
hostConfig.Links = Links
|
|
|
|
}
|
2014-04-07 22:12:22 -04:00
|
|
|
if Dns := job.GetenvList("Dns"); Dns != nil {
|
|
|
|
hostConfig.Dns = Dns
|
|
|
|
}
|
|
|
|
if DnsSearch := job.GetenvList("DnsSearch"); DnsSearch != nil {
|
|
|
|
hostConfig.DnsSearch = DnsSearch
|
|
|
|
}
|
2014-04-08 06:02:17 -04:00
|
|
|
if VolumesFrom := job.GetenvList("VolumesFrom"); VolumesFrom != nil {
|
|
|
|
hostConfig.VolumesFrom = VolumesFrom
|
|
|
|
}
|
2014-02-11 23:04:39 -05:00
|
|
|
return hostConfig
|
|
|
|
}
|