Skip to content

Commit

Permalink
fix: do not try to create file shares for non-directories
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
milas committed Apr 17, 2024
1 parent d239f0f commit 7390df7
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions pkg/compose/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,25 @@ func (s *composeService) ensureProjectVolumes(ctx context.Context, project *type
if !filepath.IsAbs(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 {
return fmt.Errorf("service %s: host path %q does not exist and `create_host_path` is false", svcName, vol.Source)
}
if err := os.MkdirAll(p, 0o755); err != nil {
return fmt.Errorf("creating host path: %w", err)
logrus.Debugf("Skipping creating file share for %q: does not exist and `create_host_path` is false", p)
continue
}
} 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)
}
}
Expand All @@ -185,14 +196,14 @@ func (s *composeService) ensureProjectVolumes(ctx context.Context, project *type

fileShareManager := desktop.NewFileShareManager(s.desktopCli, project.Name, paths)
if err := fileShareManager.EnsureExists(ctx); err != nil {
return fmt.Errorf("initializing: %w", err)
return fmt.Errorf("initializing file shares: %w", err)
}
}
return 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
}
Expand Down

0 comments on commit 7390df7

Please sign in to comment.