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

Method executePlugin

pkg/compose/plugins.go:108–190  ·  pkg/compose/plugins.go::composeService.executePlugin
(cmd *exec.Cmd, command string, service types.ServiceConfig)

Source from the content-addressed store, hash-verified

106}
107
108func (s *composeService) executePlugin(cmd *exec.Cmd, command string, service types.ServiceConfig) (pluginVariables, error) { //nolint:gocyclo
109 var action string
110 switch command {
111 case "up":
112 s.events.On(creatingEvent(service.Name))
113 action = "create"
114 case "down":
115 s.events.On(removingEvent(service.Name))
116 action = "remove"
117 case "stop":
118 s.events.On(stoppingEvent(service.Name))
119 action = "stop"
120 default:
121 return pluginVariables{}, fmt.Errorf("unsupported plugin command: %s", command)
122 }
123
124 stdout, err := cmd.StdoutPipe()
125 if err != nil {
126 return pluginVariables{}, err
127 }
128
129 err = cmd.Start()
130 if err != nil {
131 return pluginVariables{}, err
132 }
133
134 decoder := json.NewDecoder(stdout)
135 defer func() { _ = stdout.Close() }()
136
137 variables := pluginVariables{
138 prefixed: types.Mapping{},
139 raw: types.Mapping{},
140 }
141
142 for {
143 var msg JsonMessage
144 err = decoder.Decode(&msg)
145 if errors.Is(err, io.EOF) {
146 break
147 }
148 if err != nil {
149 return pluginVariables{}, err
150 }
151 switch msg.Type {
152 case ErrorType:
153 s.events.On(newEvent(service.Name, api.Error, firstLine(msg.Message)))
154 return pluginVariables{}, errors.New(msg.Message)
155 case InfoType:
156 s.events.On(newEvent(service.Name, api.Working, firstLine(msg.Message)))
157 case SetEnvType:
158 key, val, found := strings.Cut(msg.Message, "=")
159 if !found {
160 return pluginVariables{}, fmt.Errorf("invalid response from plugin: %s", msg.Message)
161 }
162 variables.prefixed[key] = val
163 case RawSetEnvType:
164 key, val, found := strings.Cut(msg.Message, "=")
165 if !found {

Callers 1

runPluginMethod · 0.95

Calls 14

creatingEventFunction · 0.85
removingEventFunction · 0.85
stoppingEventFunction · 0.85
newEventFunction · 0.85
firstLineFunction · 0.85
errorEventFunction · 0.85
createdEventFunction · 0.85
removedEventFunction · 0.85
stoppedEventFunction · 0.85
ErrorMethod · 0.80
OnMethod · 0.65
StartMethod · 0.65

Tested by

no test coverage detected