Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support http registries for pushing bundles #405

Merged
merged 1 commit into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions cmd/mindthegap/push/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func NewCommand(out output.Output, bundleCmdName string) *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 @@ -133,6 +138,7 @@ func NewCommand(out output.Output, bundleCmdName string) *cobra.Command {
sourceRemoteOpts,
destRegistryURI.Address(),
destRemoteOpts,
destNameOpts,
out,
prePushFuncs...,
)
Expand Down Expand Up @@ -190,7 +196,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 @@ -221,14 +227,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_image_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,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