Merge pull request #4389 from TomSweeneyRedHat/dev/tsweeney/contextdir

Validate contextdir on build
This commit is contained in:
Matthew Heon
2019-11-04 10:08:17 -05:00
committed by GitHub
2 changed files with 13 additions and 0 deletions

View File

@ -238,6 +238,9 @@ func buildCmd(c *cliconfig.BuildValues) error {
if contextDir == "" {
return errors.Errorf("no context directory specified, and no containerfile specified")
}
if !fileIsDir(contextDir) {
return errors.Errorf("context must be a directory: %v", contextDir)
}
if len(containerfiles) == 0 {
if checkIfFileExists(filepath.Join(contextDir, "Containerfile")) {
containerfiles = append(containerfiles, filepath.Join(contextDir, "Containerfile"))

View File

@ -74,3 +74,13 @@ func checkIfFileExists(name string) bool {
}
return !file.IsDir()
}
// Check if a file is or is not a directory
func fileIsDir(name string) bool {
file, err := os.Stat(name)
// All errors return file == nil
if err != nil {
return false
}
return file.IsDir()
}