Skip to content

Commit

Permalink
builder: conditional warning for wcow
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Feb 3, 2022
1 parent f57a76b commit afcd4d6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
14 changes: 1 addition & 13 deletions cli/command/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ import (
"github.com/spf13/cobra"
)

var (
errStdinConflict = errors.New("invalid argument: can't use stdin for both build context and dockerfile")
warnLegacyBuilder string
)
var errStdinConflict = errors.New("invalid argument: can't use stdin for both build context and dockerfile")

type buildOptions struct {
context string
Expand Down Expand Up @@ -107,11 +104,6 @@ func NewBuildCommand(dockerCli command.Cli) *cobra.Command {
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
options.context = args[0]
cmd.VisitParents(func(cmd *cobra.Command) {
if v, ok := cmd.Annotations["_warning_legacy_builder"]; ok {
warnLegacyBuilder = v
}
})
return runBuild(dockerCli, options)
},
}
Expand Down Expand Up @@ -192,10 +184,6 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
remote string
)

if warnLegacyBuilder != "" && !options.quiet && dockerCli.ServerInfo().OSType != "windows" {
_, _ = fmt.Fprint(dockerCli.Err(), warnLegacyBuilder)
}

if options.stream {
_, _ = fmt.Fprint(dockerCli.Err(), `DEPRECATED: The experimental --stream flag has been removed and the build context
will be sent non-streaming. Enable BuildKit instead with DOCKER_BUILDKIT=1
Expand Down
11 changes: 6 additions & 5 deletions cmd/docker/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const (
buildxMissingWarning = `DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
Install the buildx component to build images with BuildKit:
https://docs.docker.com/go/buildx/
`

buildxMissingError = `ERROR: BuildKit is enabled but the buildx component is missing or broken.
Expand Down Expand Up @@ -75,8 +74,10 @@ func processBuilder(dockerCli command.Cli, cmd *cobra.Command, args, osargs []st
}

if useLegacy {
// set warning msg as annotation that will be displayed in build cmd
cmd.Annotations["_warning_legacy_builder"] = newBuilderError(true, nil).Error()
// display warning if not wcow and continue
if dockerCli.ServerInfo().OSType != "windows" {
_, _ = fmt.Fprintln(dockerCli.Err(), newBuilderError(true, nil))
}
return args, osargs, nil
}

Expand All @@ -90,8 +91,8 @@ func processBuilder(dockerCli command.Cli, cmd *cobra.Command, args, osargs []st
if useBuilder {
return args, osargs, newBuilderError(false, perr)
}
// otherwise, set the warning msg as annotation that will be displayed in build cmd
cmd.Annotations["_warning_legacy_builder"] = newBuilderError(true, perr).Error()
// otherwise, display warning and continue
_, _ = fmt.Fprintln(dockerCli.Err(), newBuilderError(true, perr))
return args, osargs, nil
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/docker/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestBuildkitDisabled(t *testing.T) {
assert.NilError(t, err)
assert.DeepEqual(t, []string{"build", "."}, args)

output.Assert(t, cmd.Annotations["_warning_legacy_builder"], map[int]func(string) error{
output.Assert(t, b.String(), map[int]func(string) error{
0: output.Suffix("DEPRECATED: The legacy builder is deprecated and will be removed in a future release."),
})
}
Expand All @@ -95,7 +95,7 @@ func TestBuilderBroken(t *testing.T) {
assert.NilError(t, err)
assert.DeepEqual(t, []string{"build", "."}, args)

output.Assert(t, cmd.Annotations["_warning_legacy_builder"], map[int]func(string) error{
output.Assert(t, b.String(), map[int]func(string) error{
0: output.Prefix("failed to fetch metadata:"),
2: output.Suffix("DEPRECATED: The legacy builder is deprecated and will be removed in a future release."),
})
Expand Down
1 change: 0 additions & 1 deletion e2e/image/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func TestBuildFromContextDirectoryWithTag(t *testing.T) {
const buildxMissingWarning = `DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
Install the buildx component to build images with BuildKit:
https://docs.docker.com/go/buildx/
`

result.Assert(t, icmd.Expected{Err: buildxMissingWarning})
Expand Down

0 comments on commit afcd4d6

Please sign in to comment.