add deprecation warning for x-initialSync + e2e test

Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
Guillaume Lours 2025-09-18 10:35:08 +02:00 committed by Nicolas De loof
parent 956891af54
commit df3c27c864
4 changed files with 59 additions and 5 deletions

View File

@ -231,13 +231,27 @@ func (s *composeService) watch(ctx context.Context, project *types.Project, opti
if isSync(trigger) && checkIfPathAlreadyBindMounted(trigger.Path, service.Volumes) { 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) logrus.Warnf("path '%s' also declared by a bind mount volume, this path won't be monitored!\n", trigger.Path)
continue continue
} else if trigger.InitialSync && isSync(trigger) { } 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 // 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) err := s.initialSync(ctx, project, service, trigger, syncer)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} }
}
paths = append(paths, trigger.Path) paths = append(paths, trigger.Path)
} }

View File

@ -9,6 +9,7 @@ services:
watch: watch:
- path: . - path: .
target: /data target: /data
initial_sync: true
action: sync+exec action: sync+exec
exec: exec:
command: echo "SUCCESS" command: echo "SUCCESS"

View File

@ -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

View File

@ -405,3 +405,27 @@ func TestWatchIncludes(t *testing.T) {
c.RunDockerComposeCmdNoCheck(t, "-p", projectName, "kill", "-s", "9") 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")
}