Skip to content

Commit 42cbfed

Browse files
committed
introduce watch restart action
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent fc56650 commit 42cbfed

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/Microsoft/go-winio v0.6.2
1010
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
1111
github.com/buger/goterm v1.0.4
12-
github.com/compose-spec/compose-go/v2 v2.4.6-0.20241203131247-9a9cc5d9c345
12+
github.com/compose-spec/compose-go/v2 v2.4.6-0.20241211105841-27dbf493c70e
1313
github.com/containerd/containerd v1.7.24
1414
github.com/containerd/platforms v0.2.1
1515
github.com/davecgh/go-spew v1.1.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 h1:QVw89YDxXxEe+l8gU8E
8585
github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
8686
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
8787
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
88-
github.com/compose-spec/compose-go/v2 v2.4.6-0.20241203131247-9a9cc5d9c345 h1:oLm7hga9jjaDedg+dqsWiI1GeRrcGLBPxu8W0VfpiKA=
89-
github.com/compose-spec/compose-go/v2 v2.4.6-0.20241203131247-9a9cc5d9c345/go.mod h1:lFN0DrMxIncJGYAXTfWuajfwj5haBJqrBkarHcnjJKc=
88+
github.com/compose-spec/compose-go/v2 v2.4.6-0.20241211105841-27dbf493c70e h1:MpISkSqxiD7QsuQT1wRQYQ4LZwvugiiyZjGHBwJ6vk0=
89+
github.com/compose-spec/compose-go/v2 v2.4.6-0.20241211105841-27dbf493c70e/go.mod h1:lFN0DrMxIncJGYAXTfWuajfwj5haBJqrBkarHcnjJKc=
9090
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
9191
github.com/containerd/cgroups/v3 v3.0.3 h1:S5ByHZ/h9PMe5IOQoN7E+nMc2UcLEM/V48DGDJ9kip0=
9292
github.com/containerd/cgroups/v3 v3.0.3/go.mod h1:8HBe7V3aWGLFPd/k03swSIsGjZhHI2WzJmticMgVuz0=

pkg/compose/watch.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,17 @@ func (t tarDockerClient) Untar(ctx context.Context, id string, archive io.ReadCl
472472
func (s *composeService) handleWatchBatch(ctx context.Context, project *types.Project, serviceName string, options api.WatchOptions, batch []fileEvent, syncer sync.Syncer) error {
473473
pathMappings := make([]sync.PathMapping, len(batch))
474474
restartService := false
475+
syncService := false
475476
for i := range batch {
476-
if batch[i].Trigger.Action == types.WatchActionRebuild {
477+
switch batch[i].Trigger.Action {
478+
case types.WatchActionRebuild:
477479
return s.rebuild(ctx, project, serviceName, options)
478-
}
479-
if batch[i].Trigger.Action == types.WatchActionSyncRestart {
480+
case types.WatchActionSync, types.WatchActionSyncExec:
481+
syncService = true
482+
case types.WatchActionSyncRestart:
483+
restartService = true
484+
syncService = true
485+
case types.WatchActionRestart:
480486
restartService = true
481487
}
482488
pathMappings[i] = batch[i].PathMapping
@@ -488,8 +494,10 @@ func (s *composeService) handleWatchBatch(ctx context.Context, project *types.Pr
488494
if err != nil {
489495
return err
490496
}
491-
if err := syncer.Sync(ctx, service, pathMappings); err != nil {
492-
return err
497+
if syncService {
498+
if err := syncer.Sync(ctx, service, pathMappings); err != nil {
499+
return err
500+
}
493501
}
494502
if restartService {
495503
err = s.restart(ctx, project.Name, api.RestartOptions{

0 commit comments

Comments
 (0)