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

Commit 1573491

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

File tree

13 files changed

+586
-52
lines changed

13 files changed

+586
-52
lines changed

Gopkg.lock

Lines changed: 9 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
@@ -13,11 +13,13 @@ import (
1313
"strings"
1414
"sync"
1515

16-
"github.com/deislabs/cnab-go/bundle"
17-
cnab "github.com/deislabs/cnab-go/driver"
1816
"github.com/docker/app/internal"
1917
"github.com/docker/app/internal/packager"
2018
"github.com/docker/app/types"
19+
20+
"github.com/containerd/console"
21+
"github.com/deislabs/cnab-go/bundle"
22+
cnab "github.com/deislabs/cnab-go/driver"
2123
"github.com/docker/buildx/build"
2224
"github.com/docker/buildx/driver"
2325
_ "github.com/docker/buildx/driver/docker" // required to get default driver registered, see driver/docker/factory.go:14
@@ -86,28 +88,43 @@ func Cmd(dockerCli command.Cli) *cobra.Command {
8688
return cmd
8789
}
8890

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

97-
func getOutputFile(realOut *streams.Out, quiet bool) (*os.File, error) {
98-
if _outputFile != nil {
99-
return _outputFile, nil
100-
}
95+
func NewFile(f *streams.Out) console.File {
96+
return File{f: f}
97+
}
98+
99+
func (f File) Fd() uintptr {
100+
return f.f.FD()
101+
}
102+
103+
func (f File) Name() string {
104+
return os.Stdout.Name()
105+
}
106+
107+
func (f File) Read(p []byte) (n int, err error) {
108+
return 0, nil
109+
}
110+
111+
func (f File) Write(p []byte) (n int, err error) {
112+
return f.f.Write(p)
113+
}
114+
115+
func (f File) Close() error {
116+
return nil
117+
}
118+
119+
func getOutputFile(realOut *streams.Out, quiet bool) (console.File, error) {
101120
if quiet {
102-
var err error
103-
_outputFile, err = os.Create(os.DevNull)
121+
nullFile, err := os.Create(os.DevNull)
104122
if err != nil {
105123
return nil, err
106124
}
107-
return _outputFile, nil
125+
return nullFile, nil
108126
}
109-
_outputFile = os.NewFile(realOut.FD(), os.Stdout.Name())
110-
return _outputFile, nil
127+
return NewFile(realOut), nil
111128
}
112129

113130
func runBuild(dockerCli command.Cli, contextPath string, opt buildOptions) error {
@@ -212,7 +229,7 @@ func buildImageUsingBuildx(app *types.App, contextPath string, opt buildOptions,
212229
ctx, cancel := context.WithCancel(appcontext.Context())
213230
defer cancel()
214231
const drivername = "buildx_buildkit_default"
215-
d, err := driver.GetDriver(ctx, drivername, nil, dockerCli.Client(), nil, "", nil)
232+
d, err := driver.GetDriver(ctx, drivername, nil, dockerCli.Client(), nil, nil, "", nil, "")
216233
if err != nil {
217234
return nil, err
218235
}

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)