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

Expose docker mount options #3021

Merged
merged 3 commits into from
Aug 17, 2017
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
102 changes: 102 additions & 0 deletions client/driver/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -234,6 +267,40 @@ 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 dconf.Mounts[i].Type == "" {
dconf.Mounts[i].Type = "volume"
}
if dconf.Mounts[i].Type != "volume" {
return nil, fmt.Errorf("mount type %v is not supported")
}
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...)
}
Expand Down Expand Up @@ -452,6 +519,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,
},
Expand Down Expand Up @@ -935,6 +1005,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
Expand Down
13 changes: 13 additions & 0 deletions vendor/github.com/fsouza/go-dockerclient/AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion vendor/github.com/fsouza/go-dockerclient/README.markdown

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions vendor/github.com/fsouza/go-dockerclient/appveyor.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 49 additions & 3 deletions vendor/github.com/fsouza/go-dockerclient/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading