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

Method SetModelVariables

pkg/compose/model.go:196–238  ·  pkg/compose/model.go::modelAPI.SetModelVariables
(ctx context.Context, project *types.Project)

Source from the content-addressed store, hash-verified

194}
195
196func (m *modelAPI) SetModelVariables(ctx context.Context, project *types.Project) error {
197 cmd := exec.CommandContext(ctx, m.path, "status", "--json")
198 err := m.prepare(ctx, cmd)
199 if err != nil {
200 return err
201 }
202
203 statusOut, err := cmd.CombinedOutput()
204 if err != nil {
205 return fmt.Errorf("error checking docker-model status: %w", err)
206 }
207 type Status struct {
208 Endpoint string `json:"endpoint"`
209 }
210
211 var status Status
212 err = json.Unmarshal(statusOut, &status)
213 if err != nil {
214 return err
215 }
216
217 for _, service := range project.Services {
218 for ref, modelConfig := range service.Models {
219 model := project.Models[ref]
220 varPrefix := strings.ReplaceAll(strings.ToUpper(ref), "-", "_")
221 var variable string
222 if modelConfig != nil && modelConfig.ModelVariable != "" {
223 variable = modelConfig.ModelVariable
224 } else {
225 variable = varPrefix + "_MODEL"
226 }
227 service.Environment[variable] = &model.Model
228
229 if modelConfig != nil && modelConfig.EndpointVariable != "" {
230 variable = modelConfig.EndpointVariable
231 } else {
232 variable = varPrefix + "_URL"
233 }
234 service.Environment[variable] = &status.Endpoint
235 }
236 }
237 return nil
238}
239
240type Model struct {
241 Id string `json:"id"`

Callers 1

ensureModelsMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected