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
209174func 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