Skip to content

Commit

Permalink
Merge pull request #9212 from csrwng/image_progress
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored Jun 10, 2016
2 parents 3480ccb + 1497ef6 commit aa31f13
Show file tree
Hide file tree
Showing 8 changed files with 345 additions and 258 deletions.
32 changes: 6 additions & 26 deletions pkg/bootstrap/docker/dockerhelper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/golang/glog"

starterrors "github.com/openshift/origin/pkg/bootstrap/docker/errors"
"github.com/openshift/origin/pkg/cmd/util/pullprogress"
"github.com/openshift/origin/pkg/util/docker/dockerfile/builder/imageprogress"
)

const openShiftInsecureCIDR = "172.30.0.0/16"
Expand Down Expand Up @@ -120,31 +120,11 @@ func (h *Helper) CheckAndPull(image string, out io.Writer) error {
}
glog.V(5).Infof("Image %q not found. Pulling", image)
fmt.Fprintf(out, "Pulling image %s\n", image)
extracting := false
var outputStream io.Writer
writeProgress := func(r *pullprogress.ProgressReport) {
if extracting {
return
}
if r.Downloading == 0 && r.Waiting == 0 && r.Extracting > 0 {
fmt.Fprintf(out, "Extracting\n")
extracting = true
return
}
plural := "s"
if r.Downloading == 1 {
plural = " "
}
fmt.Fprintf(out, "Downloading %d layer%s (%3.0f%%)", r.Downloading, plural, r.DownloadPct)
if r.Waiting > 0 {
fmt.Fprintf(out, ", %d waiting\n", r.Waiting)
} else {
fmt.Fprintf(out, "\n")
}
logProgress := func(s string) {
fmt.Fprintf(out, "%s\n", s)
}
if !glog.V(5) {
outputStream = pullprogress.NewPullProgressWriter(writeProgress)
} else {
outputStream := imageprogress.NewPullWriter(logProgress)
if glog.V(5) {
outputStream = out
}
err = h.client.PullImage(docker.PullImageOptions{
Expand All @@ -155,7 +135,7 @@ func (h *Helper) CheckAndPull(image string, out io.Writer) error {
if err != nil {
return starterrors.NewError("error pulling Docker image %s", image).WithCause(err)
}
fmt.Fprintf(out, "Image pull comlete\n")
fmt.Fprintf(out, "Image pull complete\n")
return nil
}

Expand Down
18 changes: 13 additions & 5 deletions pkg/build/builder/dockerutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (
"strings"
"time"

s2iapi "github.com/openshift/source-to-image/pkg/api"
"github.com/docker/docker/pkg/parsers"
docker "github.com/fsouza/go-dockerclient"
"k8s.io/kubernetes/pkg/util/interrupt"
utilruntime "k8s.io/kubernetes/pkg/util/runtime"

"github.com/docker/docker/pkg/parsers"
docker "github.com/fsouza/go-dockerclient"
s2iapi "github.com/openshift/source-to-image/pkg/api"
"github.com/openshift/source-to-image/pkg/tar"

"github.com/openshift/origin/pkg/util/docker/dockerfile/builder/imageprogress"
)

var (
Expand Down Expand Up @@ -55,12 +57,18 @@ type DockerClient interface {
// If any other scenario the push will fail, without retries.
func pushImage(client DockerClient, name string, authConfig docker.AuthConfiguration) error {
repository, tag := docker.ParseRepositoryTag(name)
logProgress := func(s string) {
glog.V(1).Infof("%s", s)
}
opts := docker.PushImageOptions{
Name: repository,
Tag: tag,
Name: repository,
Tag: tag,
OutputStream: imageprogress.NewPushWriter(logProgress),
RawJSONStream: true,
}
if glog.Is(5) {
opts.OutputStream = os.Stderr
opts.RawJSONStream = false
}
var err error
var retriableError = false
Expand Down
4 changes: 2 additions & 2 deletions pkg/build/builder/sti.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (s *S2IBuilder) Build() error {
} else {
glog.V(2).Infof("No push secret provided")
}
glog.V(1).Infof("Pushing %s image ...", pushTag)
glog.V(1).Infof("Pushing image %s ...", pushTag)
if err := pushImage(s.dockerClient, pushTag, pushAuthConfig); err != nil {
// write extended error message to assist in problem resolution
msg := fmt.Sprintf("Failed to push image. Response from registry is: %v", err)
Expand All @@ -281,7 +281,7 @@ func (s *S2IBuilder) Build() error {
}
return errors.New(msg)
}
glog.V(1).Infof("Successfully pushed %s", pushTag)
glog.V(1).Infof("Push successful")
}
return nil
}
Expand Down
223 changes: 0 additions & 223 deletions pkg/cmd/util/pullprogress/writer.go

This file was deleted.

18 changes: 16 additions & 2 deletions pkg/util/docker/dockerfile/builder/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"github.com/fsouza/go-dockerclient/external/github.com/docker/docker/pkg/archive"
"github.com/fsouza/go-dockerclient/external/github.com/docker/docker/pkg/fileutils"
"github.com/golang/glog"

"github.com/openshift/origin/pkg/util/docker/dockerfile/builder/imageprogress"
)

// ClientExecutor can run Docker builds from a Docker client.
Expand Down Expand Up @@ -298,10 +300,22 @@ func (e *ClientExecutor) LoadImage(from string) (*docker.Image, error) {
}

var lastErr error
outputProgress := func(s string) {
e.LogFn("%s", s)
}
for _, config := range auth {
// TODO: handle IDs?
// TODO: use RawJSONStream:true and handle the output nicely
if err = e.Client.PullImage(docker.PullImageOptions{Repository: from, OutputStream: e.Out, Tag: tag}, config); err == nil {
pullImageOptions := docker.PullImageOptions{
Repository: from,
Tag: tag,
OutputStream: imageprogress.NewPullWriter(outputProgress),
RawJSONStream: true,
}
if glog.V(5) {
pullImageOptions.OutputStream = os.Stderr
pullImageOptions.RawJSONStream = false
}
if err = e.Client.PullImage(pullImageOptions, config); err == nil {
break
}
lastErr = err
Expand Down
Loading

0 comments on commit aa31f13

Please sign in to comment.