Skip to content

Commit

Permalink
fix: Support http registries for pushing bundles (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmidyson committed Jun 5, 2023
1 parent 1d8d23a commit 2a4c1af
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 3 deletions.
14 changes: 11 additions & 3 deletions cmd/mindthegap/push/imagebundle/image_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func NewCommand(out output.Output) *cobra.Command {
}
destRemoteOpts := []remote.Option{remote.WithTransport(destTLSRoundTripper)}

var destNameOpts []name.Option
if flags.SkipTLSVerify(destRegistrySkipTLSVerify, destRegistryURI) {
destNameOpts = append(destNameOpts, name.Insecure)
}

keychain := authn.DefaultKeychain
if destRegistryUsername != "" && destRegistryPassword != "" {
keychain = authn.NewMultiKeychain(
Expand Down Expand Up @@ -132,6 +137,7 @@ func NewCommand(out output.Output) *cobra.Command {
sourceRemoteOpts,
destRegistryURI.Address(),
destRemoteOpts,
destNameOpts,
out,
prePushFuncs...,
)
Expand Down Expand Up @@ -168,7 +174,7 @@ type prePushFunc func(destRegistry, imageName string, imageTags ...string) error
func pushImages(
cfg config.ImagesConfig,
sourceRegistry string, sourceRemoteOpts []remote.Option,
destRegistry string, destRemoteOpts []remote.Option,
destRegistry string, destRemoteOpts []remote.Option, destNameOpts []name.Option,
out output.Output,
prePushFuncs ...prePushFunc,
) error {
Expand Down Expand Up @@ -199,14 +205,16 @@ func pushImages(
)

srcImage := fmt.Sprintf("%s/%s:%s", sourceRegistry, imageName, imageTag)
srcRef, err := name.ParseReference(srcImage, name.StrictValidation)
srcRef, err := name.ParseReference(srcImage, name.Insecure, name.StrictValidation)
if err != nil {
out.EndOperation(false)
return err
}

destImage := fmt.Sprintf("%s/%s:%s", destRegistry, imageName, imageTag)
dstRef, err := name.ParseReference(destImage, name.StrictValidation)
dstRef, err := name.ParseReference(
destImage,
append(destNameOpts, name.StrictValidation)...)
if err != nil {
out.EndOperation(false)
return err
Expand Down
62 changes: 62 additions & 0 deletions test/e2e/imagebundle/push_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,68 @@ var _ = Describe("Push Bundle", func() {
Eventually(done).Should(BeClosed())
})

It("With non-TLS", func() {
helpers.CreateBundle(
GinkgoT(),
bundleFile,
filepath.Join("testdata", "create-success.yaml"),
)

ipAddr := helpers.GetFirstNonLoopbackIP(GinkgoT())

port, err := freeport.GetFreePort()
Expect(err).NotTo(HaveOccurred())
reg, err := registry.NewRegistry(registry.Config{
StorageDirectory: filepath.Join(tmpDir, "registry"),
Host: ipAddr.String(),
Port: uint16(port),
})
Expect(err).NotTo(HaveOccurred())

done := make(chan struct{})
go func() {
defer GinkgoRecover()

Expect(reg.ListenAndServe()).To(Succeed())

close(done)
}()

helpers.WaitForTCPPort(GinkgoT(), ipAddr.String(), port)

cmd.SetArgs([]string{
"--image-bundle", bundleFile,
"--to-registry", fmt.Sprintf("http://%s:%d", ipAddr, port),
})

Expect(cmd.Execute()).To(Succeed())

testRoundTripper, err := httputils.TLSConfiguredRoundTripper(
remote.DefaultTransport,
net.JoinHostPort(ipAddr.String(), strconv.Itoa(port)),
true,
"",
)
Expect(err).NotTo(HaveOccurred())

helpers.ValidateImageIsAvailable(
GinkgoT(),
ipAddr.String(),
port,
"stefanprodan/podinfo",
"6.2.0",
[]*v1.Platform{{
OS: "linux",
Architecture: runtime.GOARCH,
}},
remote.WithTransport(testRoundTripper),
)

Expect(reg.Shutdown(context.Background())).To((Succeed()))

Eventually(done).Should(BeClosed())
})

It("Bundle does not exist", func() {
cmd.SetArgs([]string{
"--image-bundle", bundleFile,
Expand Down

0 comments on commit 2a4c1af

Please sign in to comment.