Skip to content
Closed
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
2 changes: 2 additions & 0 deletions cli/command/service/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
flags.SetAnnotation(flagSysCtl, "version", []string{"1.40"})
flags.Var(&opts.ulimits, flagUlimit, "Ulimit options")
flags.SetAnnotation(flagUlimit, "version", []string{"1.41"})
flags.Var(&opts.devices, flagDevice, "Devices to add")
flags.SetAnnotation(flagDevice, "version", []string{"1.42"})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version is almost assuredly wrong. No idea if this should be 1.41, 1.42, or 1.43. I wasn't easily able to figure out what the current version is.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the master's API version is 1.43: https://github.com/moby/moby/blob/master/api/common.go#L6


flags.Var(cliopts.NewListOptsRef(&opts.resources.resGenericResources, ValidateSingleGenericResource), "generic-resource", "User defined resources")
flags.SetAnnotation(flagHostAdd, "version", []string{"1.32"})
Expand Down
16 changes: 16 additions & 0 deletions cli/command/service/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ Ulimits:
{{- range $k, $v := .ContainerUlimits }}
{{ $k }}: {{ $v }}
{{- end }}{{ end }}
{{- if .ContainerDevices }}
Devices:
{{- range $port := .ContainerDevices }}
PathOnHost = {{ $port.PathOnHost }}
PathInContainer = {{ $port.PathInContainer }}
CgroupPermissions = {{ $port.CgroupPermissions }}
{{- end }} {{ end -}}
{{- if .ContainerMounts }}
Mounts:
{{- end }}
Expand Down Expand Up @@ -487,6 +494,15 @@ func (ctx *serviceInspectContext) HasContainerUlimits() bool {
return len(ctx.Service.Spec.TaskTemplate.ContainerSpec.Ulimits) > 0
}


func (ctx *serviceInspectContext) ContainerDevices() []container.DeviceMapping {
return ctx.Service.Spec.TaskTemplate.ContainerSpec.Devices;
}

func (ctx *serviceInspectContext) HasContainerDevices() bool {
return len(ctx.Service.Spec.TaskTemplate.ContainerSpec.Devices) > 0
}

func (ctx *serviceInspectContext) HasResources() bool {
return ctx.Service.Spec.TaskTemplate.Resources != nil
}
Expand Down
3 changes: 3 additions & 0 deletions cli/command/service/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ type serviceOptions struct {
capAdd opts.ListOpts
capDrop opts.ListOpts
ulimits opts.UlimitOpt
devices opts.ListOpts

resources resourceOptions
stopGrace opts.DurationOpt
Expand Down Expand Up @@ -564,6 +565,7 @@ func newServiceOptions() *serviceOptions {
capAdd: opts.NewListOpts(nil),
capDrop: opts.NewListOpts(nil),
ulimits: *opts.NewUlimitOpt(nil),
devices: opts.NewListOpts(nil),
}
}

Expand Down Expand Up @@ -1029,6 +1031,7 @@ const (
flagUlimit = "ulimit"
flagUlimitAdd = "ulimit-add"
flagUlimitRemove = "ulimit-rm"
flagDevice = "device"
)

func validateAPIVersion(c swarm.ServiceSpec, serverAPIVersion string) error {
Expand Down
33 changes: 33 additions & 0 deletions cli/compose/convert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ func Service(
}
}

devices, err := convertDevices(service.Devices)
if err != nil {
return swarm.ServiceSpec{}, err
}

capAdd, capDrop := opts.EffectiveCapAddCapDrop(service.CapAdd, service.CapDrop)

serviceSpec := swarm.ServiceSpec{
Expand Down Expand Up @@ -153,6 +158,7 @@ func Service(
CapabilityAdd: capAdd,
CapabilityDrop: capDrop,
Ulimits: convertUlimits(service.Ulimits),
Devices: devices,
},
LogDriver: logDriver,
Resources: resources,
Expand Down Expand Up @@ -719,3 +725,30 @@ func convertUlimits(origUlimits map[string]*composetypes.UlimitsConfig) []*units
})
return ulimits
}

func convertDevices(devices []string) ([]container.DeviceMapping, error) {
newDevices := make([]container.DeviceMapping, len(devices))
for i, device := range devices {
parts := strings.Split(device, ":")
if len(parts) < 1 || len(parts) > 3 {
return nil, errors.New("failed to parse device")
}

mapping := container.DeviceMapping{
PathOnHost: parts[0],
PathInContainer: parts[0],
}

if len(parts) > 1 {
mapping.PathInContainer = parts[1]
}

if len(parts) == 3 {
mapping.CgroupPermissions = parts[2]
}

newDevices[i] = mapping
}

return newDevices, nil
}
1 change: 0 additions & 1 deletion cli/compose/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ var UnsupportedProperties = []string{
"build",
"cgroupns_mode",
"cgroup_parent",
"devices",
"domainname",
"external_links",
"ipc",
Expand Down
Loading