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

Commit 4c12639

Browse files
ndeloofeunomie
andcommitted
naming things...
Co-Authored-By: Yves Brissaud <[email protected]> Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 0d85dfb commit 4c12639

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

internal/commands/build/build.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,16 @@ func Cmd(dockerCli command.Cli) *cobra.Command {
6565
}
6666

6767
func runBuild(dockerCli command.Cli, application string, opt buildOptions) (reference.Named, error) {
68-
ctx := appcontext.Context()
69-
info, err := dockerCli.Client().Info(ctx)
68+
err := checkMinimalEngineVersion(dockerCli)
7069
if err != nil {
7170
return nil, err
7271
}
73-
majorVersion, err := strconv.Atoi(info.ServerVersion[:strings.IndexRune(info.ServerVersion, '.')])
72+
73+
var ref reference.Named
74+
ref, err = packager.GetNamedTagged(opt.tag)
7475
if err != nil {
7576
return nil, err
7677
}
77-
if majorVersion < 19 {
78-
return nil, errors.New("'build' require docker engine 19.03 or later")
79-
}
8078

8179
app, err := packager.Extract(application)
8280
if err != nil {
@@ -101,6 +99,8 @@ func runBuild(dockerCli command.Cli, application string, opt buildOptions) (refe
10199

102100
debugBuildOpts(buildopts)
103101

102+
ctx, cancel := context.WithCancel(appcontext.Context())
103+
defer cancel()
104104
d, err := driver.GetDriver(ctx, "buildx_buildkit_default", nil, dockerCli.Client(), nil, "", nil)
105105
if err != nil {
106106
return nil, err
@@ -112,25 +112,17 @@ func runBuild(dockerCli command.Cli, application string, opt buildOptions) (refe
112112
},
113113
}
114114

115-
ctx2, cancel := context.WithCancel(ctx)
116-
defer cancel()
117-
118-
pw := progress.NewPrinter(ctx2, os.Stderr, opt.progress)
115+
pw := progress.NewPrinter(ctx, os.Stderr, opt.progress)
119116

120117
// We rely on buildx "docker" builder integrated in docker engine, so don't nee a DockerAPI here
121-
resp, err := build.Build(ctx2, driverInfo, buildopts, nil, dockerCli.ConfigFile(), pw)
118+
resp, err := build.Build(ctx, driverInfo, buildopts, nil, dockerCli.ConfigFile(), pw)
122119
if err != nil {
123120
return nil, err
124121
}
125122

126123
fmt.Println("Successfully built service images")
127124
updateBundle(bundle, resp)
128125

129-
var ref reference.Named
130-
ref, err = packager.GetNamedTagged(opt.tag)
131-
if err != nil {
132-
return nil, err
133-
}
134126
if ref == nil {
135127
if ref, err = computeDigest(bundle); err != nil {
136128
return nil, err
@@ -143,6 +135,21 @@ func runBuild(dockerCli command.Cli, application string, opt buildOptions) (refe
143135
return ref, nil
144136
}
145137

138+
func checkMinimalEngineVersion(dockerCli command.Cli) error {
139+
info, err := dockerCli.Client().Info(appcontext.Context())
140+
if err != nil {
141+
return err
142+
}
143+
majorVersion, err := strconv.Atoi(info.ServerVersion[:strings.IndexRune(info.ServerVersion, '.')])
144+
if err != nil {
145+
return err
146+
}
147+
if majorVersion < 19 {
148+
return errors.New("'build' require docker engine 19.03 or later")
149+
}
150+
return nil
151+
}
152+
146153
func updateBundle(bundle *bundle.Bundle, resp map[string]*client.SolveResponse) {
147154
debugSolveResponses(resp)
148155
for service, r := range resp {

internal/commands/build/compose.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
// parseCompose do parse app compose file and extract buildx Options
1515
// We don't rely on bake's ReadTargets + TargetsToBuildOpt here as we have to skip environment variable interpolation
1616
func parseCompose(app *types.App, options buildOptions) (map[string]build.Options, error) {
17-
1817
// Fixme can have > 1 composes ?
1918
parsed, err := loader.ParseYAML(app.Composes()[0])
2019
if err != nil {

0 commit comments

Comments
 (0)