2014-02-11 23:04:39 -05:00
|
|
|
package runconfig
|
|
|
|
|
|
|
|
import (
|
2014-05-02 19:59:28 -04:00
|
|
|
"strings"
|
|
|
|
|
2014-07-24 18:19:50 -04:00
|
|
|
"github.com/docker/docker/engine"
|
|
|
|
"github.com/docker/docker/nat"
|
|
|
|
"github.com/docker/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-05-31 00:00:47 -04:00
|
|
|
type DeviceMapping struct {
|
|
|
|
PathOnHost string
|
|
|
|
PathInContainer string
|
|
|
|
CgroupPermissions string
|
|
|
|
}
|
|
|
|
|
2014-08-04 19:14:43 -04:00
|
|
|
type RestartPolicy struct {
|
|
|
|
Name string
|
|
|
|
MaximumRetryCount int
|
|
|
|
}
|
|
|
|
|
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-31 00:00:47 -04:00
|
|
|
Devices []DeviceMapping
|
2014-05-02 19:59:28 -04:00
|
|
|
NetworkMode NetworkMode
|
2014-07-10 14:41:11 -04:00
|
|
|
CapAdd []string
|
|
|
|
CapDrop []string
|
2014-08-04 19:14:43 -04:00
|
|
|
RestartPolicy RestartPolicy
|
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
|
|
|
}
|
2014-08-04 19:14:43 -04:00
|
|
|
|
2014-02-11 23:04:39 -05:00
|
|
|
job.GetenvJson("LxcConf", &hostConfig.LxcConf)
|
|
|
|
job.GetenvJson("PortBindings", &hostConfig.PortBindings)
|
2014-05-31 00:00:47 -04:00
|
|
|
job.GetenvJson("Devices", &hostConfig.Devices)
|
2014-08-04 19:14:43 -04:00
|
|
|
job.GetenvJson("RestartPolicy", &hostConfig.RestartPolicy)
|
2014-02-11 23:04:39 -05:00
|
|
|
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-07-10 17:51:15 -04:00
|
|
|
if CapAdd := job.GetenvList("CapAdd"); CapAdd != nil {
|
|
|
|
hostConfig.CapAdd = CapAdd
|
|
|
|
}
|
|
|
|
if CapDrop := job.GetenvList("CapDrop"); CapDrop != nil {
|
|
|
|
hostConfig.CapDrop = CapDrop
|
|
|
|
}
|
2014-08-04 19:14:43 -04:00
|
|
|
|
2014-02-11 23:04:39 -05:00
|
|
|
return hostConfig
|
|
|
|
}
|