watch: enable tar-based syncer by default (#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 <milas.bowman@docker.com>
This commit is contained in:
Milas Bowman 2023-08-04 16:58:01 -04:00 committed by GitHub
parent b406b393bf
commit fd8ab2f7ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 11 deletions

View File

@ -67,22 +67,32 @@ type fileEvent struct {
Action WatchAction Action WatchAction
} }
// getSyncImplementation returns the the tar-based syncer unless it has been explicitly
// disabled with `COMPOSE_EXPERIMENTAL_WATCH_TAR=0`. Note that the absence of the env
// var means enabled.
func (s *composeService) getSyncImplementation(project *types.Project) sync.Syncer {
var useTar bool
if useTarEnv, ok := os.LookupEnv("COMPOSE_EXPERIMENTAL_WATCH_TAR"); ok {
useTar, _ = strconv.ParseBool(useTarEnv)
} else {
useTar = true
}
if useTar {
return sync.NewTar(project.Name, tarDockerClient{s: s})
}
return sync.NewDockerCopy(project.Name, s, s.stdinfo())
}
func (s *composeService) Watch(ctx context.Context, project *types.Project, services []string, _ api.WatchOptions) error { //nolint: gocyclo func (s *composeService) Watch(ctx context.Context, project *types.Project, services []string, _ api.WatchOptions) error { //nolint: gocyclo
_, err := s.prepareProjectForBuild(project, nil) _, err := s.prepareProjectForBuild(project, nil)
if err != nil { if err != nil {
return err return err
} }
var syncer sync.Syncer
if useTar, _ := strconv.ParseBool(os.Getenv("COMPOSE_EXPERIMENTAL_WATCH_TAR")); useTar {
syncer = sync.NewTar(project.Name, tarDockerClient{s: s})
} else {
syncer = sync.NewDockerCopy(project.Name, s, s.stdinfo())
}
if err := project.ForServices(services); err != nil { if err := project.ForServices(services); err != nil {
return err return err
} }
syncer := s.getSyncImplementation(project)
eg, ctx := errgroup.WithContext(ctx) eg, ctx := errgroup.WithContext(ctx)
watching := false watching := false
for i := range project.Services { for i := range project.Services {

View File

@ -20,6 +20,7 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
"sync/atomic" "sync/atomic"
"testing" "testing"
@ -73,9 +74,7 @@ func doTest(t *testing.T, svcName string, tarSync bool) {
env := []string{ env := []string{
"COMPOSE_FILE=" + composeFilePath, "COMPOSE_FILE=" + composeFilePath,
"COMPOSE_PROJECT_NAME=" + projName, "COMPOSE_PROJECT_NAME=" + projName,
} "COMPOSE_EXPERIMENTAL_WATCH_TAR=" + strconv.FormatBool(tarSync),
if tarSync {
env = append(env, "COMPOSE_EXPERIMENTAL_WATCH_TAR=1")
} }
cli := NewCLI(t, WithEnv(env...)) cli := NewCLI(t, WithEnv(env...))