Provide full path to Docker config file

Add tests.  The tests assume a POSIX file system, but it seems many
other tests assume Linux, so perhaps this is not a problem, or at
least does not add a new problem.

Fixes #1235
This commit is contained in:
David Dooling
2020-05-06 10:02:47 -05:00
parent c0618a06c1
commit 8bfd370ef9
2 changed files with 50 additions and 6 deletions
+8 -6
View File
@@ -55,14 +55,16 @@ const (
UpstreamClientUaKey = "UPSTREAM_CLIENT_TYPE"
)
// DockerConfLocation returns the file system location of the Docker configuration
// from the DOCKER_CONFIG environment variable. If that variable is not set, it
// returns "/kaniko/.docker/config.json".
// DockerConfLocation returns the file system location of the Docker
// configuration file under the directory set in the DOCKER_CONFIG environment
// variable. If that variable is not set, it returns the OS-equivalent of
// "/kaniko/.docker/config.json".
func DockerConfLocation() string {
if dockerConfLocation := os.Getenv("DOCKER_CONFIG"); dockerConfLocation != "" {
return dockerConfLocation
configFile := "config.json"
if dockerConfDir := os.Getenv("DOCKER_CONFIG"); dockerConfDir != "" {
return filepath.Join(dockerConfDir, configFile)
}
return "/kaniko/.docker/config.json"
return string(os.PathSeparator) + filepath.Join("kaniko", ".docker", configFile)
}
func (w *withUserAgent) RoundTrip(r *http.Request) (*http.Response, error) {