Skip to content

Commit df3c27c

Browse files
gloursndeloof
authored andcommitted
add deprecation warning for x-initialSync + e2e test
Signed-off-by: Guillaume Lours <[email protected]>
1 parent 956891a commit df3c27c

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed

pkg/compose/watch.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,25 @@ func (s *composeService) watch(ctx context.Context, project *types.Project, opti
231231
if isSync(trigger) && checkIfPathAlreadyBindMounted(trigger.Path, service.Volumes) {
232232
logrus.Warnf("path '%s' also declared by a bind mount volume, this path won't be monitored!\n", trigger.Path)
233233
continue
234-
} else if trigger.InitialSync && isSync(trigger) {
235-
// Need to check initial files are in container that are meant to be synced from watch action
236-
err := s.initialSync(ctx, project, service, trigger, syncer)
237-
if err != nil {
238-
return nil, err
234+
} else {
235+
shouldInitialSync := trigger.InitialSync
236+
237+
// Check legacy extension attribute for backward compatibility
238+
if !shouldInitialSync {
239+
var legacyInitialSync bool
240+
success, err := trigger.Extensions.Get("x-initialSync", &legacyInitialSync)
241+
if err == nil && success && legacyInitialSync {
242+
shouldInitialSync = true
243+
logrus.Warnf("x-initialSync is DEPRECATED, please use the official `initial_sync` attribute\n")
244+
}
245+
}
246+
247+
if shouldInitialSync && isSync(trigger) {
248+
// Need to check initial files are in container that are meant to be synced from watch action
249+
err := s.initialSync(ctx, project, service, trigger, syncer)
250+
if err != nil {
251+
return nil, err
252+
}
239253
}
240254
}
241255
paths = append(paths, trigger.Path)

pkg/e2e/fixtures/watch/exec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ services:
99
watch:
1010
- path: .
1111
target: /data
12+
initial_sync: true
1213
action: sync+exec
1314
exec:
1415
command: echo "SUCCESS"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
test:
3+
build:
4+
dockerfile_inline: FROM alpine
5+
command: ping localhost
6+
volumes:
7+
- /data
8+
develop:
9+
watch:
10+
- path: .
11+
target: /data
12+
action: sync+exec
13+
exec:
14+
command: echo "SUCCESS"
15+
x-initialSync: true

pkg/e2e/watch_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,27 @@ func TestWatchIncludes(t *testing.T) {
405405

406406
c.RunDockerComposeCmdNoCheck(t, "-p", projectName, "kill", "-s", "9")
407407
}
408+
409+
func TestCheckWarningXInitialSyn(t *testing.T) {
410+
c := NewCLI(t)
411+
const projectName = "test_watch_warn_initial_syn"
412+
413+
defer c.cleanupWithDown(t, projectName)
414+
415+
tmpdir := t.TempDir()
416+
composeFilePath := filepath.Join(tmpdir, "compose.yaml")
417+
CopyFile(t, filepath.Join("fixtures", "watch", "x-initialSync.yaml"), composeFilePath)
418+
cmd := c.NewDockerComposeCmd(t, "-p", projectName, "-f", composeFilePath, "--verbose", "up", "--watch")
419+
buffer := bytes.NewBuffer(nil)
420+
cmd.Stdout = buffer
421+
watch := icmd.StartCmd(cmd)
422+
423+
poll.WaitOn(t, func(l poll.LogT) poll.Result {
424+
if strings.Contains(watch.Combined(), "x-initialSync is DEPRECATED, please use the official `initial_sync` attribute") {
425+
return poll.Success()
426+
}
427+
return poll.Continue("%v", watch.Stdout())
428+
})
429+
430+
c.RunDockerComposeCmdNoCheck(t, "-p", projectName, "kill", "-s", "9")
431+
}

0 commit comments

Comments
 (0)