Skip to content

Commit

Permalink
fix: check bind source file/dir exists (#624)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
raharper authored Jun 11, 2024
1 parent d3f8ebd commit 8fbf329
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func New(sc types.StackerConfig, name string) (*Container, error) {
func (c *Container) BindMount(source string, dest string, extraOpts string) error {
createOpt := "create=dir"
stat, err := os.Stat(source)
if os.IsNotExist(err) {
return errors.Errorf("bind mount source %q does not exist, refusing bind mount: %s", source, err)
}
if err == nil && !stat.IsDir() {
createOpt = "create=file"
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/stacker/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,10 @@ func SetupLayerConfig(config types.StackerConfig, c *container.Container, l type
}

for _, bind := range l.Binds {
log.Debugf("bind mounting %q into container at %q", bind.Source, bind.Dest)
err = c.BindMount(bind.Source, bind.Dest, "")
if err != nil {
return err
return errors.Errorf("failed to bind mount %q at %q: %s", bind.Source, bind.Dest, err)
}
}

Expand Down

0 comments on commit 8fbf329

Please sign in to comment.