Allow DOCKER_CONFIG to be a filename (#1409)

* Allow DOCKER_CONFIG to be a filename

* UnitTest: DockerConfLocation must return a file if it is existent and passed using env, or default if the file is incorrect
This commit is contained in:
Akram Ben Aissi
2020-09-30 16:45:34 -07:00
committed by GitHub
parent b4824582fb
commit ab768b5d26
2 changed files with 88 additions and 14 deletions
+12 -2
View File
@@ -67,8 +67,18 @@ const (
// "/kaniko/.docker/config.json".
func DockerConfLocation() string {
configFile := "config.json"
if dockerConfDir := os.Getenv("DOCKER_CONFIG"); dockerConfDir != "" {
return filepath.Join(dockerConfDir, configFile)
if dockerConfig := os.Getenv("DOCKER_CONFIG"); dockerConfig != "" {
file, err := os.Stat(dockerConfig)
if err == nil {
if file.IsDir() {
return filepath.Join(dockerConfig, configFile)
}
} else {
if os.IsNotExist(err) {
return string(os.PathSeparator) + filepath.Join("kaniko", ".docker", configFile)
}
}
return filepath.Clean(dockerConfig)
}
return string(os.PathSeparator) + filepath.Join("kaniko", ".docker", configFile)
}