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
commit 8e5aad97dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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()
}