Repository: docker/compose
Pull request #11213 (2023-11-21 15:23:12)

in watch mode force pull policy to build for services with both build and develop attributes
This default behaviour will force a rebuild of the service images at watch process startup and be sure containers will be in sync with the local source code

**What I did**
For each service target by `watch` process (with a `develop` configuration) force the pull policy to build to be sure they will be rebuild at watch startup

**Related issue**
<!-- If this is a bug fix, make sure your description includes "fixes #xxxx", or "closes #xxxx" -->

**(not mandatory) A picture of a cute animal, if possible in relation to what you did**
![image](https://github.com/docker/compose/assets/705411/ec2831b5-49a0-4129-b922-dc12c43ee619)


ndeloof: LGTM
A forced-(re)build might take time even with cache (baking a cache-efficient Dockerfile is an art), so I wonder we should guard this by comparison between last modified time for watched files and image's creation date.
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/docker/compose/pull/11213?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=docker) Report
Attention: `5 lines` in your changes are missing coverage. Please review.
> Comparison is base [(`0ab21a2`)](https://app.codecov.io/gh/docker/compose/commit/0ab21a2080b5992246c9d6620f920f32a013e29f?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=docker) 56.83% compared to head [(`0ba63da`)](https://app.codecov.io/gh/docker/compose/pull/11213?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=docker) 56.81%.
> Report is 1 commits behind head on main.

| [Files](https://app.codecov.io/gh/docker/compose/pull/11213?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=docker) | Patch % | Lines |
|---|---|---|
| [cmd/compose/watch.go](https://app.codecov.io/gh/docker/compose/pull/11213?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=docker#diff-Y21kL2NvbXBvc2Uvd2F0Y2guZ28=) | 0.00% | [5 Missing :warning: ](https://app.codecov.io/gh/docker/compose/pull/11213?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=docker) |

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main   #11213      +/-   ##
==========================================
- Coverage   56.83%   56.81%   -0.02%     
==========================================
  Files         133      133              
  Lines       11486    11491       +5     
==========================================
+ Hits         6528     6529       +1     
- Misses       4321     4326       +5     
+ Partials      637      636       -1     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/docker/compose/pull/11213?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=docker).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=docker).


Patch:
diff --git a/cmd/compose/watch.go b/cmd/compose/watch.go
index fa3d19369..7311d9bca 100644
--- a/cmd/compose/watch.go
+++ b/cmd/compose/watch.go
@@ -20,6 +20,8 @@ import (
 	"context"
 	"fmt"
 
+	"github.com/compose-spec/compose-go/types"
+
 	"github.com/docker/cli/cli/command"
 	"github.com/docker/compose/v2/internal/locker"
 	"github.com/docker/compose/v2/pkg/api"
@@ -85,6 +87,12 @@ func runWatch(ctx context.Context, dockerCli command.Cli, backend api.Service, w
 	}
 
 	if !watchOpts.noUp {
+		for index, service := range project.Services {
+			if service.Build != nil && service.Develop != nil {
+				service.PullPolicy = types.PullPolicyBuild
+			}
+			project.Services[index] = service
+		}
 		upOpts := api.UpOptions{
 			Create: api.CreateOptions{
 				Build:                &build,


Test patch:
diff --git a/pkg/compose/kill_test.go b/pkg/compose/kill_test.go
index 2ad0d2120..8705c1b96 100644
--- a/pkg/compose/kill_test.go
+++ b/pkg/compose/kill_test.go
@@ -114,7 +114,7 @@ func testContainer(service string, id string, oneOff bool) moby.Container {
 }
 
 func containerLabels(service string, oneOff bool) map[string]string {
-	workingdir := "/src/pkg/compose/testdata"
+	workingdir, _ := filepath.Abs("testdata")
 	composefile := filepath.Join(workingdir, "compose.yaml")
 	labels := map[string]string{
 		compose.ServiceLabel:     service,