@@ -21,7 +21,6 @@ import (
2121 "context"
2222 "encoding/json"
2323 "fmt"
24- "os"
2524 "os/exec"
2625 "slices"
2726 "strconv"
@@ -32,8 +31,6 @@ import (
3231 "github.com/docker/cli/cli-plugins/manager"
3332 "github.com/docker/compose/v2/pkg/progress"
3433 "github.com/spf13/cobra"
35- "go.opentelemetry.io/otel"
36- "go.opentelemetry.io/otel/propagation"
3734 "golang.org/x/sync/errgroup"
3835)
3936
@@ -51,7 +48,11 @@ func (s *composeService) ensureModels(ctx context.Context, project *types.Projec
5148 }
5249
5350 cmd := exec .CommandContext (ctx , dockerModel .Path , "ls" , "--json" )
54- s .setupChildProcess (ctx , cmd )
51+ err = s .prepareShellOut (ctx , project , cmd )
52+ if err != nil {
53+ return err
54+ }
55+
5556 output , err := cmd .CombinedOutput ()
5657 if err != nil {
5758 return fmt .Errorf ("error checking available models: %w" , err )
@@ -85,32 +86,29 @@ func (s *composeService) ensureModels(ctx context.Context, project *types.Projec
8586 eg .Go (func () error {
8687 w := progress .ContextWriter (gctx )
8788 if ! slices .Contains (availableModels , config .Model ) {
88- err = s .pullModel (gctx , dockerModel , config , quietPull , w )
89+ err = s .pullModel (gctx , dockerModel , project , config , quietPull , w )
8990 if err != nil {
9091 return err
9192 }
9293 }
93- err = s .configureModel (gctx , dockerModel , config , w )
94- if err != nil {
95- return err
96- }
97- w .Event (progress .CreatedEvent (config .Name ))
98- return nil
94+ return s .configureModel (gctx , dockerModel , project , config , w )
9995 })
10096 }
10197 return eg .Wait ()
10298}
10399
104- func (s * composeService ) pullModel (ctx context.Context , dockerModel * manager.Plugin , model types.ModelConfig , quietPull bool , w progress.Writer ) error {
100+ func (s * composeService ) pullModel (ctx context.Context , dockerModel * manager.Plugin , project * types. Project , model types.ModelConfig , quietPull bool , w progress.Writer ) error {
105101 w .Event (progress.Event {
106102 ID : model .Name ,
107103 Status : progress .Working ,
108104 Text : "Pulling" ,
109105 })
110106
111107 cmd := exec .CommandContext (ctx , dockerModel .Path , "pull" , model .Model )
112- s .setupChildProcess (ctx , cmd )
113-
108+ err := s .prepareShellOut (ctx , project , cmd )
109+ if err != nil {
110+ return err
111+ }
114112 stream , err := cmd .StdoutPipe ()
115113 if err != nil {
116114 return err
@@ -150,7 +148,7 @@ func (s *composeService) pullModel(ctx context.Context, dockerModel *manager.Plu
150148 return err
151149}
152150
153- func (s * composeService ) configureModel (ctx context.Context , dockerModel * manager.Plugin , config types.ModelConfig , w progress.Writer ) error {
151+ func (s * composeService ) configureModel (ctx context.Context , dockerModel * manager.Plugin , project * types. Project , config types.ModelConfig , w progress.Writer ) error {
154152 w .Event (progress.Event {
155153 ID : config .Name ,
156154 Status : progress .Working ,
@@ -167,13 +165,20 @@ func (s *composeService) configureModel(ctx context.Context, dockerModel *manage
167165 args = append (args , config .RuntimeFlags ... )
168166 }
169167 cmd := exec .CommandContext (ctx , dockerModel .Path , args ... )
170- s .setupChildProcess (ctx , cmd )
168+ err := s .prepareShellOut (ctx , project , cmd )
169+ if err != nil {
170+ return err
171+ }
171172 return cmd .Run ()
172173}
173174
174175func (s * composeService ) setModelVariables (ctx context.Context , dockerModel * manager.Plugin , project * types.Project ) error {
175176 cmd := exec .CommandContext (ctx , dockerModel .Path , "status" , "--json" )
176- s .setupChildProcess (ctx , cmd )
177+ err := s .prepareShellOut (ctx , project , cmd )
178+ if err != nil {
179+ return err
180+ }
181+
177182 statusOut , err := cmd .CombinedOutput ()
178183 if err != nil {
179184 return fmt .Errorf ("error checking docker-model status: %w" , err )
@@ -211,19 +216,6 @@ func (s *composeService) setModelVariables(ctx context.Context, dockerModel *man
211216 return nil
212217}
213218
214- func (s * composeService ) setupChildProcess (gctx context.Context , cmd * exec.Cmd ) {
215- // exec provider command with same environment Compose is running
216- env := types .NewMapping (os .Environ ())
217- // but remove DOCKER_CLI_PLUGIN... variable so plugin can detect it run standalone
218- delete (env , manager .ReexecEnvvar )
219- // propagate opentelemetry context to child process, see https://github.com/open-telemetry/oteps/blob/main/text/0258-env-context-baggage-carriers.md
220- carrier := propagation.MapCarrier {}
221- otel .GetTextMapPropagator ().Inject (gctx , & carrier )
222- env .Merge (types .Mapping (carrier ))
223- env ["DOCKER_CONTEXT" ] = s .dockerCli .CurrentContext ()
224- cmd .Env = env .Values ()
225- }
226-
227219type Model struct {
228220 Id string `json:"id"`
229221 Tags []string `json:"tags"`
0 commit comments