Skip to content

Commit

Permalink
fix: check bind source file/dir exists
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 committed Jun 4, 2024
1 parent d3f8ebd commit b2242c7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/stacker/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,12 @@ func SetupLayerConfig(config types.StackerConfig, c *container.Container, l type
}

for _, bind := range l.Binds {
_, err := os.Stat(bind.Source)
// c.BindMount allows files to not exist and will create them, but not so for directories.
if os.IsNotExist(err) {
log.Errorf("bind mount source %q does not exist, refusing bind mount: %s", bind.Source, err)
return fmt.Errorf("bind mount source %q does not exist, refusing bind mount: %s", bind.Source, err)
}
err = c.BindMount(bind.Source, bind.Dest, "")
if err != nil {
return err
Expand Down

0 comments on commit b2242c7

Please sign in to comment.