mirror of https://github.com/docker/compose.git
when bind mount has CreateHostPath set, use bind API
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
38b4220bdb
commit
b33588b725
2
go.mod
2
go.mod
|
@ -17,7 +17,7 @@ require (
|
|||
github.com/awslabs/goformation/v4 v4.15.6
|
||||
github.com/buger/goterm v1.0.0
|
||||
github.com/cnabio/cnab-to-oci v0.3.1-beta1
|
||||
github.com/compose-spec/compose-go v0.0.0-20210426122519-7739b749b02f
|
||||
github.com/compose-spec/compose-go v0.0.0-20210427143821-6d1c5982084f
|
||||
github.com/containerd/console v1.0.1
|
||||
github.com/containerd/containerd v1.4.3
|
||||
github.com/containerd/continuity v0.0.0-20200928162600-f2cc35102c2a // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -308,8 +308,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
|
|||
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
|
||||
github.com/codahale/hdrhistogram v0.0.0-20160425231609-f8ad88b59a58/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
|
||||
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
|
||||
github.com/compose-spec/compose-go v0.0.0-20210426122519-7739b749b02f h1:t52ow0GxFOfxOwtEEiZKOd5B3yrdz2VuSuP/4xMb06k=
|
||||
github.com/compose-spec/compose-go v0.0.0-20210426122519-7739b749b02f/go.mod h1:6eIT9U2OgdHmkRD6szmqatCrWWEEUSwl/j2iJYH4jLo=
|
||||
github.com/compose-spec/compose-go v0.0.0-20210427143821-6d1c5982084f h1:EJu2tLPcjRTAdFDJZOQj57ehBo+m71Iz6sUf1Q8/BOY=
|
||||
github.com/compose-spec/compose-go v0.0.0-20210427143821-6d1c5982084f/go.mod h1:6eIT9U2OgdHmkRD6szmqatCrWWEEUSwl/j2iJYH4jLo=
|
||||
github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko=
|
||||
github.com/containerd/cgroups v0.0.0-20200531161412-0dbf7f05ba59/go.mod h1:pA0z1pT8KYB3TCXK/ocprsh7MAkoW8bZVzPdih9snmM=
|
||||
github.com/containerd/cgroups v0.0.0-20200710171044-318312a37340 h1:9atoWyI9RtXFwf7UDbme/6M8Ud0rFrx+Q3ZWgSnsxtw=
|
||||
|
|
|
@ -574,22 +574,25 @@ func (s *composeService) buildContainerVolumes(ctx context.Context, p types.Proj
|
|||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
// filter binds and volumes mount targets
|
||||
volumeMounts := map[string]struct{}{}
|
||||
binds := []string{}
|
||||
MOUNTS:
|
||||
for _, m := range mountOptions {
|
||||
|
||||
if m.Type == mount.TypeVolume {
|
||||
volumeMounts[m.Target] = struct{}{}
|
||||
if m.Source != "" {
|
||||
binds = append(binds, fmt.Sprintf("%s:%s:rw", m.Source, m.Target))
|
||||
volumeMounts[m.Target] = struct{}{}
|
||||
// `Bind` API is used when host path need to be created if missing, `Mount` is preferred otherwise
|
||||
if m.Type == mount.TypeBind {
|
||||
for _, v := range service.Volumes {
|
||||
if v.Target == m.Target && v.Bind != nil && v.Bind.CreateHostPath {
|
||||
mode := "rw"
|
||||
if m.ReadOnly {
|
||||
mode = "ro"
|
||||
}
|
||||
binds = append(binds, fmt.Sprintf("%s:%s:%s", m.Source, m.Target, mode))
|
||||
continue MOUNTS
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, m := range mountOptions {
|
||||
if m.Type == mount.TypeBind || m.Type == mount.TypeTmpfs {
|
||||
mounts = append(mounts, m)
|
||||
}
|
||||
mounts = append(mounts, m)
|
||||
}
|
||||
return volumeMounts, binds, mounts, nil
|
||||
}
|
||||
|
@ -623,7 +626,6 @@ func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby
|
|||
return nil, err
|
||||
}
|
||||
mounts[k] = m
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -758,7 +760,6 @@ func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.
|
|||
}
|
||||
if volume.Type == types.VolumeTypeVolume {
|
||||
if volume.Source != "" {
|
||||
|
||||
pVolume, ok := project.Volumes[volume.Source]
|
||||
if ok {
|
||||
source = pVolume.Name
|
||||
|
|
|
@ -49,7 +49,7 @@ func TestLocalComposeVolume(t *testing.T) {
|
|||
res := c.RunDockerCmd("inspect", "compose-e2e-volume_nginx2_1", "--format", "{{ json .Mounts }}")
|
||||
output := res.Stdout()
|
||||
// nolint
|
||||
assert.Assert(t, strings.Contains(output, `"Destination":"/usr/src/app/node_modules","Driver":"local","Mode":"","RW":true,"Propagation":""`), output)
|
||||
assert.Assert(t, strings.Contains(output, `"Destination":"/usr/src/app/node_modules","Driver":"local","Mode":"z","RW":true,"Propagation":""`), output)
|
||||
assert.Assert(t, strings.Contains(output, `"Destination":"/myconfig","Mode":"","RW":false,"Propagation":"rprivate"`), output)
|
||||
})
|
||||
|
||||
|
@ -64,11 +64,11 @@ func TestLocalComposeVolume(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("check container bind-mounts specs", func(t *testing.T) {
|
||||
res := c.RunDockerCmd("inspect", "compose-e2e-volume_nginx_1", "--format", "{{ json .HostConfig.Mounts }}")
|
||||
res := c.RunDockerCmd("inspect", "compose-e2e-volume_nginx_1", "--format", "{{ json .Mounts }}")
|
||||
output := res.Stdout()
|
||||
// nolint
|
||||
assert.Assert(t, strings.Contains(output, `"Type":"bind"`))
|
||||
assert.Assert(t, strings.Contains(output, `"Target":"/usr/share/nginx/html"`))
|
||||
assert.Assert(t, strings.Contains(output, `"Destination":"/usr/share/nginx/html"`))
|
||||
})
|
||||
|
||||
t.Run("cleanup volume project", func(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue