Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit cdbd8af

Browse files
authored
Merge pull request #1328 from jonjohnsonjr/artifact-registry
Add pkg.dev to automagic config file population
2 parents 1231c77 + c428814 commit cdbd8af

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

pkg/executor/push.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,20 @@ func CheckPushPermissions(opts *config.KanikoOptions) error {
105105
continue
106106
}
107107

108+
registryName := destRef.Repository.Registry.Name()
108109
// Historically kaniko was pre-configured by default with gcr credential helper,
109110
// in here we keep the backwards compatibility by enabling the GCR helper only
110-
// when gcr.io is in one of the destinations.
111-
if strings.Contains(destRef.RegistryStr(), "gcr.io") {
111+
// when gcr.io (or pkg.dev) is in one of the destinations.
112+
if registryName == "gcr.io" || strings.HasSuffix(registryName, ".gcr.io") || strings.HasSuffix(registryName, ".pkg.dev") {
112113
// Checking for existence of docker.config as it's normally required for
113114
// authenticated registries and prevent overwriting user provided docker conf
114115
if _, err := fs.Stat(DockerConfLocation()); os.IsNotExist(err) {
115-
if err := execCommand("docker-credential-gcr", "configure-docker").Run(); err != nil {
116+
flags := fmt.Sprintf("--registries=%s", registryName)
117+
if err := execCommand("docker-credential-gcr", "configure-docker", flags).Run(); err != nil {
116118
return errors.Wrap(err, "error while configuring docker-credential-gcr helper")
117119
}
118120
}
119121
}
120-
registryName := destRef.Repository.Registry.Name()
121122
if opts.Insecure || opts.InsecureRegistries.Contains(registryName) {
122123
newReg, err := name.NewRegistry(registryName, name.WeakValidation, name.Insecure)
123124
if err != nil {

pkg/executor/push_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,12 @@ func TestCheckPushPermissions(t *testing.T) {
299299
}{
300300
{"gcr.io/test-image", true, false},
301301
{"gcr.io/test-image", false, true},
302+
{"us-docker.pkg.dev/test-image", true, false},
303+
{"us-docker.pkg.dev/test-image", false, true},
302304
{"localhost:5000/test-image", false, false},
303305
{"localhost:5000/test-image", false, true},
306+
{"notgcr.io/test-image", false, false},
307+
{"notgcr.io/test-image", false, true},
304308
}
305309

306310
execCommand = fakeExecCommand

0 commit comments

Comments
 (0)