expose mount options to nomad
This commit is contained in:
parent
5508d392ef
commit
9063b500e0
|
@ -135,6 +135,38 @@ type DockerLoggingOpts struct {
|
|||
Config map[string]string `mapstructure:"-"`
|
||||
}
|
||||
|
||||
type Mount struct {
|
||||
Target string `mapstructure:"target"`
|
||||
Source string `mapstructure:"source"`
|
||||
Type string `mapstructure:"type"`
|
||||
ReadOnly bool `mapstructure:"readonly"`
|
||||
BindOptions *BindOptions `mapstructure:"bind_options"`
|
||||
VolumeOptions *VolumeOptions `mapstructure:"volume_options"`
|
||||
TempfsOptions *TempfsOptions `mapstructure:"tempfs_options"`
|
||||
}
|
||||
|
||||
type BindOptions struct {
|
||||
Propagation string `mapstructure:"propagation"`
|
||||
}
|
||||
|
||||
type VolumeOptions struct {
|
||||
NoCopy bool `mapstructure:"no_copy"`
|
||||
Labels map[string]string `mapstructure:"labels"`
|
||||
DriverConfig VolumeDriverConfig `mapstructure:"driver_config"`
|
||||
}
|
||||
|
||||
// TempfsOptions contains optional configuration for the tempfs type
|
||||
type TempfsOptions struct {
|
||||
SizeBytes int64 `mapstructure:"size_bytes"`
|
||||
Mode int `mapstructure:"mode"`
|
||||
}
|
||||
|
||||
// VolumeDriverConfig holds a map of volume driver specific options
|
||||
type VolumeDriverConfig struct {
|
||||
Name string `mapstructure:"name"`
|
||||
Options map[string]string `mapstructure:"options"`
|
||||
}
|
||||
|
||||
type DockerDriverConfig struct {
|
||||
ImageName string `mapstructure:"image"` // Container's Image Name
|
||||
LoadImage string `mapstructure:"load"` // LoadImage is a path to an image archive file
|
||||
|
@ -165,6 +197,7 @@ type DockerDriverConfig struct {
|
|||
WorkDir string `mapstructure:"work_dir"` // Working directory inside the container
|
||||
Logging []DockerLoggingOpts `mapstructure:"logging"` // Logging options for syslog server
|
||||
Volumes []string `mapstructure:"volumes"` // Host-Volumes to mount in, syntax: /path/to/host/directory:/destination/path/in/container
|
||||
Mounts []Mount `mapstructure:"mounts"` // Docker volumes to mount
|
||||
VolumeDriver string `mapstructure:"volume_driver"` // Docker volume driver used for the container's volumes
|
||||
ForcePull bool `mapstructure:"force_pull"` // Always force pull before running image, useful if your tags are mutable
|
||||
MacAddress string `mapstructure:"mac_address"` // Pin mac address to container
|
||||
|
@ -234,6 +267,34 @@ func NewDockerDriverConfig(task *structs.Task, env *env.TaskEnv) (*DockerDriverC
|
|||
}
|
||||
}
|
||||
|
||||
for i, m := range dconf.Mounts {
|
||||
dconf.Mounts[i].Target = env.ReplaceEnv(m.Target)
|
||||
dconf.Mounts[i].Source = env.ReplaceEnv(m.Source)
|
||||
dconf.Mounts[i].Type = env.ReplaceEnv(m.Type)
|
||||
if m.BindOptions != nil {
|
||||
dconf.Mounts[i].BindOptions.Propagation = env.ReplaceEnv(m.BindOptions.Propagation)
|
||||
}
|
||||
if m.VolumeOptions != nil {
|
||||
if m.VolumeOptions.Labels != nil {
|
||||
for k, v := range m.VolumeOptions.Labels {
|
||||
if k != env.ReplaceEnv(k) {
|
||||
delete(dconf.Mounts[i].VolumeOptions.Labels, k)
|
||||
}
|
||||
dconf.Mounts[i].VolumeOptions.Labels[env.ReplaceEnv(k)] = env.ReplaceEnv(v)
|
||||
}
|
||||
}
|
||||
dconf.Mounts[i].VolumeOptions.DriverConfig.Name = env.ReplaceEnv(m.VolumeOptions.DriverConfig.Name)
|
||||
if m.VolumeOptions.DriverConfig.Options != nil {
|
||||
for k, v := range m.VolumeOptions.DriverConfig.Options {
|
||||
if k != env.ReplaceEnv(k) {
|
||||
delete(dconf.Mounts[i].VolumeOptions.DriverConfig.Options, k)
|
||||
}
|
||||
dconf.Mounts[i].VolumeOptions.DriverConfig.Options[env.ReplaceEnv(k)] = env.ReplaceEnv(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(dconf.Logging) > 0 {
|
||||
dconf.Logging[0].Config = mapMergeStrStr(dconf.Logging[0].ConfigRaw...)
|
||||
}
|
||||
|
@ -452,6 +513,9 @@ func (d *DockerDriver) Validate(config map[string]interface{}) error {
|
|||
"volume_driver": &fields.FieldSchema{
|
||||
Type: fields.TypeString,
|
||||
},
|
||||
"mounts": {
|
||||
Type: fields.TypeArray,
|
||||
},
|
||||
"force_pull": &fields.FieldSchema{
|
||||
Type: fields.TypeBool,
|
||||
},
|
||||
|
@ -935,6 +999,38 @@ func (d *DockerDriver) createContainerConfig(ctx *ExecContext, task *structs.Tas
|
|||
}
|
||||
}
|
||||
|
||||
// Setup mounts
|
||||
for _, m := range driverConfig.Mounts {
|
||||
hm := docker.HostMount{
|
||||
Target: m.Target,
|
||||
Source: m.Source,
|
||||
Type: m.Type,
|
||||
ReadOnly: m.ReadOnly,
|
||||
}
|
||||
if m.BindOptions != nil {
|
||||
hm.BindOptions = &docker.BindOptions{
|
||||
Propagation: m.BindOptions.Propagation,
|
||||
}
|
||||
}
|
||||
if m.VolumeOptions != nil {
|
||||
hm.VolumeOptions = &docker.VolumeOptions{
|
||||
NoCopy: m.VolumeOptions.NoCopy,
|
||||
Labels: m.VolumeOptions.Labels,
|
||||
DriverConfig: docker.VolumeDriverConfig{
|
||||
Name: m.VolumeOptions.DriverConfig.Name,
|
||||
Options: m.VolumeOptions.DriverConfig.Options,
|
||||
},
|
||||
}
|
||||
}
|
||||
if m.TempfsOptions != nil {
|
||||
hm.TempfsOptions = &docker.TempfsOptions{
|
||||
SizeBytes: m.TempfsOptions.SizeBytes,
|
||||
Mode: m.TempfsOptions.Mode,
|
||||
}
|
||||
}
|
||||
hostConfig.Mounts = append(hostConfig.Mounts, hm)
|
||||
}
|
||||
|
||||
// set DNS search domains and extra hosts
|
||||
hostConfig.DNSSearch = driverConfig.DNSSearchDomains
|
||||
hostConfig.ExtraHosts = driverConfig.ExtraHosts
|
||||
|
|
Loading…
Reference in New Issue