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

Commit

Permalink
Use fork of buildx to fix file finalizer
Browse files Browse the repository at this point in the history
Signed-off-by: Ulysses Souza <[email protected]>
  • Loading branch information
ulyssessouza committed Jan 7, 2020
1 parent 3064a5d commit 1573491
Show file tree
Hide file tree
Showing 13 changed files with 586 additions and 52 deletions.
15 changes: 9 additions & 6 deletions Gopkg.lock

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

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

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

[[constraint]]
#[[constraint]]
# name = "github.com/docker/buildx"
# version = "=v0.3.1"

[[override]]
name = "github.com/docker/buildx"
version = "=v0.3.1"
source = "github.com/ulyssessouza/buildx"
revision = "5941345e21ebda43723a475380135fe3741d6b3c"

[[override]]
name = "github.com/moby/buildkit"
Expand All @@ -48,6 +53,11 @@ required = ["github.com/wadey/gocovmerge"]
name = "github.com/containerd/containerd"
version = "v1.3.0"

[[override]]
name = "github.com/containerd/console"
source = "github.com/ulyssessouza/console"
revision = "f652dc3e99a9f4aa760deb9b4b28edb7c4e5001a"

[[override]]
name = "github.com/docker/cli"
revision = "37f9a88c696ae81be14c1697bd083d6421b4933c"
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
19 changes: 11 additions & 8 deletions vendor/github.com/containerd/console/console.go

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

6 changes: 3 additions & 3 deletions vendor/github.com/containerd/console/console_unix.go

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

4 changes: 2 additions & 2 deletions vendor/github.com/containerd/console/console_windows.go

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

3 changes: 3 additions & 0 deletions vendor/github.com/docker/buildx/driver/driver.go

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

28 changes: 17 additions & 11 deletions vendor/github.com/docker/buildx/driver/manager.go

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

Loading

0 comments on commit 1573491

Please sign in to comment.