浏览代码

add deprecation warning for x-initialSync + e2e test

Signed-off-by: Guillaume Lours <[email protected]>
Guillaume Lours 2 月之前
父节点
当前提交
df3c27c864
共有 4 个文件被更改,包括 59 次插入5 次删除
  1. 19 5
      pkg/compose/watch.go
  2. 1 0
      pkg/e2e/fixtures/watch/exec.yaml
  3. 15 0
      pkg/e2e/fixtures/watch/x-initialSync.yaml
  4. 24 0
      pkg/e2e/watch_test.go

+ 19 - 5
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)

+ 1 - 0
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"

+ 15 - 0
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

+ 24 - 0
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")
+}