Merge pull request #10090 from milas/fix-wcow-volume

volume: fix WCOW volume mounts
This commit is contained in:
Milas Bowman 2022-12-16 13:43:04 -05:00 committed by GitHub
commit c37182b2c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 11 deletions

View File

@ -260,7 +260,7 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project,
stdinOpen = service.StdinOpen stdinOpen = service.StdinOpen
) )
volumeMounts, binds, mounts, err := s.buildContainerVolumes(ctx, *p, service, inherit) binds, mounts, err := s.buildContainerVolumes(ctx, *p, service, inherit)
if err != nil { if err != nil {
return nil, nil, nil, err return nil, nil, nil, err
} }
@ -289,7 +289,6 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project,
StopSignal: service.StopSignal, StopSignal: service.StopSignal,
Env: ToMobyEnv(env), Env: ToMobyEnv(env),
Healthcheck: ToMobyHealthCheck(service.HealthCheck), Healthcheck: ToMobyHealthCheck(service.HealthCheck),
Volumes: volumeMounts,
StopTimeout: ToSeconds(service.StopGracePeriod), StopTimeout: ToSeconds(service.StopGracePeriod),
} }
@ -731,30 +730,32 @@ func getDependentServiceFromMode(mode string) string {
return "" return ""
} }
func (s *composeService) buildContainerVolumes(ctx context.Context, p types.Project, service types.ServiceConfig, func (s *composeService) buildContainerVolumes(
inherit *moby.Container) (map[string]struct{}, []string, []mount.Mount, error) { ctx context.Context,
var mounts = []mount.Mount{} p types.Project,
service types.ServiceConfig,
inherit *moby.Container,
) ([]string, []mount.Mount, error) {
var mounts []mount.Mount
var binds []string
image := api.GetImageNameOrDefault(service, p.Name) image := api.GetImageNameOrDefault(service, p.Name)
imgInspect, _, err := s.apiClient().ImageInspectWithRaw(ctx, image) imgInspect, _, err := s.apiClient().ImageInspectWithRaw(ctx, image)
if err != nil { if err != nil {
return nil, nil, nil, err return nil, nil, err
} }
mountOptions, err := buildContainerMountOptions(p, service, imgInspect, inherit) mountOptions, err := buildContainerMountOptions(p, service, imgInspect, inherit)
if err != nil { if err != nil {
return nil, nil, nil, err return nil, nil, err
} }
volumeMounts := map[string]struct{}{}
binds := []string{}
MOUNTS: MOUNTS:
for _, m := range mountOptions { for _, m := range mountOptions {
if m.Type == mount.TypeNamedPipe { if m.Type == mount.TypeNamedPipe {
mounts = append(mounts, m) mounts = append(mounts, m)
continue continue
} }
volumeMounts[m.Target] = struct{}{}
if m.Type == mount.TypeBind { if m.Type == mount.TypeBind {
// `Mount` is preferred but does not offer option to created host path if missing // `Mount` is preferred but does not offer option to created host path if missing
// so `Bind` API is used here with raw volume string // so `Bind` API is used here with raw volume string
@ -774,7 +775,7 @@ MOUNTS:
} }
mounts = append(mounts, m) mounts = append(mounts, m)
} }
return volumeMounts, binds, mounts, nil return binds, mounts, nil
} }
func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby.ImageInspect, inherit *moby.Container) ([]mount.Mount, error) { func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby.ImageInspect, inherit *moby.Container) ([]mount.Mount, error) {