@@ -65,18 +65,16 @@ func Cmd(dockerCli command.Cli) *cobra.Command {
65
65
}
66
66
67
67
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 )
70
69
if err != nil {
71
70
return nil , err
72
71
}
73
- majorVersion , err := strconv .Atoi (info .ServerVersion [:strings .IndexRune (info .ServerVersion , '.' )])
72
+
73
+ var ref reference.Named
74
+ ref , err = packager .GetNamedTagged (opt .tag )
74
75
if err != nil {
75
76
return nil , err
76
77
}
77
- if majorVersion < 19 {
78
- return nil , errors .New ("'build' require docker engine 19.03 or later" )
79
- }
80
78
81
79
app , err := packager .Extract (application )
82
80
if err != nil {
@@ -101,6 +99,8 @@ func runBuild(dockerCli command.Cli, application string, opt buildOptions) (refe
101
99
102
100
debugBuildOpts (buildopts )
103
101
102
+ ctx , cancel := context .WithCancel (appcontext .Context ())
103
+ defer cancel ()
104
104
d , err := driver .GetDriver (ctx , "buildx_buildkit_default" , nil , dockerCli .Client (), nil , "" , nil )
105
105
if err != nil {
106
106
return nil , err
@@ -112,25 +112,17 @@ func runBuild(dockerCli command.Cli, application string, opt buildOptions) (refe
112
112
},
113
113
}
114
114
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 )
119
116
120
117
// 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 )
122
119
if err != nil {
123
120
return nil , err
124
121
}
125
122
126
123
fmt .Println ("Successfully built service images" )
127
124
updateBundle (bundle , resp )
128
125
129
- var ref reference.Named
130
- ref , err = packager .GetNamedTagged (opt .tag )
131
- if err != nil {
132
- return nil , err
133
- }
134
126
if ref == nil {
135
127
if ref , err = computeDigest (bundle ); err != nil {
136
128
return nil , err
@@ -143,6 +135,21 @@ func runBuild(dockerCli command.Cli, application string, opt buildOptions) (refe
143
135
return ref , nil
144
136
}
145
137
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
+
146
153
func updateBundle (bundle * bundle.Bundle , resp map [string ]* client.SolveResponse ) {
147
154
debugSolveResponses (resp )
148
155
for service , r := range resp {
0 commit comments