Skip to content

Commit 6fef143

Browse files
committed
Set buildx as default builder
Signed-off-by: CrazyMax <[email protected]>
1 parent 5bb88dc commit 6fef143

File tree

405 files changed

+302
-99022
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

405 files changed

+302
-99022
lines changed

‎Dockerfile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ARG GO_VERSION=1.16.11
55
ARG XX_VERSION=1.0.0-rc.2
66
ARG GOVERSIONINFO_VERSION=v1.3.0
77
ARG GOTESTSUM_VERSION=v1.7.0
8+
ARG BUILDX_VERSION=0.7.1
89

910
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-${BASE_VARIANT} AS gostable
1011
FROM --platform=$BUILDPLATFORM golang:1.17rc1-${BASE_VARIANT} AS golatest
@@ -106,6 +107,8 @@ ARG COMPOSE_VERSION=1.29.2
106107
RUN curl -fsSL https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose && \
107108
chmod +x /usr/local/bin/docker-compose
108109

110+
FROM docker/buildx-bin:${BUILDX_VERSION} AS buildx
111+
109112
FROM e2e-base-${BASE_VARIANT} AS e2e
110113
ARG NOTARY_VERSION=v0.6.1
111114
ADD --chmod=0755 https://github.com/theupdateframework/notary/releases/download/${NOTARY_VERSION}/notary-Linux-amd64 /usr/local/bin/notary
@@ -114,6 +117,7 @@ RUN echo 'notary.cert' >> /etc/ca-certificates.conf && update-ca-certificates
114117
COPY --from=gotestsum /out/gotestsum /usr/bin/gotestsum
115118
COPY --from=build /out ./build/
116119
COPY --from=build-plugins /out ./build/
120+
COPY --from=buildx /buildx /usr/libexec/docker/cli-plugins/docker-buildx
117121
COPY . .
118122
ENV DOCKER_BUILDKIT=1
119123
ENV PATH=/go/src/github.com/docker/cli/build:$PATH

‎cli-plugins/manager/manager.go‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,36 @@ func listPluginCandidates(dirs []string) (map[string][]string, error) {
104104
return result, nil
105105
}
106106

107+
// GetPlugin returns a plugin on the system by its name
108+
func GetPlugin(name string, dockerCli command.Cli, rootcmd *cobra.Command) (*Plugin, error) {
109+
pluginDirs, err := getPluginDirs(dockerCli)
110+
if err != nil {
111+
return nil, err
112+
}
113+
114+
candidates, err := listPluginCandidates(pluginDirs)
115+
if err != nil {
116+
return nil, err
117+
}
118+
119+
if paths, ok := candidates[name]; ok {
120+
if len(paths) == 0 {
121+
return nil, errPluginNotFound(name)
122+
}
123+
c := &candidate{paths[0]}
124+
p, err := newPlugin(c, rootcmd)
125+
if err != nil {
126+
return nil, err
127+
}
128+
if !IsNotFound(p.Err) {
129+
p.ShadowedPaths = paths[1:]
130+
}
131+
return &p, nil
132+
}
133+
134+
return nil, errPluginNotFound(name)
135+
}
136+
107137
// ListPlugins produces a list of the plugins available on the system
108138
func ListPlugins(dockerCli command.Cli, rootcmd *cobra.Command) ([]Plugin, error) {
109139
pluginDirs, err := getPluginDirs(dockerCli)

‎cli-plugins/manager/manager_test.go‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,29 @@ func TestListPluginCandidates(t *testing.T) {
8282
assert.DeepEqual(t, candidates, exp)
8383
}
8484

85+
func TestGetPlugin(t *testing.T) {
86+
dir := fs.NewDir(t, t.Name(),
87+
fs.WithFile("docker-bbb", `
88+
#!/bin/sh
89+
echo '{"SchemaVersion":"0.1.0"}'`, fs.WithMode(0777)),
90+
fs.WithFile("docker-aaa", `
91+
#!/bin/sh
92+
echo '{"SchemaVersion":"0.1.0"}'`, fs.WithMode(0777)),
93+
)
94+
defer dir.Remove()
95+
96+
cli := test.NewFakeCli(nil)
97+
cli.SetConfigFile(&configfile.ConfigFile{CLIPluginsExtraDirs: []string{dir.Path()}})
98+
99+
plugin, err := GetPlugin("bbb", cli, &cobra.Command{})
100+
assert.NilError(t, err)
101+
assert.Equal(t, plugin.Name, "bbb")
102+
103+
_, err = GetPlugin("ccc", cli, &cobra.Command{})
104+
assert.Error(t, err, "Error: No such CLI plugin: ccc")
105+
assert.Assert(t, IsNotFound(err))
106+
}
107+
85108
func TestListPluginsIsSorted(t *testing.T) {
86109
dir := fs.NewDir(t, t.Name(),
87110
fs.WithFile("docker-bbb", `

‎cli/command/cli.go‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"os"
88
"path/filepath"
99
"runtime"
10-
"strconv"
1110
"strings"
1211
"time"
1312

@@ -169,20 +168,6 @@ func (cli *DockerCli) ContentTrustEnabled() bool {
169168
return cli.contentTrust
170169
}
171170

172-
// BuildKitEnabled returns whether buildkit is enabled either through a daemon setting
173-
// or otherwise the client-side DOCKER_BUILDKIT environment variable
174-
func BuildKitEnabled(si ServerInfo) (bool, error) {
175-
buildkitEnabled := si.BuildkitVersion == types.BuilderBuildKit
176-
if buildkitEnv := os.Getenv("DOCKER_BUILDKIT"); buildkitEnv != "" {
177-
var err error
178-
buildkitEnabled, err = strconv.ParseBool(buildkitEnv)
179-
if err != nil {
180-
return false, errors.Wrap(err, "DOCKER_BUILDKIT environment variable expects boolean value")
181-
}
182-
}
183-
return buildkitEnabled, nil
184-
}
185-
186171
// ManifestStore returns a store for local manifests
187172
func (cli *DockerCli) ManifestStore() manifeststore.Store {
188173
// TODO: support override default location from config file

‎cli/command/image/build.go‎

Lines changed: 7 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"bufio"
66
"bytes"
77
"context"
8-
"encoding/csv"
98
"encoding/json"
109
"fmt"
1110
"io"
@@ -57,7 +56,6 @@ type buildOptions struct {
5756
isolation string
5857
quiet bool
5958
noCache bool
60-
progress string
6159
rm bool
6260
forceRm bool
6361
pull bool
@@ -71,9 +69,6 @@ type buildOptions struct {
7169
stream bool
7270
platform string
7371
untrusted bool
74-
secrets []string
75-
ssh []string
76-
outputs []string
7772
}
7873

7974
// dockerfileFromStdin returns true when the user specified that the Dockerfile
@@ -118,40 +113,26 @@ func NewBuildCommand(dockerCli command.Cli) *cobra.Command {
118113
flags.VarP(&options.tags, "tag", "t", "Name and optionally a tag in the 'name:tag' format")
119114
flags.Var(&options.buildArgs, "build-arg", "Set build-time variables")
120115
flags.Var(options.ulimits, "ulimit", "Ulimit options")
121-
flags.SetAnnotation("ulimit", "no-buildkit", nil)
122116
flags.StringVarP(&options.dockerfileName, "file", "f", "", "Name of the Dockerfile (Default is 'PATH/Dockerfile')")
123117
flags.VarP(&options.memory, "memory", "m", "Memory limit")
124-
flags.SetAnnotation("memory", "no-buildkit", nil)
125118
flags.Var(&options.memorySwap, "memory-swap", "Swap limit equal to memory plus swap: '-1' to enable unlimited swap")
126-
flags.SetAnnotation("memory-swap", "no-buildkit", nil)
127119
flags.Var(&options.shmSize, "shm-size", "Size of /dev/shm")
128-
flags.SetAnnotation("shm-size", "no-buildkit", nil)
129120
flags.Int64VarP(&options.cpuShares, "cpu-shares", "c", 0, "CPU shares (relative weight)")
130-
flags.SetAnnotation("cpu-shares", "no-buildkit", nil)
131121
flags.Int64Var(&options.cpuPeriod, "cpu-period", 0, "Limit the CPU CFS (Completely Fair Scheduler) period")
132-
flags.SetAnnotation("cpu-period", "no-buildkit", nil)
133122
flags.Int64Var(&options.cpuQuota, "cpu-quota", 0, "Limit the CPU CFS (Completely Fair Scheduler) quota")
134-
flags.SetAnnotation("cpu-quota", "no-buildkit", nil)
135123
flags.StringVar(&options.cpuSetCpus, "cpuset-cpus", "", "CPUs in which to allow execution (0-3, 0,1)")
136-
flags.SetAnnotation("cpuset-cpus", "no-buildkit", nil)
137124
flags.StringVar(&options.cpuSetMems, "cpuset-mems", "", "MEMs in which to allow execution (0-3, 0,1)")
138-
flags.SetAnnotation("cpuset-mems", "no-buildkit", nil)
139125
flags.StringVar(&options.cgroupParent, "cgroup-parent", "", "Optional parent cgroup for the container")
140-
flags.SetAnnotation("cgroup-parent", "no-buildkit", nil)
141126
flags.StringVar(&options.isolation, "isolation", "", "Container isolation technology")
142127
flags.Var(&options.labels, "label", "Set metadata for an image")
143128
flags.BoolVar(&options.noCache, "no-cache", false, "Do not use cache when building the image")
144129
flags.BoolVar(&options.rm, "rm", true, "Remove intermediate containers after a successful build")
145-
flags.SetAnnotation("rm", "no-buildkit", nil)
146130
flags.BoolVar(&options.forceRm, "force-rm", false, "Always remove intermediate containers")
147-
flags.SetAnnotation("force-rm", "no-buildkit", nil)
148131
flags.BoolVarP(&options.quiet, "quiet", "q", false, "Suppress the build output and print image ID on success")
149132
flags.BoolVar(&options.pull, "pull", false, "Always attempt to pull a newer version of the image")
150133
flags.StringSliceVar(&options.cacheFrom, "cache-from", []string{}, "Images to consider as cache sources")
151134
flags.BoolVar(&options.compress, "compress", false, "Compress the build context using gzip")
152-
flags.SetAnnotation("compress", "no-buildkit", nil)
153135
flags.StringSliceVar(&options.securityOpt, "security-opt", []string{}, "Security options")
154-
flags.SetAnnotation("security-opt", "no-buildkit", nil)
155136
flags.StringVar(&options.networkMode, "network", "default", "Set the networking mode for the RUN instructions during build")
156137
flags.SetAnnotation("network", "version", []string{"1.25"})
157138
flags.Var(&options.extraHosts, "add-host", "Add a custom host-to-IP mapping (host:ip)")
@@ -162,7 +143,6 @@ func NewBuildCommand(dockerCli command.Cli) *cobra.Command {
162143

163144
flags.StringVar(&options.platform, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
164145
flags.SetAnnotation("platform", "version", []string{"1.38"})
165-
flags.SetAnnotation("platform", "buildkit", nil)
166146

167147
flags.BoolVar(&options.squash, "squash", false, "Squash newly built layers into a single new layer")
168148
flags.SetAnnotation("squash", "experimental", nil)
@@ -171,21 +151,6 @@ func NewBuildCommand(dockerCli command.Cli) *cobra.Command {
171151
flags.BoolVar(&options.stream, "stream", false, "Stream attaches to server to negotiate build context")
172152
flags.MarkHidden("stream")
173153

174-
flags.StringVar(&options.progress, "progress", "auto", "Set type of progress output (auto, plain, tty). Use plain to show container output")
175-
flags.SetAnnotation("progress", "buildkit", nil)
176-
177-
flags.StringArrayVar(&options.secrets, "secret", []string{}, "Secret file to expose to the build (only if BuildKit enabled): id=mysecret,src=/local/secret")
178-
flags.SetAnnotation("secret", "version", []string{"1.39"})
179-
flags.SetAnnotation("secret", "buildkit", nil)
180-
181-
flags.StringArrayVar(&options.ssh, "ssh", []string{}, "SSH agent socket or keys to expose to the build (only if BuildKit enabled) (format: default|<id>[=<socket>|<key>[,<key>]])")
182-
flags.SetAnnotation("ssh", "version", []string{"1.39"})
183-
flags.SetAnnotation("ssh", "buildkit", nil)
184-
185-
flags.StringArrayVarP(&options.outputs, "output", "o", []string{}, "Output destination (format: type=local,dest=path)")
186-
flags.SetAnnotation("output", "version", []string{"1.40"})
187-
flags.SetAnnotation("output", "buildkit", nil)
188-
189154
return cmd
190155
}
191156

@@ -207,15 +172,8 @@ func (out *lastProgressOutput) WriteProgress(prog progress.Progress) error {
207172

208173
// nolint: gocyclo
209174
func runBuild(dockerCli command.Cli, options buildOptions) error {
210-
buildkitEnabled, err := command.BuildKitEnabled(dockerCli.ServerInfo())
211-
if err != nil {
212-
return err
213-
}
214-
if buildkitEnabled {
215-
return runBuildBuildKit(dockerCli, options)
216-
}
217-
218175
var (
176+
err error
219177
buildCtx io.ReadCloser
220178
dockerfileCtx io.ReadCloser
221179
contextDir string
@@ -226,6 +184,12 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
226184
remote string
227185
)
228186

187+
if !options.quiet {
188+
_, _ = fmt.Fprint(dockerCli.Err(), `WARNING: The legacy builder is in use and will build your image in an inefficient way.
189+
190+
`)
191+
}
192+
229193
if options.stream {
230194
_, _ = fmt.Fprint(dockerCli.Err(), `DEPRECATED: The experimental --stream flag has been removed and the build context
231195
will be sent non-streaming. Enable BuildKit instead with DOCKER_BUILDKIT=1
@@ -609,58 +573,3 @@ func imageBuildOptions(dockerCli command.Cli, options buildOptions) types.ImageB
609573
Platform: options.platform,
610574
}
611575
}
612-
613-
func parseOutputs(inp []string) ([]types.ImageBuildOutput, error) {
614-
var outs []types.ImageBuildOutput
615-
if len(inp) == 0 {
616-
return nil, nil
617-
}
618-
for _, s := range inp {
619-
csvReader := csv.NewReader(strings.NewReader(s))
620-
fields, err := csvReader.Read()
621-
if err != nil {
622-
return nil, err
623-
}
624-
if len(fields) == 1 && fields[0] == s && !strings.HasPrefix(s, "type=") {
625-
if s == "-" {
626-
outs = append(outs, types.ImageBuildOutput{
627-
Type: "tar",
628-
Attrs: map[string]string{
629-
"dest": s,
630-
},
631-
})
632-
} else {
633-
outs = append(outs, types.ImageBuildOutput{
634-
Type: "local",
635-
Attrs: map[string]string{
636-
"dest": s,
637-
},
638-
})
639-
}
640-
continue
641-
}
642-
643-
out := types.ImageBuildOutput{
644-
Attrs: map[string]string{},
645-
}
646-
for _, field := range fields {
647-
parts := strings.SplitN(field, "=", 2)
648-
if len(parts) != 2 {
649-
return nil, errors.Errorf("invalid value %s", field)
650-
}
651-
key := strings.ToLower(parts[0])
652-
value := parts[1]
653-
switch key {
654-
case "type":
655-
out.Type = value
656-
default:
657-
out.Attrs[key] = value
658-
}
659-
}
660-
if out.Type == "" {
661-
return nil, errors.Errorf("type is required for output")
662-
}
663-
outs = append(outs, out)
664-
}
665-
return outs, nil
666-
}

0 commit comments

Comments
 (0)