CreateComposeProject creates a compose project from a string
(yamlStr string)
| 311 | |
| 312 | // CreateComposeProject creates a compose project from a string |
| 313 | func CreateComposeProject(yamlStr string) (*types.Project, error) { |
| 314 | project, err := loader.LoadWithContext( |
| 315 | context.Background(), |
| 316 | types.ConfigDetails{ |
| 317 | ConfigFiles: []types.ConfigFile{ |
| 318 | {Content: []byte(yamlStr)}, |
| 319 | }, |
| 320 | }, |
| 321 | loader.WithProfiles([]string{`*`}), |
| 322 | ) |
| 323 | if err != nil { |
| 324 | return project, err |
| 325 | } |
| 326 | // Initialize Networks, Services, and Volumes to empty maps if nil |
| 327 | if project.Networks == nil { |
| 328 | project.Networks = types.Networks{} |
| 329 | } |
| 330 | if project.Services == nil { |
| 331 | project.Services = types.Services{} |
| 332 | } |
| 333 | if project.Volumes == nil { |
| 334 | project.Volumes = types.Volumes{} |
| 335 | } |
| 336 | // Ensure nested fields like Labels, Networks, and Environment are initialized |
| 337 | for name, network := range project.Networks { |
| 338 | if network.Labels == nil { |
| 339 | network.Labels = types.Labels{} |
| 340 | } |
| 341 | project.Networks[name] = network |
| 342 | } |
| 343 | for name, service := range project.Services { |
| 344 | if service.Networks == nil { |
| 345 | service.Networks = map[string]*types.ServiceNetworkConfig{} |
| 346 | } |
| 347 | if service.Environment == nil { |
| 348 | service.Environment = types.MappingWithEquals{} |
| 349 | } |
| 350 | project.Services[name] = service |
| 351 | } |
| 352 | return project, nil |
| 353 | } |
| 354 | |
| 355 | // PullImages pulls images in parallel if they don't exist locally |
| 356 | // If pullAlways is true, it will always pull |
no outgoing calls