Merge pull request #5911 from thaJeztah/builder_nits

cli/command/image: fix some minor linting issues
This commit is contained in:
Sebastiaan van Stijn 2025-03-10 16:12:24 +01:00 committed by GitHub
commit 879acd15ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -242,7 +242,7 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
if err != nil { if err != nil {
if options.quiet && urlutil.IsURL(specifiedContext) { if options.quiet && urlutil.IsURL(specifiedContext) {
fmt.Fprintln(dockerCli.Err(), progBuff) _, _ = fmt.Fprintln(dockerCli.Err(), progBuff)
} }
return errors.Errorf("unable to prepare context: %s", err) return errors.Errorf("unable to prepare context: %s", err)
} }
@ -337,16 +337,16 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
for k, auth := range creds { for k, auth := range creds {
authConfigs[k] = registrytypes.AuthConfig(auth) authConfigs[k] = registrytypes.AuthConfig(auth)
} }
buildOptions := imageBuildOptions(dockerCli, options) buildOpts := imageBuildOptions(dockerCli, options)
buildOptions.Version = types.BuilderV1 buildOpts.Version = types.BuilderV1
buildOptions.Dockerfile = relDockerfile buildOpts.Dockerfile = relDockerfile
buildOptions.AuthConfigs = authConfigs buildOpts.AuthConfigs = authConfigs
buildOptions.RemoteContext = remote buildOpts.RemoteContext = remote
response, err := dockerCli.Client().ImageBuild(ctx, body, buildOptions) response, err := dockerCli.Client().ImageBuild(ctx, body, buildOpts)
if err != nil { if err != nil {
if options.quiet { if options.quiet {
fmt.Fprintf(dockerCli.Err(), "%s", progBuff) _, _ = fmt.Fprintf(dockerCli.Err(), "%s", progBuff)
} }
cancel() cancel()
return err return err
@ -357,7 +357,7 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
aux := func(msg jsonstream.JSONMessage) { aux := func(msg jsonstream.JSONMessage) {
var result types.BuildResult var result types.BuildResult
if err := json.Unmarshal(*msg.Aux, &result); err != nil { if err := json.Unmarshal(*msg.Aux, &result); err != nil {
fmt.Fprintf(dockerCli.Err(), "Failed to parse aux message: %s", err) _, _ = fmt.Fprintf(dockerCli.Err(), "Failed to parse aux message: %s", err)
} else { } else {
imageID = result.ID imageID = result.ID
} }
@ -371,7 +371,7 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
jerr.Code = 1 jerr.Code = 1
} }
if options.quiet { if options.quiet {
fmt.Fprintf(dockerCli.Err(), "%s%s", progBuff, buildBuff) _, _ = fmt.Fprintf(dockerCli.Err(), "%s%s", progBuff, buildBuff)
} }
return cli.StatusError{Status: jerr.Message, StatusCode: jerr.Code} return cli.StatusError{Status: jerr.Message, StatusCode: jerr.Code}
} }
@ -381,7 +381,7 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
// Windows: show error message about modified file permissions if the // Windows: show error message about modified file permissions if the
// daemon isn't running Windows. // daemon isn't running Windows.
if response.OSType != "windows" && runtime.GOOS == "windows" && !options.quiet { if response.OSType != "windows" && runtime.GOOS == "windows" && !options.quiet {
fmt.Fprintln(dockerCli.Out(), "SECURITY WARNING: You are building a Docker "+ _, _ = fmt.Fprintln(dockerCli.Out(), "SECURITY WARNING: You are building a Docker "+
"image from Windows against a non-Windows Docker host. All files and "+ "image from Windows against a non-Windows Docker host. All files and "+
"directories added to build context will have '-rwxr-xr-x' permissions. "+ "directories added to build context will have '-rwxr-xr-x' permissions. "+
"It is recommended to double check and reset permissions for sensitive "+ "It is recommended to double check and reset permissions for sensitive "+
@ -502,12 +502,12 @@ func replaceDockerfileForContentTrust(ctx context.Context, inputTarStream io.Rea
hdr, err := tarReader.Next() hdr, err := tarReader.Next()
if err == io.EOF { if err == io.EOF {
// Signals end of archive. // Signals end of archive.
tarWriter.Close() _ = tarWriter.Close()
pipeWriter.Close() _ = pipeWriter.Close()
return return
} }
if err != nil { if err != nil {
pipeWriter.CloseWithError(err) _ = pipeWriter.CloseWithError(err)
return return
} }
@ -519,7 +519,7 @@ func replaceDockerfileForContentTrust(ctx context.Context, inputTarStream io.Rea
var newDockerfile []byte var newDockerfile []byte
newDockerfile, *resolvedTags, err = rewriteDockerfileFromForContentTrust(ctx, content, translator) newDockerfile, *resolvedTags, err = rewriteDockerfileFromForContentTrust(ctx, content, translator)
if err != nil { if err != nil {
pipeWriter.CloseWithError(err) _ = pipeWriter.CloseWithError(err)
return return
} }
hdr.Size = int64(len(newDockerfile)) hdr.Size = int64(len(newDockerfile))
@ -527,12 +527,12 @@ func replaceDockerfileForContentTrust(ctx context.Context, inputTarStream io.Rea
} }
if err := tarWriter.WriteHeader(hdr); err != nil { if err := tarWriter.WriteHeader(hdr); err != nil {
pipeWriter.CloseWithError(err) _ = pipeWriter.CloseWithError(err)
return return
} }
if _, err := io.Copy(tarWriter, content); err != nil { if _, err := io.Copy(tarWriter, content); err != nil {
pipeWriter.CloseWithError(err) _ = pipeWriter.CloseWithError(err)
return return
} }
} }