mirror of https://github.com/docker/compose.git
fix: do not try to create file shares for non-directories
When creating automatic file shares, ignore any non-directory bind mounts, e.g. for an individual (normal) file or a special type like a Unix socket (`/var/run/docker.sock`). Additionally, there's no need to create a directory if one does not exist, the API will handle that. However, the check for existence remains so that `create_host_path: false` mounts can be ignored. Signed-off-by: Milas Bowman <milas.bowman@docker.com>
This commit is contained in:
parent
d239f0f318
commit
922422a539
|
@ -167,14 +167,25 @@ func (s *composeService) ensureProjectVolumes(ctx context.Context, project *type
|
||||||
if !filepath.IsAbs(p) {
|
if !filepath.IsAbs(p) {
|
||||||
return fmt.Errorf("file share path is not absolute: %s", p)
|
return fmt.Errorf("file share path is not absolute: %s", p)
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(p); errors.Is(err, fs.ErrNotExist) {
|
if fi, err := os.Stat(p); errors.Is(err, fs.ErrNotExist) {
|
||||||
|
// actual directory will be implicitly created when the
|
||||||
|
// file share is initialized if it doesn't exist, so
|
||||||
|
// need to filter out any that should not be auto-created
|
||||||
if vol.Bind != nil && !vol.Bind.CreateHostPath {
|
if vol.Bind != nil && !vol.Bind.CreateHostPath {
|
||||||
return fmt.Errorf("service %s: host path %q does not exist and `create_host_path` is false", svcName, vol.Source)
|
logrus.Debugf("Skipping creating file share for %q: does not exist and `create_host_path` is false", p)
|
||||||
}
|
continue
|
||||||
if err := os.MkdirAll(p, 0o755); err != nil {
|
|
||||||
return fmt.Errorf("creating host path: %w", err)
|
|
||||||
}
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
// if we can't read the path, we won't be able ot make
|
||||||
|
// a file share for it
|
||||||
|
logrus.Debugf("Skipping creating file share for %q: %v", p, err)
|
||||||
|
continue
|
||||||
|
} else if !fi.IsDir() {
|
||||||
|
// ignore files & special types (e.g. Unix sockets)
|
||||||
|
logrus.Debugf("Skipping creating file share for %q: not a directory", p)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
paths = append(paths, p)
|
paths = append(paths, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,14 +196,14 @@ func (s *composeService) ensureProjectVolumes(ctx context.Context, project *type
|
||||||
|
|
||||||
fileShareManager := desktop.NewFileShareManager(s.desktopCli, project.Name, paths)
|
fileShareManager := desktop.NewFileShareManager(s.desktopCli, project.Name, paths)
|
||||||
if err := fileShareManager.EnsureExists(ctx); err != nil {
|
if err := fileShareManager.EnsureExists(ctx); err != nil {
|
||||||
return fmt.Errorf("initializing: %w", err)
|
return fmt.Errorf("initializing file shares: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
progress.ContextWriter(ctx).TailMsgf("Failed to prepare Synchronized File Shares: %v", err)
|
progress.ContextWriter(ctx).TailMsgf("Failed to prepare Synchronized file shares: %v", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue