Browse Source

Merge pull request #1435 from docker/more_composefile

add support for a few more composefile attributes
Nicolas De loof 4 years ago
parent
commit
23b03af744
2 changed files with 85 additions and 14 deletions
  1. 11 0
      local/compose/build.go
  2. 74 14
      local/compose/create.go

+ 11 - 0
local/compose/build.go

@@ -50,6 +50,17 @@ func (s *composeService) Build(ctx context.Context, project *types.Project, opti
 			buildOptions.Pull = options.Pull
 			buildOptions.BuildArgs = options.Args
 			opts[imageName] = buildOptions
+			buildOptions.CacheFrom, err = build.ParseCacheEntry(service.Build.CacheFrom)
+			if err != nil {
+				return err
+			}
+
+			for _, image := range service.Build.CacheFrom {
+				buildOptions.CacheFrom = append(buildOptions.CacheFrom, bclient.CacheOptionsEntry{
+					Type:  "registry",
+					Attrs: map[string]string{"ref": image},
+				})
+			}
 		}
 	}
 

+ 74 - 14
local/compose/create.go

@@ -33,6 +33,7 @@ import (
 	volume_api "github.com/docker/docker/api/types/volume"
 	"github.com/docker/docker/errdefs"
 	"github.com/docker/go-connections/nat"
+	"github.com/docker/go-units"
 	"github.com/pkg/errors"
 	"github.com/sirupsen/logrus"
 
@@ -272,6 +273,31 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project,
 		return nil, nil, nil, err
 	}
 
+	shmSize := int64(0)
+	if service.ShmSize != "" {
+		shmSize, err = strconv.ParseInt(service.ShmSize, 10, 64)
+		if err != nil {
+			return nil, nil, nil, err
+		}
+	}
+
+	tmpfs := map[string]string{}
+	for _, t := range service.Tmpfs {
+		if arr := strings.SplitN(t, ":", 2); len(arr) > 1 {
+			tmpfs[arr[0]] = arr[1]
+		} else {
+			tmpfs[arr[0]] = ""
+		}
+	}
+
+	var logConfig container.LogConfig
+	if service.Logging != nil {
+		logConfig = container.LogConfig{
+			Type:   service.Logging.Driver,
+			Config: service.Logging.Options,
+		}
+	}
+
 	hostConfig := container.HostConfig{
 		AutoRemove:     autoRemove,
 		Binds:          binds,
@@ -282,20 +308,23 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project,
 		Init:           service.Init,
 		ReadonlyRootfs: service.ReadOnly,
 		RestartPolicy:  getRestartPolicy(service),
-		// ShmSize: , TODO
-		Sysctls:      service.Sysctls,
-		PortBindings: portBindings,
-		Resources:    resources,
-		VolumeDriver: service.VolumeDriver,
-		VolumesFrom:  service.VolumesFrom,
-		DNS:          service.DNS,
-		DNSSearch:    service.DNSSearch,
-		DNSOptions:   service.DNSOpts,
-		ExtraHosts:   service.ExtraHosts,
-		SecurityOpt:  service.SecurityOpt,
-		UsernsMode:   container.UsernsMode(service.UserNSMode),
-		Privileged:   service.Privileged,
-		Isolation:    container.Isolation(service.Isolation),
+		ShmSize:        shmSize,
+		Sysctls:        service.Sysctls,
+		PortBindings:   portBindings,
+		Resources:      resources,
+		VolumeDriver:   service.VolumeDriver,
+		VolumesFrom:    service.VolumesFrom,
+		DNS:            service.DNS,
+		DNSSearch:      service.DNSSearch,
+		DNSOptions:     service.DNSOpts,
+		ExtraHosts:     service.ExtraHosts,
+		SecurityOpt:    service.SecurityOpt,
+		UsernsMode:     container.UsernsMode(service.UserNSMode),
+		Privileged:     service.Privileged,
+		PidMode:        container.PidMode(service.Pid),
+		Tmpfs:          tmpfs,
+		Isolation:      container.Isolation(service.Isolation),
+		LogConfig:      logConfig,
 	}
 
 	networkConfig := buildDefaultNetworkConfig(service, networkMode, getContainerName(p.Name, service, number))
@@ -349,6 +378,37 @@ func getDeployResources(s types.ServiceConfig) container.Resources {
 			Driver:       device.Driver,
 		})
 	}
+
+	for _, device := range s.Devices {
+		// FIXME should use docker/cli parseDevice, unfortunately private
+		src := ""
+		dst := ""
+		permissions := "rwm"
+		arr := strings.Split(device, ":")
+		switch len(arr) {
+		case 3:
+			permissions = arr[2]
+			fallthrough
+		case 2:
+			dst = arr[1]
+			fallthrough
+		case 1:
+			src = arr[0]
+		}
+		resources.Devices = append(resources.Devices, container.DeviceMapping{
+			PathOnHost:        src,
+			PathInContainer:   dst,
+			CgroupPermissions: permissions,
+		})
+	}
+
+	for name, u := range s.Ulimits {
+		resources.Ulimits = append(resources.Ulimits, &units.Ulimit{
+			Name: name,
+			Hard: int64(u.Hard),
+			Soft: int64(u.Soft),
+		})
+	}
 	return resources
 }