Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #779 from ulyssessouza/refactor-build
Browse files Browse the repository at this point in the history
Bump buildx and fix file finalizer breaking the stdout fix
  • Loading branch information
silvin-lubecki authored Jan 7, 2020
2 parents 3064a5d + 864442b commit 6d698be
Show file tree
Hide file tree
Showing 692 changed files with 137,249 additions and 56,462 deletions.
293 changes: 155 additions & 138 deletions Gopkg.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

required = ["github.com/wadey/gocovmerge"]

[[constraint]]
[[override]]
name = "github.com/docker/buildx"
version = "=v0.3.1"
revision = "709ef36b4f10a9389fd9a806657c48a969909d85"

[[override]]
name = "github.com/moby/buildkit"
Expand All @@ -46,7 +46,7 @@ required = ["github.com/wadey/gocovmerge"]

[[override]]
name = "github.com/containerd/containerd"
version = "v1.3.0"
revision = "97712c8ad73dd302d5d226e0384b2d86e5de2989"

[[override]]
name = "github.com/docker/cli"
Expand Down
55 changes: 36 additions & 19 deletions internal/commands/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import (
"strings"
"sync"

"github.com/deislabs/cnab-go/bundle"
cnab "github.com/deislabs/cnab-go/driver"
"github.com/docker/app/internal"
"github.com/docker/app/internal/packager"
"github.com/docker/app/types"

"github.com/containerd/console"
"github.com/deislabs/cnab-go/bundle"
cnab "github.com/deislabs/cnab-go/driver"
"github.com/docker/buildx/build"
"github.com/docker/buildx/driver"
_ "github.com/docker/buildx/driver/docker" // required to get default driver registered, see driver/docker/factory.go:14
Expand Down Expand Up @@ -86,28 +88,43 @@ func Cmd(dockerCli command.Cli) *cobra.Command {
return cmd
}

// FIXME: DO NOT SET THIS VARIABLE DIRECTLY! Use `getOutputFile`
// This global var prevents the file to be garbage collected and by that invalidated
// A an alternative fix for this would be writing the output to a bytes buffer and flushing to stdout.
// The impossibility here is that os.File is not an interface that a buffer can implement.
// Maybe `progress.NewPrinter` should implement an "os.File-like" interface just for its needs.
// See https://github.com/golang/go/issues/14106
var _outputFile *os.File
type File struct {
f *streams.Out
}

func getOutputFile(realOut *streams.Out, quiet bool) (*os.File, error) {
if _outputFile != nil {
return _outputFile, nil
}
func NewFile(f *streams.Out) console.File {
return File{f: f}
}

func (f File) Fd() uintptr {
return f.f.FD()
}

func (f File) Name() string {
return os.Stdout.Name()
}

func (f File) Read(p []byte) (n int, err error) {
return 0, nil
}

func (f File) Write(p []byte) (n int, err error) {
return f.f.Write(p)
}

func (f File) Close() error {
return nil
}

func getOutputFile(realOut *streams.Out, quiet bool) (console.File, error) {
if quiet {
var err error
_outputFile, err = os.Create(os.DevNull)
nullFile, err := os.Create(os.DevNull)
if err != nil {
return nil, err
}
return _outputFile, nil
return nullFile, nil
}
_outputFile = os.NewFile(realOut.FD(), os.Stdout.Name())
return _outputFile, nil
return NewFile(realOut), nil
}

func runBuild(dockerCli command.Cli, contextPath string, opt buildOptions) error {
Expand Down Expand Up @@ -212,7 +229,7 @@ func buildImageUsingBuildx(app *types.App, contextPath string, opt buildOptions,
ctx, cancel := context.WithCancel(appcontext.Context())
defer cancel()
const drivername = "buildx_buildkit_default"
d, err := driver.GetDriver(ctx, drivername, nil, dockerCli.Client(), nil, "", nil)
d, err := driver.GetDriver(ctx, drivername, nil, dockerCli.Client(), nil, nil, "", nil, "")
if err != nil {
return nil, err
}
Expand Down
15 changes: 0 additions & 15 deletions vendor/cloud.google.com/go/AUTHORS

This file was deleted.

40 changes: 0 additions & 40 deletions vendor/cloud.google.com/go/CONTRIBUTORS

This file was deleted.

24 changes: 18 additions & 6 deletions vendor/cloud.google.com/go/compute/metadata/metadata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions vendor/github.com/Masterminds/semver/LICENSE.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6d698be

Please sign in to comment.