Skip to content

Commit fbcd2aa

Browse files
author
Tibor Vass
committed
build: remove --stream
--stream was always experimental and this patch removes the functionality. Users should enable BuildKit with DOCKER_BUILDKIT=1 Signed-off-by: Tibor Vass <tibor@docker.com>
1 parent 0397c2c commit fbcd2aa

File tree

2 files changed

+5
-149
lines changed

2 files changed

+5
-149
lines changed

cli/command/image/build.go

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"fmt"
1111
"io"
1212
"io/ioutil"
13-
"net"
1413
"os"
1514
"path/filepath"
1615
"regexp"
@@ -33,7 +32,6 @@ import (
3332
"github.com/docker/docker/pkg/urlutil"
3433
units "github.com/docker/go-units"
3534
"github.com/pkg/errors"
36-
"github.com/sirupsen/logrus"
3735
"github.com/spf13/cobra"
3836
)
3937

@@ -165,9 +163,7 @@ func NewBuildCommand(dockerCli command.Cli) *cobra.Command {
165163
flags.SetAnnotation("squash", "version", []string{"1.25"})
166164

167165
flags.BoolVar(&options.stream, "stream", false, "Stream attaches to server to negotiate build context")
168-
flags.SetAnnotation("stream", "experimental", nil)
169-
flags.SetAnnotation("stream", "version", []string{"1.31"})
170-
flags.SetAnnotation("stream", "no-buildkit", nil)
166+
flags.MarkHidden("stream")
171167

172168
flags.StringVar(&options.progress, "progress", "auto", "Set type of progress output (auto, plain, tty). Use plain to show container output")
173169
flags.SetAnnotation("progress", "buildkit", nil)
@@ -224,8 +220,8 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
224220
remote string
225221
)
226222

227-
if options.compress && options.stream {
228-
return errors.New("--compress conflicts with --stream options")
223+
if options.stream {
224+
return errors.New("Experimental flag --stream was removed, enable BuildKit instead with DOCKER_BUILDKIT=1")
229225
}
230226

231227
if options.dockerfileFromStdin() {
@@ -284,7 +280,7 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
284280
}
285281

286282
// read from a directory into tar archive
287-
if buildCtx == nil && !options.stream {
283+
if buildCtx == nil {
288284
excludes, err := build.ReadDockerignore(contextDir)
289285
if err != nil {
290286
return err
@@ -315,16 +311,6 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
315311
}
316312
}
317313

318-
// if streaming and Dockerfile was not from stdin then read from file
319-
// to the same reader that is usually stdin
320-
if options.stream && dockerfileCtx == nil {
321-
dockerfileCtx, err = os.Open(relDockerfile)
322-
if err != nil {
323-
return errors.Wrapf(err, "failed to open %s", relDockerfile)
324-
}
325-
defer dockerfileCtx.Close()
326-
}
327-
328314
ctx, cancel := context.WithCancel(context.Background())
329315
defer cancel()
330316

@@ -367,38 +353,11 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
367353
buildCtx = dockerfileCtx
368354
}
369355

370-
s, err := trySession(dockerCli, contextDir, true)
371-
if err != nil {
372-
return err
373-
}
374-
375356
var body io.Reader
376-
if buildCtx != nil && !options.stream {
357+
if buildCtx != nil {
377358
body = progress.NewProgressReader(buildCtx, progressOutput, 0, "", "Sending build context to Docker daemon")
378359
}
379360

380-
// add context stream to the session
381-
if options.stream && s != nil {
382-
syncDone := make(chan error) // used to signal first progress reporting completed.
383-
// progress would also send errors but don't need it here as errors
384-
// are handled by session.Run() and ImageBuild()
385-
if err := addDirToSession(s, contextDir, progressOutput, syncDone); err != nil {
386-
return err
387-
}
388-
389-
buf := newBufferedWriter(syncDone, buildBuff)
390-
defer func() {
391-
select {
392-
case <-buf.flushed:
393-
case <-ctx.Done():
394-
}
395-
}()
396-
buildBuff = buf
397-
398-
remote = clientSessionRemote
399-
body = buildCtx
400-
}
401-
402361
configFile := dockerCli.ConfigFile()
403362
creds, _ := configFile.GetAllCredentials()
404363
authConfigs := make(map[string]types.AuthConfig, len(creds))
@@ -411,20 +370,6 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
411370
buildOptions.AuthConfigs = authConfigs
412371
buildOptions.RemoteContext = remote
413372

414-
if s != nil {
415-
go func() {
416-
logrus.Debugf("running session: %v", s.ID())
417-
dialSession := func(ctx context.Context, proto string, meta map[string][]string) (net.Conn, error) {
418-
return dockerCli.Client().DialHijack(ctx, "/session", proto, meta)
419-
}
420-
if err := s.Run(ctx, dialSession); err != nil {
421-
logrus.Error(err)
422-
cancel() // cancel progress context
423-
}
424-
}()
425-
buildOptions.SessionID = s.ID()
426-
}
427-
428373
response, err := dockerCli.Client().ImageBuild(ctx, body, buildOptions)
429374
if err != nil {
430375
if options.quiet {

cli/command/image/build_session.go

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
11
package image
22

33
import (
4-
"bytes"
54
"context"
65
"crypto/rand"
76
"crypto/sha256"
87
"encoding/hex"
98
"fmt"
10-
"io"
119
"io/ioutil"
1210
"os"
1311
"path/filepath"
14-
"sync"
15-
"time"
1612

1713
"github.com/docker/cli/cli/command"
18-
"github.com/docker/cli/cli/command/image/build"
1914
cliconfig "github.com/docker/cli/cli/config"
2015
"github.com/docker/docker/api/types/versions"
21-
"github.com/docker/docker/pkg/progress"
2216
"github.com/moby/buildkit/session"
23-
"github.com/moby/buildkit/session/filesync"
2417
"github.com/pkg/errors"
25-
"golang.org/x/time/rate"
2618
)
2719

2820
const clientSessionRemote = "client-session"
@@ -49,87 +41,6 @@ func trySession(dockerCli command.Cli, contextDir string, forStream bool) (*sess
4941
return s, nil
5042
}
5143

52-
func addDirToSession(session *session.Session, contextDir string, progressOutput progress.Output, done chan error) error {
53-
excludes, err := build.ReadDockerignore(contextDir)
54-
if err != nil {
55-
return err
56-
}
57-
58-
p := &sizeProgress{out: progressOutput, action: "Streaming build context to Docker daemon"}
59-
60-
workdirProvider := filesync.NewFSSyncProvider([]filesync.SyncedDir{
61-
{Dir: contextDir, Excludes: excludes},
62-
})
63-
session.Allow(workdirProvider)
64-
65-
// this will be replaced on parallel build jobs. keep the current
66-
// progressbar for now
67-
if snpc, ok := workdirProvider.(interface {
68-
SetNextProgressCallback(func(int, bool), chan error)
69-
}); ok {
70-
snpc.SetNextProgressCallback(p.update, done)
71-
}
72-
73-
return nil
74-
}
75-
76-
type sizeProgress struct {
77-
out progress.Output
78-
action string
79-
limiter *rate.Limiter
80-
}
81-
82-
func (sp *sizeProgress) update(size int, last bool) {
83-
if sp.limiter == nil {
84-
sp.limiter = rate.NewLimiter(rate.Every(100*time.Millisecond), 1)
85-
}
86-
if last || sp.limiter.Allow() {
87-
sp.out.WriteProgress(progress.Progress{Action: sp.action, Current: int64(size), LastUpdate: last})
88-
}
89-
}
90-
91-
type bufferedWriter struct {
92-
done chan error
93-
io.Writer
94-
buf *bytes.Buffer
95-
flushed chan struct{}
96-
mu sync.Mutex
97-
}
98-
99-
func newBufferedWriter(done chan error, w io.Writer) *bufferedWriter {
100-
bw := &bufferedWriter{done: done, Writer: w, buf: new(bytes.Buffer), flushed: make(chan struct{})}
101-
go func() {
102-
<-done
103-
bw.flushBuffer()
104-
}()
105-
return bw
106-
}
107-
108-
func (bw *bufferedWriter) Write(dt []byte) (int, error) {
109-
select {
110-
case <-bw.done:
111-
bw.flushBuffer()
112-
return bw.Writer.Write(dt)
113-
default:
114-
return bw.buf.Write(dt)
115-
}
116-
}
117-
118-
func (bw *bufferedWriter) flushBuffer() {
119-
bw.mu.Lock()
120-
select {
121-
case <-bw.flushed:
122-
default:
123-
bw.Writer.Write(bw.buf.Bytes())
124-
close(bw.flushed)
125-
}
126-
bw.mu.Unlock()
127-
}
128-
129-
func (bw *bufferedWriter) String() string {
130-
return fmt.Sprintf("%s", bw.Writer)
131-
}
132-
13344
func getBuildSharedKey(dir string) (string, error) {
13445
// build session is hash of build dir with node based randomness
13546
s := sha256.Sum256([]byte(fmt.Sprintf("%s:%s", tryNodeIdentifier(), dir)))

0 commit comments

Comments
 (0)