Skip to content

Commit

Permalink
Merge pull request #1328 from jonjohnsonjr/artifact-registry
Browse files Browse the repository at this point in the history
Add pkg.dev to automagic config file population
  • Loading branch information
tejal29 authored Jun 23, 2020
2 parents 1231c77 + c428814 commit cdbd8af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/executor/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,20 @@ func CheckPushPermissions(opts *config.KanikoOptions) error {
continue
}

registryName := destRef.Repository.Registry.Name()
// Historically kaniko was pre-configured by default with gcr credential helper,
// in here we keep the backwards compatibility by enabling the GCR helper only
// when gcr.io is in one of the destinations.
if strings.Contains(destRef.RegistryStr(), "gcr.io") {
// when gcr.io (or pkg.dev) is in one of the destinations.
if registryName == "gcr.io" || strings.HasSuffix(registryName, ".gcr.io") || strings.HasSuffix(registryName, ".pkg.dev") {
// Checking for existence of docker.config as it's normally required for
// authenticated registries and prevent overwriting user provided docker conf
if _, err := fs.Stat(DockerConfLocation()); os.IsNotExist(err) {
if err := execCommand("docker-credential-gcr", "configure-docker").Run(); err != nil {
flags := fmt.Sprintf("--registries=%s", registryName)
if err := execCommand("docker-credential-gcr", "configure-docker", flags).Run(); err != nil {
return errors.Wrap(err, "error while configuring docker-credential-gcr helper")
}
}
}
registryName := destRef.Repository.Registry.Name()
if opts.Insecure || opts.InsecureRegistries.Contains(registryName) {
newReg, err := name.NewRegistry(registryName, name.WeakValidation, name.Insecure)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/executor/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,12 @@ func TestCheckPushPermissions(t *testing.T) {
}{
{"gcr.io/test-image", true, false},
{"gcr.io/test-image", false, true},
{"us-docker.pkg.dev/test-image", true, false},
{"us-docker.pkg.dev/test-image", false, true},
{"localhost:5000/test-image", false, false},
{"localhost:5000/test-image", false, true},
{"notgcr.io/test-image", false, false},
{"notgcr.io/test-image", false, true},
}

execCommand = fakeExecCommand
Expand Down

0 comments on commit cdbd8af

Please sign in to comment.