Skip to content

Commit

Permalink
Merge pull request #220 from dlion/allow-multiple-insecure-registries
Browse files Browse the repository at this point in the history
Initialize the map only once to support multiple registries
  • Loading branch information
natalieparellano authored Sep 19, 2023
2 parents a995227 + 03ffcd2 commit 4ec9360
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion remote/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@ func WithPreviousImage(imageName string) ImageOption {
// insecure parameter allows image references to be fetched without TLS.
func WithRegistrySetting(repository string, insecure bool) ImageOption {
return func(opts *options) error {
opts.registrySettings = make(map[string]registrySetting)
if len(opts.registrySettings) == 0 {
opts.registrySettings = make(map[string]registrySetting)
}

opts.registrySettings[repository] = registrySetting{
insecure: insecure,
}

return nil
}
}
Expand Down
12 changes: 12 additions & 0 deletions remote/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ func testImage(t *testing.T, when spec.G, it spec.S) {
h.AssertError(t, err, "http://")
})

it("tries to pull the image from an insecure registry if WithRegistrySettings insecure has been set, it works with multiple registries", func() {
_, err := remote.NewImage(
repoName,
authn.DefaultKeychain,
remote.FromBaseImage("myother-insecure-registry.com/repo/superbase"),
remote.WithRegistrySetting("myregistry.domain.com", true),
remote.WithRegistrySetting("myother-insecure-registry.com", true),
)

h.AssertError(t, err, "http://myother-insecure-registry.com")
})

it("sets the initial state from a windows/amd64 base image", func() {
baseImageName := "mcr.microsoft.com/windows/nanoserver@sha256:06281772b6a561411d4b338820d94ab1028fdeb076c85350bbc01e80c4bfa2b4"
existingLayerSha := "sha256:26fd2d9d4c64a4f965bbc77939a454a31b607470f430b5d69fc21ded301fa55e"
Expand Down

0 comments on commit 4ec9360

Please sign in to comment.