Skip to content

Commit fd8ab2f

Browse files
authored
watch: enable tar-based syncer by default (docker#10877)
Swap the default implementation now that batching is merged. Keeping the `docker cp` based implementation around for the moment, but it needs to be _explicitly_ disabled now by setting `COMPOSE_EXPERIMENTAL_WATCH_TAR=0`. After the next release, we should remove the `docker cp` implementation entirely. Signed-off-by: Milas Bowman <[email protected]>
1 parent b406b39 commit fd8ab2f

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

pkg/compose/watch.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,32 @@ type fileEvent struct {
6767
Action WatchAction
6868
}
6969

70+
// getSyncImplementation returns the the tar-based syncer unless it has been explicitly
71+
// disabled with `COMPOSE_EXPERIMENTAL_WATCH_TAR=0`. Note that the absence of the env
72+
// var means enabled.
73+
func (s *composeService) getSyncImplementation(project *types.Project) sync.Syncer {
74+
var useTar bool
75+
if useTarEnv, ok := os.LookupEnv("COMPOSE_EXPERIMENTAL_WATCH_TAR"); ok {
76+
useTar, _ = strconv.ParseBool(useTarEnv)
77+
} else {
78+
useTar = true
79+
}
80+
if useTar {
81+
return sync.NewTar(project.Name, tarDockerClient{s: s})
82+
}
83+
84+
return sync.NewDockerCopy(project.Name, s, s.stdinfo())
85+
}
86+
7087
func (s *composeService) Watch(ctx context.Context, project *types.Project, services []string, _ api.WatchOptions) error { //nolint: gocyclo
7188
_, err := s.prepareProjectForBuild(project, nil)
7289
if err != nil {
7390
return err
7491
}
75-
var syncer sync.Syncer
76-
if useTar, _ := strconv.ParseBool(os.Getenv("COMPOSE_EXPERIMENTAL_WATCH_TAR")); useTar {
77-
syncer = sync.NewTar(project.Name, tarDockerClient{s: s})
78-
} else {
79-
syncer = sync.NewDockerCopy(project.Name, s, s.stdinfo())
80-
}
81-
8292
if err := project.ForServices(services); err != nil {
8393
return err
8494
}
85-
95+
syncer := s.getSyncImplementation(project)
8696
eg, ctx := errgroup.WithContext(ctx)
8797
watching := false
8898
for i := range project.Services {

pkg/e2e/watch_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"os"
2222
"path/filepath"
23+
"strconv"
2324
"strings"
2425
"sync/atomic"
2526
"testing"
@@ -73,9 +74,7 @@ func doTest(t *testing.T, svcName string, tarSync bool) {
7374
env := []string{
7475
"COMPOSE_FILE=" + composeFilePath,
7576
"COMPOSE_PROJECT_NAME=" + projName,
76-
}
77-
if tarSync {
78-
env = append(env, "COMPOSE_EXPERIMENTAL_WATCH_TAR=1")
77+
"COMPOSE_EXPERIMENTAL_WATCH_TAR=" + strconv.FormatBool(tarSync),
7978
}
8079

8180
cli := NewCLI(t, WithEnv(env...))

0 commit comments

Comments
 (0)