From df3c27c864254e1cef916f2240256bd73845e866 Mon Sep 17 00:00:00 2001 From: Guillaume Lours <705411+glours@users.noreply.github.com> Date: Thu, 18 Sep 2025 10:35:08 +0200 Subject: [PATCH] add deprecation warning for x-initialSync + e2e test Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> --- pkg/compose/watch.go | 24 ++++++++++++++++++----- pkg/e2e/fixtures/watch/exec.yaml | 1 + pkg/e2e/fixtures/watch/x-initialSync.yaml | 15 ++++++++++++++ pkg/e2e/watch_test.go | 24 +++++++++++++++++++++++ 4 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 pkg/e2e/fixtures/watch/x-initialSync.yaml diff --git a/pkg/compose/watch.go b/pkg/compose/watch.go index f9f3a2030..ea63de26c 100644 --- a/pkg/compose/watch.go +++ b/pkg/compose/watch.go @@ -231,11 +231,25 @@ func (s *composeService) watch(ctx context.Context, project *types.Project, opti if isSync(trigger) && checkIfPathAlreadyBindMounted(trigger.Path, service.Volumes) { logrus.Warnf("path '%s' also declared by a bind mount volume, this path won't be monitored!\n", trigger.Path) continue - } else if trigger.InitialSync && isSync(trigger) { - // Need to check initial files are in container that are meant to be synced from watch action - err := s.initialSync(ctx, project, service, trigger, syncer) - if err != nil { - return nil, err + } else { + shouldInitialSync := trigger.InitialSync + + // Check legacy extension attribute for backward compatibility + if !shouldInitialSync { + var legacyInitialSync bool + success, err := trigger.Extensions.Get("x-initialSync", &legacyInitialSync) + if err == nil && success && legacyInitialSync { + shouldInitialSync = true + logrus.Warnf("x-initialSync is DEPRECATED, please use the official `initial_sync` attribute\n") + } + } + + if shouldInitialSync && isSync(trigger) { + // Need to check initial files are in container that are meant to be synced from watch action + err := s.initialSync(ctx, project, service, trigger, syncer) + if err != nil { + return nil, err + } } } paths = append(paths, trigger.Path) diff --git a/pkg/e2e/fixtures/watch/exec.yaml b/pkg/e2e/fixtures/watch/exec.yaml index ac1947fb1..9d232ac76 100644 --- a/pkg/e2e/fixtures/watch/exec.yaml +++ b/pkg/e2e/fixtures/watch/exec.yaml @@ -9,6 +9,7 @@ services: watch: - path: . target: /data + initial_sync: true action: sync+exec exec: command: echo "SUCCESS" \ No newline at end of file diff --git a/pkg/e2e/fixtures/watch/x-initialSync.yaml b/pkg/e2e/fixtures/watch/x-initialSync.yaml new file mode 100644 index 000000000..6a954bd6a --- /dev/null +++ b/pkg/e2e/fixtures/watch/x-initialSync.yaml @@ -0,0 +1,15 @@ +services: + test: + build: + dockerfile_inline: FROM alpine + command: ping localhost + volumes: + - /data + develop: + watch: + - path: . + target: /data + action: sync+exec + exec: + command: echo "SUCCESS" + x-initialSync: true \ No newline at end of file diff --git a/pkg/e2e/watch_test.go b/pkg/e2e/watch_test.go index 5c4db4765..360fe5210 100644 --- a/pkg/e2e/watch_test.go +++ b/pkg/e2e/watch_test.go @@ -405,3 +405,27 @@ func TestWatchIncludes(t *testing.T) { c.RunDockerComposeCmdNoCheck(t, "-p", projectName, "kill", "-s", "9") } + +func TestCheckWarningXInitialSyn(t *testing.T) { + c := NewCLI(t) + const projectName = "test_watch_warn_initial_syn" + + defer c.cleanupWithDown(t, projectName) + + tmpdir := t.TempDir() + composeFilePath := filepath.Join(tmpdir, "compose.yaml") + CopyFile(t, filepath.Join("fixtures", "watch", "x-initialSync.yaml"), composeFilePath) + cmd := c.NewDockerComposeCmd(t, "-p", projectName, "-f", composeFilePath, "--verbose", "up", "--watch") + buffer := bytes.NewBuffer(nil) + cmd.Stdout = buffer + watch := icmd.StartCmd(cmd) + + poll.WaitOn(t, func(l poll.LogT) poll.Result { + if strings.Contains(watch.Combined(), "x-initialSync is DEPRECATED, please use the official `initial_sync` attribute") { + return poll.Success() + } + return poll.Continue("%v", watch.Stdout()) + }) + + c.RunDockerComposeCmdNoCheck(t, "-p", projectName, "kill", "-s", "9") +}