Use DOCKER_CONFIG for docker config location
If the DOCKER_CONFIG environment variable is set, use it when determining if the Docker config file exists. Fall back to kaniko default if it the DOCKER_CONFIG environment variable is not set. Fixes #1228
This commit is contained in:
parent
d8c786c777
commit
0871dfd6ab
|
|
@ -53,9 +53,18 @@ type withUserAgent struct {
|
||||||
|
|
||||||
const (
|
const (
|
||||||
UpstreamClientUaKey = "UPSTREAM_CLIENT_TYPE"
|
UpstreamClientUaKey = "UPSTREAM_CLIENT_TYPE"
|
||||||
DockerConfLocation = "/kaniko/.docker/config.json"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 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".
|
||||||
|
func DockerConfLocation() string {
|
||||||
|
if dockerConfLocation := os.Getenv("DOCKER_CONFIG"); dockerConfLocation != "" {
|
||||||
|
return dockerConfLocation
|
||||||
|
}
|
||||||
|
return "/kaniko/.docker/config.json"
|
||||||
|
}
|
||||||
|
|
||||||
func (w *withUserAgent) RoundTrip(r *http.Request) (*http.Response, error) {
|
func (w *withUserAgent) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||||
ua := []string{fmt.Sprintf("kaniko/%s", version.Version())}
|
ua := []string{fmt.Sprintf("kaniko/%s", version.Version())}
|
||||||
if upstream := os.Getenv(UpstreamClientUaKey); upstream != "" {
|
if upstream := os.Getenv(UpstreamClientUaKey); upstream != "" {
|
||||||
|
|
@ -130,7 +139,7 @@ func CheckPushPermissions(opts *config.KanikoOptions) error {
|
||||||
if strings.Contains(destRef.RegistryStr(), "gcr.io") {
|
if strings.Contains(destRef.RegistryStr(), "gcr.io") {
|
||||||
// Checking for existence of docker.config as it's normally required for
|
// Checking for existence of docker.config as it's normally required for
|
||||||
// authenticated registries and prevent overwriting user provided docker conf
|
// authenticated registries and prevent overwriting user provided docker conf
|
||||||
if _, err := fs.Stat(DockerConfLocation); os.IsNotExist(err) {
|
if _, err := fs.Stat(DockerConfLocation()); os.IsNotExist(err) {
|
||||||
if err := execCommand("docker-credential-gcr", "configure-docker").Run(); err != nil {
|
if err := execCommand("docker-credential-gcr", "configure-docker").Run(); err != nil {
|
||||||
return errors.Wrap(err, "error while configuring docker-credential-gcr helper")
|
return errors.Wrap(err, "error while configuring docker-credential-gcr helper")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -354,8 +354,8 @@ func TestCheckPushPermissions(t *testing.T) {
|
||||||
Destinations: []string{test.Destination},
|
Destinations: []string{test.Destination},
|
||||||
}
|
}
|
||||||
if test.ExistingConfig {
|
if test.ExistingConfig {
|
||||||
afero.WriteFile(fs, DockerConfLocation, []byte(""), os.FileMode(0644))
|
afero.WriteFile(fs, DockerConfLocation(), []byte(""), os.FileMode(0644))
|
||||||
defer fs.Remove(DockerConfLocation)
|
defer fs.Remove(DockerConfLocation())
|
||||||
}
|
}
|
||||||
CheckPushPermissions(&opts)
|
CheckPushPermissions(&opts)
|
||||||
if test.ShouldCallExecCommand != calledExecCommand {
|
if test.ShouldCallExecCommand != calledExecCommand {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue