From d3f55aec6d806ea52c359408d7485fbbf3fe248a Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sat, 6 Nov 2021 09:29:53 +0100 Subject: [PATCH 1/4] update commands Signed-off-by: CrazyMax --- cli/metrics/commands.go | 64 ++++++++++++---------------- cli/metrics/generatecommands/main.go | 7 ++- 2 files changed, 33 insertions(+), 38 deletions(-) diff --git a/cli/metrics/commands.go b/cli/metrics/commands.go index e021897ff..75ee8a376 100644 --- a/cli/metrics/commands.go +++ b/cli/metrics/commands.go @@ -26,16 +26,17 @@ var managementCommands = []string{ "help", "ecs", "scan", + "image", "app", "builder", "imagetools", "buildx", "checkpoint", + "compose", "config", "container", "context", "create", - "image", "manifest", "network", "node", @@ -51,70 +52,63 @@ var managementCommands = []string{ "volume", "login", "logout", - "compose", } var commands = []string{ - "bundle", - "completion", - "init", "inspect", - "install", - "deploy", - "list", "ls", - "cp", - "merge", + "list", + "rm", + "remove", + "tag", + "build", + "init", "pull", "push", - "render", - "split", - "status", - "uninstall", - "upgrade", - "validate", - "version", - "build", + "run", + "deploy", + "update", "prune", "create", "bake", "f", "b", "du", - "rm", "stop", "use", - "remove", - "attach", - "commit", + "version", + "convert", + "config", "cp", - "diff", + "down", + "events", "exec", - "export", + "images", "kill", "logs", - "ps", "pause", "port", - "rename", + "ps", "restart", - "run", "start", - "stats", "top", "unpause", - "update", + "up", + "attach", + "commit", + "diff", + "export", + "rename", + "stats", "wait", "aci", "ecs", + "import", "show", "history", - "import", "load", - "images", "rmi", "save", - "tag", "annotate", "connect", "disconnect", @@ -122,11 +116,11 @@ var commands = []string{ "promote", "disable", "enable", + "install", "set", + "upgrade", "rollback", "scale", - "up", - "down", "services", "ca", "join", @@ -135,7 +129,6 @@ var commands = []string{ "unlock", "unlock-key", "df", - "events", "info", "generate", "add", @@ -145,5 +138,4 @@ var commands = []string{ "azure", "logout", "search", - "convert", } diff --git a/cli/metrics/generatecommands/main.go b/cli/metrics/generatecommands/main.go index 681728cf5..aff1fc058 100644 --- a/cli/metrics/generatecommands/main.go +++ b/cli/metrics/generatecommands/main.go @@ -26,11 +26,12 @@ import ( var managementCommands = []string{"ecs", "scan"} -var commands = []string{} +var commands []string func main() { fmt.Println("Walking through docker help to list commands...") getCommands() + getCommands("buildx") getCommands("compose") fmt.Printf(` @@ -71,7 +72,9 @@ func getCommands(execCommands ...string) { section = commandsSection if len(execCommands) > 0 { command := execCommands[len(execCommands)-1] - managementCommands = append(managementCommands, command) + if !utils.StringContains(managementCommands, command) { + managementCommands = append(managementCommands, command) + } } continue } From 6fd97089b83e2b02df2b51ccd6837fd31c630cab Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sat, 6 Nov 2021 09:35:32 +0100 Subject: [PATCH 2/4] sort commands Signed-off-by: CrazyMax --- cli/metrics/commands.go | 144 +++++++++++++-------------- cli/metrics/generatecommands/main.go | 4 + 2 files changed, 76 insertions(+), 72 deletions(-) diff --git a/cli/metrics/commands.go b/cli/metrics/commands.go index 75ee8a376..203fe3231 100644 --- a/cli/metrics/commands.go +++ b/cli/metrics/commands.go @@ -24,12 +24,8 @@ var commandFlags = []string{ // Generated with generatecommands/main.go var managementCommands = []string{ "help", - "ecs", - "scan", - "image", "app", "builder", - "imagetools", "buildx", "checkpoint", "compose", @@ -37,105 +33,109 @@ var managementCommands = []string{ "container", "context", "create", + "ecs", + "image", + "imagetools", + "key", + "login", + "logout", "manifest", "network", "node", "plugin", + "scan", "secret", "service", + "signer", "stack", "swarm", "system", - "key", - "signer", "trust", "volume", - "login", - "logout", } var commands = []string{ - "inspect", - "ls", - "list", - "rm", - "remove", - "tag", - "build", - "init", - "pull", - "push", - "run", - "deploy", - "update", - "prune", - "create", - "bake", - "f", + "aci", + "add", + "annotate", + "attach", + "azure", "b", - "du", - "stop", - "use", - "version", - "convert", + "bake", + "build", + "ca", + "commit", "config", + "connect", + "convert", "cp", + "create", + "demote", + "deploy", + "df", + "diff", + "disable", + "disconnect", "down", + "du", + "ecs", + "enable", "events", "exec", + "export", + "f", + "generate", + "history", "images", + "import", + "info", + "init", + "inspect", + "install", + "join", + "join-token", "kill", + "leave", + "list", + "load", + "login", + "logout", "logs", + "ls", "pause", "port", + "promote", + "prune", "ps", - "restart", - "start", - "top", - "unpause", - "up", - "attach", - "commit", - "diff", - "export", + "pull", + "push", + "remove", "rename", - "stats", - "wait", - "aci", - "ecs", - "import", - "show", - "history", - "load", + "restart", + "revoke", + "rm", "rmi", - "save", - "annotate", - "connect", - "disconnect", - "demote", - "promote", - "disable", - "enable", - "install", - "set", - "upgrade", "rollback", + "run", + "save", "scale", + "search", "services", - "ca", - "join", - "join-token", - "leave", + "set", + "show", + "sign", + "start", + "stats", + "stop", + "tag", + "top", "unlock", "unlock-key", - "df", - "info", - "generate", - "add", - "revoke", - "sign", - "login", - "azure", - "logout", - "search", + "unpause", + "up", + "update", + "upgrade", + "use", + "version", + "wait", } diff --git a/cli/metrics/generatecommands/main.go b/cli/metrics/generatecommands/main.go index aff1fc058..862c96f14 100644 --- a/cli/metrics/generatecommands/main.go +++ b/cli/metrics/generatecommands/main.go @@ -19,6 +19,7 @@ package main import ( "fmt" "os/exec" + "sort" "strings" "github.com/docker/compose/v2/pkg/utils" @@ -34,6 +35,9 @@ func main() { getCommands("buildx") getCommands("compose") + sort.Strings(managementCommands) + sort.Strings(commands) + fmt.Printf(` var managementCommands = []string{ "help", From a4ae60a39d763cb4938396960bc3f8a8db26fe1b Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Tue, 16 Nov 2021 07:13:07 +0100 Subject: [PATCH 3/4] recover missing commands for backward compatibility Signed-off-by: CrazyMax --- cli/metrics/commands.go | 8 ++++++++ cli/metrics/generatecommands/main.go | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cli/metrics/commands.go b/cli/metrics/commands.go index 203fe3231..ee44cf7e6 100644 --- a/cli/metrics/commands.go +++ b/cli/metrics/commands.go @@ -63,8 +63,10 @@ var commands = []string{ "b", "bake", "build", + "bundle", "ca", "commit", + "completion", "config", "connect", "convert", @@ -102,6 +104,7 @@ var commands = []string{ "logout", "logs", "ls", + "merge", "pause", "port", "promote", @@ -111,6 +114,7 @@ var commands = []string{ "push", "remove", "rename", + "render", "restart", "revoke", "rm", @@ -124,11 +128,14 @@ var commands = []string{ "set", "show", "sign", + "split", "start", "stats", + "status", "stop", "tag", "top", + "uninstall", "unlock", "unlock-key", "unpause", @@ -136,6 +143,7 @@ var commands = []string{ "update", "upgrade", "use", + "validate", "version", "wait", } diff --git a/cli/metrics/generatecommands/main.go b/cli/metrics/generatecommands/main.go index 862c96f14..8fe8ec789 100644 --- a/cli/metrics/generatecommands/main.go +++ b/cli/metrics/generatecommands/main.go @@ -25,9 +25,10 @@ import ( "github.com/docker/compose/v2/pkg/utils" ) -var managementCommands = []string{"ecs", "scan"} - -var commands []string +var ( + managementCommands = []string{"ecs", "scan"} + commands = []string{"bundle", "completion", "install", "merge", "render", "split", "status", "uninstall", "validate"} +) func main() { fmt.Println("Walking through docker help to list commands...") From 535fb932804c30a26d72042888631b8e8ea3e910 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Mon, 22 Nov 2021 19:36:06 +0100 Subject: [PATCH 4/4] add build metrics Signed-off-by: CrazyMax --- cli/metrics/commands.go | 2 + cli/metrics/metadata/build.go | 189 ++++++++++++++++++ cli/metrics/metadata/build_test.go | 87 ++++++++ cli/metrics/metadata/metadata.go | 29 +++ .../testdata/buildx-container/current | 1 + .../buildx-container/instances/builder | 1 + .../metadata/testdata/buildx-default/current | 1 + .../buildx-default/instances/graviton2 | 1 + cli/metrics/metrics.go | 3 +- cli/metrics/metrics_test.go | 46 +++++ local/e2e/cli-only/e2e_test.go | 16 ++ .../cli-only/testdata/buildx-config/current | 1 + .../testdata/buildx-config/instances/builder | 1 + .../buildx-config/instances/graviton2 | 1 + 14 files changed, 378 insertions(+), 1 deletion(-) create mode 100644 cli/metrics/metadata/build.go create mode 100644 cli/metrics/metadata/build_test.go create mode 100644 cli/metrics/metadata/metadata.go create mode 100644 cli/metrics/metadata/testdata/buildx-container/current create mode 100644 cli/metrics/metadata/testdata/buildx-container/instances/builder create mode 100644 cli/metrics/metadata/testdata/buildx-default/current create mode 100644 cli/metrics/metadata/testdata/buildx-default/instances/graviton2 create mode 100644 local/e2e/cli-only/testdata/buildx-config/current create mode 100644 local/e2e/cli-only/testdata/buildx-config/instances/builder create mode 100644 local/e2e/cli-only/testdata/buildx-config/instances/graviton2 diff --git a/cli/metrics/commands.go b/cli/metrics/commands.go index ee44cf7e6..0fef9f548 100644 --- a/cli/metrics/commands.go +++ b/cli/metrics/commands.go @@ -19,6 +19,8 @@ package metrics var commandFlags = []string{ //added to catch scan details "--version", "--login", + // added for build + "--builder", "--platforms", } // Generated with generatecommands/main.go diff --git a/cli/metrics/metadata/build.go b/cli/metrics/metadata/build.go new file mode 100644 index 000000000..498618219 --- /dev/null +++ b/cli/metrics/metadata/build.go @@ -0,0 +1,189 @@ +/* + Copyright 2020 Docker Compose CLI authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package metadata + +import ( + "context" + "encoding/json" + "fmt" + "io" + "io/ioutil" + "os" + "path" + "path/filepath" + "strconv" + + "github.com/docker/cli/cli/config" + "github.com/docker/cli/cli/config/configfile" + "github.com/docker/docker/api/types" + dockerclient "github.com/docker/docker/client" + "github.com/spf13/pflag" +) + +// getBuildMetadata returns build metadata for this command +func getBuildMetadata(cliSource string, command string, args []string) string { + var cli, builder string + dockercfg := config.LoadDefaultConfigFile(io.Discard) + if alias, ok := dockercfg.Aliases["builder"]; ok { + command = alias + } + if command == "build" { + cli = "docker" + builder = "buildkit" + if enabled, _ := isBuildKitEnabled(); !enabled { + builder = "legacy" + } + } else if command == "buildx" { + cli = "buildx" + builder = buildxDriver(dockercfg, args) + } + return fmt.Sprintf("%s-%s;%s", cliSource, cli, builder) +} + +// isBuildKitEnabled returns whether buildkit is enabled either through a +// daemon setting or otherwise the client-side DOCKER_BUILDKIT environment +// variable +func isBuildKitEnabled() (bool, error) { + if buildkitEnv := os.Getenv("DOCKER_BUILDKIT"); len(buildkitEnv) > 0 { + return strconv.ParseBool(buildkitEnv) + } + apiClient, err := dockerclient.NewClientWithOpts(dockerclient.FromEnv, dockerclient.WithAPIVersionNegotiation()) + if err != nil { + return false, err + } + defer apiClient.Close() //nolint:errcheck + ping, err := apiClient.Ping(context.Background()) + if err != nil { + return false, err + } + return ping.BuilderVersion == types.BuilderBuildKit, nil +} + +// buildxConfigDir will look for correct configuration store path; +// if `$BUILDX_CONFIG` is set - use it, otherwise use parent directory +// of Docker config file (i.e. `${DOCKER_CONFIG}/buildx`) +func buildxConfigDir(dockercfg *configfile.ConfigFile) string { + if buildxConfig := os.Getenv("BUILDX_CONFIG"); buildxConfig != "" { + return buildxConfig + } + return filepath.Join(filepath.Dir(dockercfg.Filename), "buildx") +} + +// buildxDriver returns the build driver being used for the build command +func buildxDriver(dockercfg *configfile.ConfigFile, buildArgs []string) string { + driver := "error" + configDir := buildxConfigDir(dockercfg) + if _, err := os.Stat(configDir); err != nil { + return driver + } + builder := buildxBuilder(buildArgs) + if len(builder) == 0 { + // if builder not defined in command, seek current in buildx store + // `${DOCKER_CONFIG}/buildx/current` + fileCurrent := path.Join(configDir, "current") + if _, err := os.Stat(fileCurrent); err != nil { + return driver + } + // content looks like + // { + // "Key": "unix:///var/run/docker.sock", + // "Name": "builder", + // "Global": false + // } + rawCurrent, err := ioutil.ReadFile(fileCurrent) + if err != nil { + return driver + } + // unmarshal and returns `Name` + var obj map[string]interface{} + if err = json.Unmarshal(rawCurrent, &obj); err != nil { + return driver + } + if n, ok := obj["Name"]; ok { + builder = n.(string) + // `Name` will be empty if `default` builder is used + // { + // "Key": "unix:///var/run/docker.sock", + // "Name": "", + // "Global": false + // } + if len(builder) == 0 { + builder = "default" + } + } else { + return driver + } + } + + // if default builder return docker + if builder == "default" { + return "docker" + } + + // read builder info and retrieve the current driver + // `${DOCKER_CONFIG}/buildx/instances/` + fileBuilder := path.Join(configDir, "instances", builder) + if _, err := os.Stat(fileBuilder); err != nil { + return driver + } + // content looks like + // { + // "Name": "builder", + // "Driver": "docker-container", + // "Nodes": [ + // { + // "Name": "builder0", + // "Endpoint": "unix:///var/run/docker.sock", + // "Platforms": null, + // "Flags": null, + // "ConfigFile": "", + // "DriverOpts": null + // } + // ], + // "Dynamic": false + // } + rawBuilder, err := ioutil.ReadFile(fileBuilder) + if err != nil { + return driver + } + // unmarshal and returns `Driver` + var obj map[string]interface{} + if err = json.Unmarshal(rawBuilder, &obj); err != nil { + return driver + } + if d, ok := obj["Driver"]; ok { + driver = d.(string) + } + return driver +} + +// buildxBuilder returns the builder being used in the build command +func buildxBuilder(buildArgs []string) string { + var builder string + fset := pflag.NewFlagSet("buildx", pflag.ContinueOnError) + fset.String("builder", "", "") + _ = fset.ParseAll(buildArgs, func(flag *pflag.Flag, value string) error { + if flag.Name == "builder" { + builder = value + } + return nil + }) + if len(builder) == 0 { + builder = os.Getenv("BUILDX_BUILDER") + } + return builder +} diff --git a/cli/metrics/metadata/build_test.go b/cli/metrics/metadata/build_test.go new file mode 100644 index 000000000..32a3a355d --- /dev/null +++ b/cli/metrics/metadata/build_test.go @@ -0,0 +1,87 @@ +/* + Copyright 2020 Docker Compose CLI authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package metadata + +import ( + "io" + "os" + "testing" + + "github.com/docker/cli/cli/config" + "gotest.tools/v3/assert" +) + +func TestBuildxBuilder(t *testing.T) { + tts := []struct { + name string + args []string + expected string + }{ + { + name: "without builder", + args: []string{"buildx", "build", "-t", "foo:bar", "."}, + expected: "", + }, + { + name: "with builder", + args: []string{"--builder", "foo", "buildx", "build", "."}, + expected: "foo", + }, + } + for _, tt := range tts { + t.Run(tt.name, func(t *testing.T) { + result := buildxBuilder(tt.args) + assert.Equal(t, tt.expected, result) + }) + } +} + +func TestBuildxDriver(t *testing.T) { + tts := []struct { + name string + cfg string + args []string + expected string + }{ + { + name: "no flag and default builder", + cfg: "./testdata/buildx-default", + args: []string{"buildx", "build", "-t", "foo:bar", "."}, + expected: "docker", + }, + { + name: "no flag and current builder", + cfg: "./testdata/buildx-container", + args: []string{"buildx", "build", "-t", "foo:bar", "."}, + expected: "docker-container", + }, + { + name: "builder flag", + cfg: "./testdata/buildx-default", + args: []string{"--builder", "graviton2", "buildx", "build", "."}, + expected: "docker-container", + }, + } + + for _, tt := range tts { + t.Run(tt.name, func(t *testing.T) { + _ = os.Setenv("BUILDX_CONFIG", tt.cfg) + result := buildxDriver(config.LoadDefaultConfigFile(io.Discard), tt.args) + assert.Equal(t, tt.expected, result) + }) + } +} diff --git a/cli/metrics/metadata/metadata.go b/cli/metrics/metadata/metadata.go new file mode 100644 index 000000000..7d55ab8b2 --- /dev/null +++ b/cli/metrics/metadata/metadata.go @@ -0,0 +1,29 @@ +/* + Copyright 2020 Docker Compose CLI authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package metadata + +// Get returns the JSON metadata linked to the invoked command +func Get(cliSource string, args []string) string { + if len(args) == 0 { + return cliSource + } + switch args[0] { + case "build", "buildx": + cliSource = getBuildMetadata(cliSource, args[0], args[1:]) + } + return cliSource +} diff --git a/cli/metrics/metadata/testdata/buildx-container/current b/cli/metrics/metadata/testdata/buildx-container/current new file mode 100644 index 000000000..1ae8f69da --- /dev/null +++ b/cli/metrics/metadata/testdata/buildx-container/current @@ -0,0 +1 @@ +{"Key":"unix:///var/run/docker.sock","Name":"builder","Global":false} \ No newline at end of file diff --git a/cli/metrics/metadata/testdata/buildx-container/instances/builder b/cli/metrics/metadata/testdata/buildx-container/instances/builder new file mode 100644 index 000000000..f12c83a8e --- /dev/null +++ b/cli/metrics/metadata/testdata/buildx-container/instances/builder @@ -0,0 +1 @@ +{"Name":"builder","Driver":"docker-container","Nodes":[{"Name":"builder0","Endpoint":"unix:///var/run/docker.sock","Platforms":null,"Flags":["--allow-insecure-entitlement","security.insecure","--allow-insecure-entitlement","network.host"],"DriverOpts":{"env.JAEGER_TRACE":"localhost:6831","image":"moby/buildkit:latest","network":"host"},"Files":null}],"Dynamic":false} \ No newline at end of file diff --git a/cli/metrics/metadata/testdata/buildx-default/current b/cli/metrics/metadata/testdata/buildx-default/current new file mode 100644 index 000000000..f34f695d0 --- /dev/null +++ b/cli/metrics/metadata/testdata/buildx-default/current @@ -0,0 +1 @@ +{"Key":"unix:///var/run/docker.sock","Name":"","Global":false} \ No newline at end of file diff --git a/cli/metrics/metadata/testdata/buildx-default/instances/graviton2 b/cli/metrics/metadata/testdata/buildx-default/instances/graviton2 new file mode 100644 index 000000000..ab45e1c09 --- /dev/null +++ b/cli/metrics/metadata/testdata/buildx-default/instances/graviton2 @@ -0,0 +1 @@ +{"Name":"graviton2","Driver":"docker-container","Nodes":[{"Name":"node1","Endpoint":"ssh://ubuntu@18.246.77.142","Platforms":[{"architecture":"arm64","os":"linux"}],"Flags":null,"ConfigFile":"","DriverOpts":{}}],"Dynamic":false} \ No newline at end of file diff --git a/cli/metrics/metrics.go b/cli/metrics/metrics.go index 7840892c3..11cbfc2ef 100644 --- a/cli/metrics/metrics.go +++ b/cli/metrics/metrics.go @@ -20,6 +20,7 @@ import ( "os" "strings" + "github.com/docker/compose-cli/cli/metrics/metadata" "github.com/docker/compose/v2/pkg/utils" ) @@ -34,7 +35,7 @@ func Track(context string, args []string, status string) { c.Send(Command{ Command: command, Context: context, - Source: CLISource, + Source: metadata.Get(CLISource, args), Status: status, }) } diff --git a/cli/metrics/metrics_test.go b/cli/metrics/metrics_test.go index 8711a07b8..5c4a7175c 100644 --- a/cli/metrics/metrics_test.go +++ b/cli/metrics/metrics_test.go @@ -335,3 +335,49 @@ func TestScan(t *testing.T) { }) } } + +func TestBuild(t *testing.T) { + testCases := []struct { + name string + args []string + expected string + }{ + { + name: "build", + args: []string{"build", "."}, + expected: "build", + }, + { + name: "build with flags", + args: []string{"build", "--file", "./Dockerfile", "--tag", "myimage:latest", "."}, + expected: "build", + }, + { + name: "buildx build", + args: []string{"buildx", "build", "."}, + expected: "buildx build", + }, + { + name: "buildx build with flags", + args: []string{"buildx", "build", "--file", "./Dockerfile", "--tag", "myimage:latest", "."}, + expected: "buildx build", + }, + { + name: "buildx build with flags and builder", + args: []string{"buildx", "--builder", "foo", "build", "--file", "./Dockerfile", "--tag", "myimage:latest", "."}, + expected: "buildx --builder build", + }, + { + name: "buildx version", + args: []string{"buildx", "version"}, + expected: "buildx version", + }, + } + + for _, testCase := range testCases { + t.Run(testCase.name, func(t *testing.T) { + result := GetCommand(testCase.args) + assert.Equal(t, testCase.expected, result) + }) + } +} diff --git a/local/e2e/cli-only/e2e_test.go b/local/e2e/cli-only/e2e_test.go index 896387e2b..fb430e9f2 100644 --- a/local/e2e/cli-only/e2e_test.go +++ b/local/e2e/cli-only/e2e_test.go @@ -210,6 +210,22 @@ func TestContextMetrics(t *testing.T) { `{"command":"context ls","context":"moby","source":"cli","status":"success"}`, }, usage) }) + + t.Run("metrics on build", func(t *testing.T) { + s.ResetUsage() + + _ = os.Setenv("BUILDX_CONFIG", "./testdata/buildx-config") + c.RunDockerOrExitError("build", "-t", "foo:bar", ".") + c.RunDockerOrExitError("buildx", "build", "-t", "foo:bar", ".") + c.RunDockerOrExitError("buildx", "--builder", "graviton2", "build", "-t", "foo:bar", ".") + + usage := s.GetUsage() + assert.DeepEqual(t, []string{ + `{"command":"build","context":"moby","source":"cli-docker;buildkit","status":"failure"}`, + `{"command":"buildx build","context":"moby","source":"cli-buildx;docker-container","status":"failure"}`, + `{"command":"buildx --builder build","context":"moby","source":"cli-buildx;docker-container","status":"failure"}`, + }, usage) + }) } func TestContextDuplicateACI(t *testing.T) { diff --git a/local/e2e/cli-only/testdata/buildx-config/current b/local/e2e/cli-only/testdata/buildx-config/current new file mode 100644 index 000000000..1ae8f69da --- /dev/null +++ b/local/e2e/cli-only/testdata/buildx-config/current @@ -0,0 +1 @@ +{"Key":"unix:///var/run/docker.sock","Name":"builder","Global":false} \ No newline at end of file diff --git a/local/e2e/cli-only/testdata/buildx-config/instances/builder b/local/e2e/cli-only/testdata/buildx-config/instances/builder new file mode 100644 index 000000000..f12c83a8e --- /dev/null +++ b/local/e2e/cli-only/testdata/buildx-config/instances/builder @@ -0,0 +1 @@ +{"Name":"builder","Driver":"docker-container","Nodes":[{"Name":"builder0","Endpoint":"unix:///var/run/docker.sock","Platforms":null,"Flags":["--allow-insecure-entitlement","security.insecure","--allow-insecure-entitlement","network.host"],"DriverOpts":{"env.JAEGER_TRACE":"localhost:6831","image":"moby/buildkit:latest","network":"host"},"Files":null}],"Dynamic":false} \ No newline at end of file diff --git a/local/e2e/cli-only/testdata/buildx-config/instances/graviton2 b/local/e2e/cli-only/testdata/buildx-config/instances/graviton2 new file mode 100644 index 000000000..ab45e1c09 --- /dev/null +++ b/local/e2e/cli-only/testdata/buildx-config/instances/graviton2 @@ -0,0 +1 @@ +{"Name":"graviton2","Driver":"docker-container","Nodes":[{"Name":"node1","Endpoint":"ssh://ubuntu@18.246.77.142","Platforms":[{"architecture":"arm64","os":"linux"}],"Flags":null,"ConfigFile":"","DriverOpts":{}}],"Dynamic":false} \ No newline at end of file