Skip to content

Commit

Permalink
show progress when images are being pushed
Browse files Browse the repository at this point in the history
  • Loading branch information
divolgin committed Oct 23, 2019
1 parent 64a7f01 commit c4bcef8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions ffi/airgap.go
Expand Up @@ -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,
Expand Down
17 changes: 9 additions & 8 deletions pkg/image/builder.go
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
Expand Down Expand Up @@ -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")
Expand All @@ -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, &copy.Options{
RemoveSignatures: true,
SignBy: "",
ReportWriter: nil,
ReportWriter: reportWriter,
SourceCtx: nil,
DestinationCtx: destCtx,
ForceManifestMIMEType: "",
Expand Down
3 changes: 3 additions & 0 deletions pkg/pull/pull.go
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/url"
"path/filepath"
Expand Down Expand Up @@ -38,6 +39,7 @@ type PullOptions struct {
RewriteImages bool
RewriteImageOptions RewriteImageOptions
HelmOptions []string
ReportWriter io.Writer
}

type RewriteImageOptions struct {
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion pkg/upstream/push_images.go
@@ -1,6 +1,7 @@
package upstream

import (
"io"
"io/ioutil"
"os"
"path"
Expand All @@ -18,6 +19,7 @@ type PushUpstreamImageOptions struct {
ImagesDir string
CreateAppDir bool
Log *logger.Logger
ReportWriter io.Writer
RegistryHost string
RegistryNamespace string
Username string
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit c4bcef8

Please sign in to comment.