diff --git a/ffi/airgap.go b/ffi/airgap.go index fbdb3b2eb6..3cafde5235 100644 --- a/ffi/airgap.go +++ b/ffi/airgap.go @@ -91,6 +91,7 @@ func PullFromAirgap(socket, licenseData, airgapDir, downstream, outputFile, regi RootDir: tmpRoot, ExcludeAdminConsole: true, RewriteImages: true, + ReportWriter: statusClient.getOutputWriter(), RewriteImageOptions: pull.RewriteImageOptions{ ImageFiles: filepath.Join(airgapDir, "images"), Host: registryHost, diff --git a/pkg/image/builder.go b/pkg/image/builder.go index 0705269ffb..9b9f9e93c8 100644 --- a/pkg/image/builder.go +++ b/pkg/image/builder.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "io" "io/ioutil" "net/http" "os" @@ -263,7 +264,7 @@ func (ref *ImageRef) pathInBundle(formatPrefix string) string { return filepath.Join(path...) } -func CopyFromFileToRegistry(path string, name string, tag string, digest string, username string, password string) error { +func CopyFromFileToRegistry(path string, name string, tag string, digest string, auth RegistryAuth, reportWriter io.Writer) error { policy, err := signature.NewPolicyFromBytes(imagePolicy) if err != nil { return errors.Wrap(err, "failed to read default policy") @@ -288,27 +289,27 @@ func CopyFromFileToRegistry(path string, name string, tag string, digest string, DockerInsecureSkipTLSVerify: types.OptionalBoolTrue, } - if username != "" && password != "" { + if auth.Username != "" && auth.Password != "" { registryHost := reference.Domain(destRef.DockerReference()) if registry.IsECREndpoint(registryHost) { - login, err := registry.GetECRLogin(registryHost, username, password) + login, err := registry.GetECRLogin(registryHost, auth.Username, auth.Password) if err != nil { return errors.Wrap(err, "failed to get ECR login") } - username = login.Username - password = login.Password + auth.Username = login.Username + auth.Password = login.Password } destCtx.DockerAuthConfig = &types.DockerAuthConfig{ - Username: username, - Password: password, + Username: auth.Username, + Password: auth.Password, } } _, err = copy.Image(context.Background(), policyContext, destRef, srcRef, ©.Options{ RemoveSignatures: true, SignBy: "", - ReportWriter: nil, + ReportWriter: reportWriter, SourceCtx: nil, DestinationCtx: destCtx, ForceManifestMIMEType: "", diff --git a/pkg/pull/pull.go b/pkg/pull/pull.go index 3abbad9161..9658f411aa 100644 --- a/pkg/pull/pull.go +++ b/pkg/pull/pull.go @@ -4,6 +4,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "io" "io/ioutil" "net/url" "path/filepath" @@ -38,6 +39,7 @@ type PullOptions struct { RewriteImages bool RewriteImageOptions RewriteImageOptions HelmOptions []string + ReportWriter io.Writer } type RewriteImageOptions struct { @@ -160,6 +162,7 @@ func Pull(upstreamURI string, pullOptions PullOptions) (string, error) { ImagesDir: imagesDirFromOptions(u, pullOptions), CreateAppDir: pullOptions.CreateAppDir, Log: log, + ReportWriter: pullOptions.ReportWriter, RegistryHost: pullOptions.RewriteImageOptions.Host, RegistryNamespace: pullOptions.RewriteImageOptions.Namespace, Username: pullOptions.RewriteImageOptions.Username, diff --git a/pkg/upstream/push_images.go b/pkg/upstream/push_images.go index 572ac01e40..10301eb0fb 100644 --- a/pkg/upstream/push_images.go +++ b/pkg/upstream/push_images.go @@ -1,6 +1,7 @@ package upstream import ( + "io" "io/ioutil" "os" "path" @@ -18,6 +19,7 @@ type PushUpstreamImageOptions struct { ImagesDir string CreateAppDir bool Log *logger.Logger + ReportWriter io.Writer RegistryHost string RegistryNamespace string Username string @@ -61,7 +63,9 @@ func (u *Upstream) TagAndPushUpstreamImages(options PushUpstreamImageOptions) ([ // copy to the registry options.Log.ChildActionWithSpinner("Pushing image %s:%s", rewrittenImage.NewName, rewrittenImage.NewTag) - err = image.CopyFromFileToRegistry(path, rewrittenImage.NewName, rewrittenImage.NewTag, rewrittenImage.Digest, options.Username, options.Password) + + registryAuth := image.RegistryAuth{Username: options.Username, Password: options.Password} + err = image.CopyFromFileToRegistry(path, rewrittenImage.NewName, rewrittenImage.NewTag, rewrittenImage.Digest, registryAuth, options.ReportWriter) if err != nil { options.Log.FinishChildSpinner() return errors.Wrap(err, "failed to push image")