diff --git a/build/build.go b/build/build.go index f94bc9b6ef8..a1449953124 100644 --- a/build/build.go +++ b/build/build.go @@ -546,7 +546,7 @@ func toSolveOpt(ctx context.Context, d driver.Driver, multiDriver bool, opt Opti so.FrontendAttrs["force-network-mode"] = opt.NetworkMode case "", "default": default: - return nil, nil, errors.Errorf("network mode %q not supported by buildkit", opt.NetworkMode) + return nil, nil, errors.Errorf("network mode %q not supported by buildkit. You can define a custom network for your builder using the network driver-opt in buildx create.", opt.NetworkMode) } // setup extrahosts diff --git a/commands/build.go b/commands/build.go index ead06b2a141..041ab643c32 100644 --- a/commands/build.go +++ b/commands/build.go @@ -22,6 +22,7 @@ import ( "github.com/moby/buildkit/session/auth/authprovider" "github.com/moby/buildkit/util/appcontext" "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -50,9 +51,6 @@ type buildOptions struct { target string ulimits *dockeropts.UlimitOpt commonOptions - - // unimplemented - squash bool } type commonOptions struct { @@ -70,9 +68,6 @@ type commonOptions struct { } func runBuild(dockerCli command.Cli, in buildOptions) (err error) { - if in.squash { - return errors.Errorf("squash currently not implemented") - } ctx := appcontext.Context() ctx, end, err := tracing.TraceCurrentCommand(ctx, "build") @@ -268,6 +263,7 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { options.contextPath = args[0] options.builder = rootOpts.builder + cmd.Flags().VisitAll(checkWarnedFlags) return runBuild(dockerCli, options) }, } @@ -324,10 +320,6 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command { flags.Var(options.ulimits, "ulimit", "Ulimit options") - // not implemented - flags.BoolVar(&options.squash, "squash", false, "Squash newly built layers into a single new layer") - flags.MarkHidden("squash") - // hidden flags var ignore string var ignoreSlice []string @@ -336,15 +328,22 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command { flags.StringVar(&ignore, "cgroup-parent", "", "Optional parent cgroup for the container") flags.MarkHidden("cgroup-parent") + //flags.SetAnnotation("cgroup-parent", "flag-warn", []string{"cgroup-parent is not implemented."}) flags.BoolVar(&ignoreBool, "compress", false, "Compress the build context using gzip") flags.MarkHidden("compress") flags.StringVar(&ignore, "isolation", "", "Container isolation technology") flags.MarkHidden("isolation") + flags.SetAnnotation("isolation", "flag-warn", []string{"isolation flag is deprecated with BuildKit."}) flags.StringSliceVar(&ignoreSlice, "security-opt", []string{}, "Security options") flags.MarkHidden("security-opt") + flags.SetAnnotation("security-opt", "flag-warn", []string{`security-opt flag is deprecated. "RUN --security=insecure" should be used with BuildKit.`}) + + flags.BoolVar(&ignoreBool, "squash", false, "Squash newly built layers into a single new layer") + flags.MarkHidden("squash") + flags.SetAnnotation("squash", "flag-warn", []string{"experimental flag squash is removed with BuildKit. You should squash inside build using a multi-stage Dockerfile for efficiency."}) flags.StringVarP(&ignore, "memory", "m", "", "Memory limit") flags.MarkHidden("memory") @@ -384,6 +383,19 @@ func commonBuildFlags(options *commonOptions, flags *pflag.FlagSet) { flags.StringVar(&options.metadataFile, "metadata-file", "", "Write build result metadata to the file") } +func checkWarnedFlags(f *pflag.Flag) { + if !f.Changed { + return + } + for t, m := range f.Annotations { + switch t { + case "flag-warn": + logrus.Warn(m[0]) + break + } + } +} + func listToMap(values []string, defaultEnv bool) map[string]string { result := make(map[string]string, len(values)) for _, value := range values { diff --git a/docs/reference/buildx_create.md b/docs/reference/buildx_create.md index 4b5abb54bca..7bb94eafad7 100644 --- a/docs/reference/buildx_create.md +++ b/docs/reference/buildx_create.md @@ -131,11 +131,6 @@ Passes additional driver-specific options. Details for each driver: - `image=IMAGE` - Sets the container image to be used for running buildkit. - `network=NETMODE` - Sets the network mode for running the buildkit container. - `cgroup-parent=CGROUP` - Sets the cgroup parent of the buildkit container if docker is using the "cgroupfs" driver. Defaults to `/docker/buildx`. - - Example: - - ```console - --driver docker-container --driver-opt image=moby/buildkit:master,network=host - ``` - `kubernetes` - `image=IMAGE` - Sets the container image to be used for running buildkit. - `namespace=NS` - Sets the Kubernetes namespace. Defaults to the current namespace. @@ -150,6 +145,30 @@ Passes additional driver-specific options. Details for each driver: - `qemu.install=(true|false)` - Install QEMU emulation for multi platforms support. - `qemu.image=IMAGE` - Sets the QEMU emulation image. Defaults to `tonistiigi/binfmt:latest` +**Examples** + +#### Use a custom network + +```console +$ docker network create foonet +$ docker buildx create --name builder --driver docker-container --driver-opt network=foonet --use +$ docker buildx inspect --bootstrap +$ docker inspect buildx_buildkit_builder0 --format={{.NetworkSettings.Networks}} +map[foonet:0xc00018c0c0] +``` + +#### OpenTelemetry support + +To capture the trace to [Jaeger](https://github.com/jaegertracing/jaeger), set +`JAEGER_TRACE` environment variable to the collection address using the `driver-opt`: + +```console +$ docker run -d --name jaeger -p 6831:6831/udp -p 16686:16686 jaegertracing/all-in-one +$ docker buildx create --name builder --driver docker-container --driver-opt network=host --driver-opt env.JAEGER_TRACE=localhost:6831 --use +$ docker buildx inspect --bootstrap +# buildx command should be traced at http://127.0.0.1:16686/ +``` + ### Remove a node from a builder (--leave) The `--leave` flag changes the action of the command to remove a node from a