From 035276e027ec8e177a18f93a4e41c5cfa685b9b0 Mon Sep 17 00:00:00 2001 From: Guillaume Lours <705411+glours@users.noreply.github.com> Date: Tue, 27 Jun 2023 00:56:04 +0200 Subject: [PATCH] watch: add warning when a path is already used by a bind mount volume (#10741) Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> --- pkg/compose/watch.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/compose/watch.go b/pkg/compose/watch.go index 2daefdd3..5de5bc12 100644 --- a/pkg/compose/watch.go +++ b/pkg/compose/watch.go @@ -143,6 +143,10 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv var paths []string for _, trigger := range config.Watch { + if 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 + } paths = append(paths, trigger.Path) } @@ -383,3 +387,12 @@ func debounce(ctx context.Context, clock clockwork.Clock, delay time.Duration, i } } } + +func checkIfPathAlreadyBindMounted(watchPath string, volumes []types.ServiceVolumeConfig) bool { + for _, volume := range volumes { + if volume.Bind != nil && strings.HasPrefix(watchPath, volume.Source) { + return true + } + } + return false +}