Create constant for Docker conf location
This commit is contained in:
parent
8518b37ca1
commit
c56f16b163
|
|
@ -53,6 +53,7 @@ type withUserAgent struct {
|
||||||
|
|
||||||
const (
|
const (
|
||||||
UpstreamClientUaKey = "UPSTREAM_CLIENT_TYPE"
|
UpstreamClientUaKey = "UPSTREAM_CLIENT_TYPE"
|
||||||
|
DockerConfLocation = "/kaniko/.docker/config.json"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (w *withUserAgent) RoundTrip(r *http.Request) (*http.Response, error) {
|
func (w *withUserAgent) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||||
|
|
@ -129,7 +130,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("/kaniko/.docker/config.json"); 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")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -334,7 +334,6 @@ func TestCheckPushPermissionsGCR(t *testing.T) {
|
||||||
Destinations: []string{"gcr.io/test-image"},
|
Destinations: []string{"gcr.io/test-image"},
|
||||||
}
|
}
|
||||||
fs = afero.NewMemMapFs()
|
fs = afero.NewMemMapFs()
|
||||||
//afero.WriteFile(fs, "/kaniko/.docker/config.json", []byte(""), os.FileMode(0644))
|
|
||||||
CheckPushPermissions(&opts)
|
CheckPushPermissions(&opts)
|
||||||
if called != true {
|
if called != true {
|
||||||
t.Error("execCommand should have been called")
|
t.Error("execCommand should have been called")
|
||||||
|
|
@ -350,7 +349,7 @@ func TestCheckPushPermissionsGCRExistingDockerConf(t *testing.T) {
|
||||||
Destinations: []string{"gcr.io/test-image"},
|
Destinations: []string{"gcr.io/test-image"},
|
||||||
}
|
}
|
||||||
fs = afero.NewMemMapFs()
|
fs = afero.NewMemMapFs()
|
||||||
afero.WriteFile(fs, "/kaniko/.docker/config.json", []byte(""), os.FileMode(0644))
|
afero.WriteFile(fs, DockerConfLocation, []byte(""), os.FileMode(0644))
|
||||||
CheckPushPermissions(&opts)
|
CheckPushPermissions(&opts)
|
||||||
if called != false {
|
if called != false {
|
||||||
t.Error("execCommand should not have been called")
|
t.Error("execCommand should not have been called")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue