Skip to content

Commit 8fbf329

Browse files
authored
fix: check bind source file/dir exists (#624)
Stacker does not check if a bind mount source exists and if the source is a directory then the container crashes with a stack trace that does not indicate that the missing source dir is the issue. Check if the source exists and return an error indicating the source is missing instead of the container stack trace. Signed-off-by: Ryan Harper <[email protected]>
1 parent d3f8ebd commit 8fbf329

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

pkg/container/container.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ func New(sc types.StackerConfig, name string) (*Container, error) {
6565
func (c *Container) BindMount(source string, dest string, extraOpts string) error {
6666
createOpt := "create=dir"
6767
stat, err := os.Stat(source)
68+
if os.IsNotExist(err) {
69+
return errors.Errorf("bind mount source %q does not exist, refusing bind mount: %s", source, err)
70+
}
6871
if err == nil && !stat.IsDir() {
6972
createOpt = "create=file"
7073
}

pkg/stacker/build.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,9 +820,10 @@ func SetupLayerConfig(config types.StackerConfig, c *container.Container, l type
820820
}
821821

822822
for _, bind := range l.Binds {
823+
log.Debugf("bind mounting %q into container at %q", bind.Source, bind.Dest)
823824
err = c.BindMount(bind.Source, bind.Dest, "")
824825
if err != nil {
825-
return err
826+
return errors.Errorf("failed to bind mount %q at %q: %s", bind.Source, bind.Dest, err)
826827
}
827828
}
828829

0 commit comments

Comments
 (0)