Skip to content

Commit 9e646f6

Browse files
committed
cli/command/image: runBuild: inline vars and minor cleanups
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 64be664 commit 9e646f6

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

cli/command/image/build.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ func (out *lastProgressOutput) WriteProgress(prog progress.Progress) error {
181181
//nolint:gocyclo
182182
func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions) error {
183183
var (
184-
err error
185184
buildCtx io.ReadCloser
186185
dockerfileCtx io.ReadCloser
187186
contextDir string
@@ -263,7 +262,7 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
263262
}
264263

265264
if err := build.ValidateContextDirectory(contextDir, excludes); err != nil {
266-
return fmt.Errorf("error checking context: %w", err)
265+
return fmt.Errorf("checking context: %w", err)
267266
}
268267

269268
// And canonicalize dockerfile name to a platform-independent one
@@ -287,9 +286,6 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
287286
}
288287
}
289288

290-
ctx, cancel := context.WithCancel(ctx)
291-
defer cancel()
292-
293289
if options.compress {
294290
buildCtx, err = build.Compress(buildCtx)
295291
if err != nil {
@@ -330,17 +326,18 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
330326
}
331327
}
332328
buildOpts := imageBuildOptions(dockerCli, options)
333-
buildOpts.Version = buildtypes.BuilderV1
334329
buildOpts.Dockerfile = relDockerfile
335330
buildOpts.AuthConfigs = authConfigs
336331
buildOpts.RemoteContext = remote
337332

333+
ctx, cancel := context.WithCancel(ctx)
334+
defer cancel()
335+
338336
response, err := dockerCli.Client().ImageBuild(ctx, body, buildOpts)
339337
if err != nil {
340338
if options.quiet {
341339
_, _ = fmt.Fprintf(dockerCli.Err(), "%s", progBuff)
342340
}
343-
cancel()
344341
return err
345342
}
346343
defer response.Body.Close()
@@ -357,7 +354,8 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
357354

358355
err = jsonstream.Display(ctx, response.Body, streams.NewOut(buildBuff), jsonstream.WithAuxCallback(aux))
359356
if err != nil {
360-
if jerr, ok := err.(*jsonstream.JSONError); ok {
357+
var jerr *jsonstream.JSONError
358+
if errors.As(err, &jerr) {
361359
// If no error code is set, default to 1
362360
if jerr.Code == 0 {
363361
jerr.Code = 1
@@ -402,6 +400,7 @@ func validateTag(rawRepo string) (string, error) {
402400
func imageBuildOptions(dockerCli command.Cli, options buildOptions) client.ImageBuildOptions {
403401
configFile := dockerCli.ConfigFile()
404402
return client.ImageBuildOptions{
403+
Version: buildtypes.BuilderV1,
405404
Memory: options.memory.Value(),
406405
MemorySwap: options.memorySwap.Value(),
407406
Tags: options.tags.GetSlice(),

0 commit comments

Comments
 (0)