Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 23b03af

Browse files
authored
Merge pull request #1435 from docker/more_composefile
add support for a few more composefile attributes
2 parents 3f50200 + 70694e1 commit 23b03af

File tree

2 files changed

+85
-14
lines changed

2 files changed

+85
-14
lines changed

local/compose/build.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ func (s *composeService) Build(ctx context.Context, project *types.Project, opti
5050
buildOptions.Pull = options.Pull
5151
buildOptions.BuildArgs = options.Args
5252
opts[imageName] = buildOptions
53+
buildOptions.CacheFrom, err = build.ParseCacheEntry(service.Build.CacheFrom)
54+
if err != nil {
55+
return err
56+
}
57+
58+
for _, image := range service.Build.CacheFrom {
59+
buildOptions.CacheFrom = append(buildOptions.CacheFrom, bclient.CacheOptionsEntry{
60+
Type: "registry",
61+
Attrs: map[string]string{"ref": image},
62+
})
63+
}
5364
}
5465
}
5566

local/compose/create.go

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
volume_api "github.com/docker/docker/api/types/volume"
3434
"github.com/docker/docker/errdefs"
3535
"github.com/docker/go-connections/nat"
36+
"github.com/docker/go-units"
3637
"github.com/pkg/errors"
3738
"github.com/sirupsen/logrus"
3839

@@ -272,6 +273,31 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project,
272273
return nil, nil, nil, err
273274
}
274275

276+
shmSize := int64(0)
277+
if service.ShmSize != "" {
278+
shmSize, err = strconv.ParseInt(service.ShmSize, 10, 64)
279+
if err != nil {
280+
return nil, nil, nil, err
281+
}
282+
}
283+
284+
tmpfs := map[string]string{}
285+
for _, t := range service.Tmpfs {
286+
if arr := strings.SplitN(t, ":", 2); len(arr) > 1 {
287+
tmpfs[arr[0]] = arr[1]
288+
} else {
289+
tmpfs[arr[0]] = ""
290+
}
291+
}
292+
293+
var logConfig container.LogConfig
294+
if service.Logging != nil {
295+
logConfig = container.LogConfig{
296+
Type: service.Logging.Driver,
297+
Config: service.Logging.Options,
298+
}
299+
}
300+
275301
hostConfig := container.HostConfig{
276302
AutoRemove: autoRemove,
277303
Binds: binds,
@@ -282,20 +308,23 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project,
282308
Init: service.Init,
283309
ReadonlyRootfs: service.ReadOnly,
284310
RestartPolicy: getRestartPolicy(service),
285-
// ShmSize: , TODO
286-
Sysctls: service.Sysctls,
287-
PortBindings: portBindings,
288-
Resources: resources,
289-
VolumeDriver: service.VolumeDriver,
290-
VolumesFrom: service.VolumesFrom,
291-
DNS: service.DNS,
292-
DNSSearch: service.DNSSearch,
293-
DNSOptions: service.DNSOpts,
294-
ExtraHosts: service.ExtraHosts,
295-
SecurityOpt: service.SecurityOpt,
296-
UsernsMode: container.UsernsMode(service.UserNSMode),
297-
Privileged: service.Privileged,
298-
Isolation: container.Isolation(service.Isolation),
311+
ShmSize: shmSize,
312+
Sysctls: service.Sysctls,
313+
PortBindings: portBindings,
314+
Resources: resources,
315+
VolumeDriver: service.VolumeDriver,
316+
VolumesFrom: service.VolumesFrom,
317+
DNS: service.DNS,
318+
DNSSearch: service.DNSSearch,
319+
DNSOptions: service.DNSOpts,
320+
ExtraHosts: service.ExtraHosts,
321+
SecurityOpt: service.SecurityOpt,
322+
UsernsMode: container.UsernsMode(service.UserNSMode),
323+
Privileged: service.Privileged,
324+
PidMode: container.PidMode(service.Pid),
325+
Tmpfs: tmpfs,
326+
Isolation: container.Isolation(service.Isolation),
327+
LogConfig: logConfig,
299328
}
300329

301330
networkConfig := buildDefaultNetworkConfig(service, networkMode, getContainerName(p.Name, service, number))
@@ -349,6 +378,37 @@ func getDeployResources(s types.ServiceConfig) container.Resources {
349378
Driver: device.Driver,
350379
})
351380
}
381+
382+
for _, device := range s.Devices {
383+
// FIXME should use docker/cli parseDevice, unfortunately private
384+
src := ""
385+
dst := ""
386+
permissions := "rwm"
387+
arr := strings.Split(device, ":")
388+
switch len(arr) {
389+
case 3:
390+
permissions = arr[2]
391+
fallthrough
392+
case 2:
393+
dst = arr[1]
394+
fallthrough
395+
case 1:
396+
src = arr[0]
397+
}
398+
resources.Devices = append(resources.Devices, container.DeviceMapping{
399+
PathOnHost: src,
400+
PathInContainer: dst,
401+
CgroupPermissions: permissions,
402+
})
403+
}
404+
405+
for name, u := range s.Ulimits {
406+
resources.Ulimits = append(resources.Ulimits, &units.Ulimit{
407+
Name: name,
408+
Hard: int64(u.Hard),
409+
Soft: int64(u.Soft),
410+
})
411+
}
352412
return resources
353413
}
354414

0 commit comments

Comments
 (0)