MCPcopy
hub / github.com/docker/compose / runWatch

Function runWatch

cmd/compose/watch.go:68–132  ·  cmd/compose/watch.go::runWatch
(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, watchOpts watchOptions, buildOpts buildOptions, services []string)

Source from the content-addressed store, hash-verified

66}
67
68func runWatch(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, watchOpts watchOptions, buildOpts buildOptions, services []string) error {
69 backend, err := compose.NewComposeService(dockerCli, backendOptions.Options...)
70 if err != nil {
71 return err
72 }
73
74 project, _, err := watchOpts.ToProject(ctx, dockerCli, backend, services)
75 if err != nil {
76 return err
77 }
78
79 if err := applyPlatforms(project, true); err != nil {
80 return err
81 }
82
83 build, err := buildOpts.toAPIBuildOptions(nil)
84 if err != nil {
85 return err
86 }
87
88 // validation done -- ensure we have the lockfile for this project before doing work
89 l, err := locker.NewPidfile(project.Name)
90 if err != nil {
91 return fmt.Errorf("cannot take exclusive lock for project %q: %w", project.Name, err)
92 }
93 if err := l.Lock(); err != nil {
94 return fmt.Errorf("cannot take exclusive lock for project %q: %w", project.Name, err)
95 }
96
97 if !watchOpts.noUp {
98 for index, service := range project.Services {
99 if service.Build != nil && service.Develop != nil {
100 service.PullPolicy = types.PullPolicyBuild
101 }
102 project.Services[index] = service
103 }
104 upOpts := api.UpOptions{
105 Create: api.CreateOptions{
106 Build: &build,
107 Services: services,
108 RemoveOrphans: false,
109 Recreate: api.RecreateDiverged,
110 RecreateDependencies: api.RecreateNever,
111 Inherit: true,
112 QuietPull: buildOpts.quiet,
113 },
114 Start: api.StartOptions{
115 Project: project,
116 Attach: nil,
117 Services: services,
118 },
119 }
120 if err := backend.Up(ctx, project, upOpts); err != nil {
121 return err
122 }
123 }
124
125 consumer := formatter.NewLogConsumer(ctx, dockerCli.Out(), dockerCli.Err(), false, false, false)

Callers 1

watchCommandFunction · 0.85

Calls 11

LockMethod · 0.95
NewComposeServiceFunction · 0.92
NewPidfileFunction · 0.92
NewLogConsumerFunction · 0.92
applyPlatformsFunction · 0.85
toAPIBuildOptionsMethod · 0.80
UpMethod · 0.65
ErrMethod · 0.65
WatchMethod · 0.65
ToProjectMethod · 0.45
OutMethod · 0.45

Tested by

no test coverage detected