Skip to content

Commit

Permalink
report build context progress
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldwan committed May 19, 2021
1 parent daffb6a commit bd2abdd
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions internal/build/imgsrc/dockerfile_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/docker/docker/api/types"
dockerclient "github.com/docker/docker/client"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/progress"
"github.com/docker/docker/pkg/streamformatter"
"github.com/docker/docker/pkg/stringid"
"github.com/moby/buildkit/util/progress/progressui"
"github.com/moby/term"
Expand All @@ -32,6 +34,22 @@ func (ds *dockerfileBuilder) Name() string {
return "Dockerfile"
}

// lastProgressOutput is the same as progress.Output except
// that it only output with the last update. It is used in
// non terminal scenarios to suppress verbose messages
type lastProgressOutput struct {
output progress.Output
}

// WriteProgress formats progress information from a ProgressReader.
func (out *lastProgressOutput) WriteProgress(prog progress.Progress) error {
if !prog.LastUpdate {
return nil
}

return out.output.WriteProgress(prog)
}

func (ds *dockerfileBuilder) Run(ctx context.Context, dockerFactory *dockerClientFactory, streams *iostreams.IOStreams, opts ImageOptions) (*DeploymentImage, error) {
if !dockerFactory.mode.IsAvailable() {
terminal.Debug("docker daemon not available, skipping")
Expand Down Expand Up @@ -99,6 +117,14 @@ func (ds *dockerfileBuilder) Run(ctx context.Context, dockerFactory *dockerClien
}
cmdfmt.PrintDone(streams.ErrOut, "Creating build context done")

// Setup an upload progress bar
progressOutput := streamformatter.NewProgressOutput(streams.Out)
if !streams.IsStdoutTTY() {
progressOutput = &lastProgressOutput{output: progressOutput}
}

r = progress.NewProgressReader(r, progressOutput, 0, "", "Sending build context to Docker daemon")

var imageID string

cmdfmt.PrintBegin(streams.ErrOut, "Building image with Docker")
Expand Down

0 comments on commit bd2abdd

Please sign in to comment.