From b2242c766cd3c2e92b7363506746e43009871d7e Mon Sep 17 00:00:00 2001 From: Ryan Harper Date: Tue, 4 Jun 2024 12:04:43 -0500 Subject: [PATCH] fix: check bind source file/dir exists 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 --- pkg/stacker/build.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/stacker/build.go b/pkg/stacker/build.go index c1d30f76..819b86d3 100644 --- a/pkg/stacker/build.go +++ b/pkg/stacker/build.go @@ -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