Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 3411212

Browse files
committed
Use fork of buildx to fix file finalizer
Signed-off-by: Ulysses Souza <[email protected]>
1 parent d119541 commit 3411212

13 files changed

Lines changed: 588 additions & 52 deletions

File tree

Gopkg.lock

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121

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

24-
[[constraint]]
24+
#[[constraint]]
25+
# name = "github.com/docker/buildx"
26+
# version = "=v0.3.1"
27+
28+
[[override]]
2529
name = "github.com/docker/buildx"
26-
version = "=v0.3.1"
30+
source = "github.com/ulyssessouza/buildx"
31+
revision = "5941345e21ebda43723a475380135fe3741d6b3c"
2732

2833
[[override]]
2934
name = "github.com/moby/buildkit"
@@ -48,6 +53,11 @@ required = ["github.com/wadey/gocovmerge"]
4853
name = "github.com/containerd/containerd"
4954
version = "v1.3.0"
5055

56+
[[override]]
57+
name = "github.com/containerd/console"
58+
source = "github.com/ulyssessouza/console"
59+
revision = "f652dc3e99a9f4aa760deb9b4b28edb7c4e5001a"
60+
5161
[[override]]
5262
name = "github.com/docker/cli"
5363
revision = "37f9a88c696ae81be14c1697bd083d6421b4933c"

internal/commands/build/build.go

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ import (
1111
"strconv"
1212
"strings"
1313

14-
"github.com/deislabs/cnab-go/bundle"
15-
cnab "github.com/deislabs/cnab-go/driver"
1614
"github.com/docker/app/internal"
1715
"github.com/docker/app/internal/packager"
1816
"github.com/docker/app/types"
17+
18+
"github.com/containerd/console"
19+
"github.com/deislabs/cnab-go/bundle"
20+
cnab "github.com/deislabs/cnab-go/driver"
1921
"github.com/docker/buildx/build"
2022
"github.com/docker/buildx/driver"
2123
_ "github.com/docker/buildx/driver/docker" // required to get default driver registered, see driver/docker/factory.go:14
@@ -76,28 +78,43 @@ func Cmd(dockerCli command.Cli) *cobra.Command {
7678
return cmd
7779
}
7880

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

87-
func getOutputFile(realOut *streams.Out, quiet bool) (*os.File, error) {
88-
if _outputFile != nil {
89-
return _outputFile, nil
90-
}
85+
func NewFile(f *streams.Out) console.File {
86+
return File{f: f}
87+
}
88+
89+
func (f File) Fd() uintptr {
90+
return f.f.FD()
91+
}
92+
93+
func (f File) Name() string {
94+
return os.Stdout.Name()
95+
}
96+
97+
func (f File) Read(p []byte) (n int, err error) {
98+
return 0, nil
99+
}
100+
101+
func (f File) Write(p []byte) (n int, err error) {
102+
return f.f.Write(p)
103+
}
104+
105+
func (f File) Close() error {
106+
return nil
107+
}
108+
109+
func getOutputFile(realOut *streams.Out, quiet bool) (console.File, error) {
91110
if quiet {
92-
var err error
93-
_outputFile, err = os.Create(os.DevNull)
111+
nullFile, err := os.Create(os.DevNull)
94112
if err != nil {
95113
return nil, err
96114
}
97-
return _outputFile, nil
115+
return nullFile, nil
98116
}
99-
_outputFile = os.NewFile(realOut.FD(), os.Stdout.Name())
100-
return _outputFile, nil
117+
return NewFile(realOut), nil
101118
}
102119

103120
func runBuild(dockerCli command.Cli, contextPath string, opt buildOptions) error {
@@ -174,7 +191,7 @@ func buildImageUsingBuildx(app *types.App, contextPath string, opt buildOptions,
174191
ctx, cancel := context.WithCancel(appcontext.Context())
175192
defer cancel()
176193
const drivername = "buildx_buildkit_default"
177-
d, err := driver.GetDriver(ctx, drivername, nil, dockerCli.Client(), nil, "", nil)
194+
d, err := driver.GetDriver(ctx, drivername, nil, dockerCli.Client(), nil, nil, "", nil, "")
178195
if err != nil {
179196
return nil, err
180197
}

vendor/github.com/containerd/console/console.go

Lines changed: 11 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containerd/console/console_unix.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containerd/console/console_windows.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/docker/buildx/driver/driver.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/docker/buildx/driver/manager.go

Lines changed: 17 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)