ToProject loads a Compose project using the LoadProject API. Accepts optional cli.ProjectOptionsFn to control loader behavior.
(ctx context.Context, dockerCli command.Cli, backend api.Compose, services []string, po ...cli.ProjectOptionsFn)
| 309 | // ToProject loads a Compose project using the LoadProject API. |
| 310 | // Accepts optional cli.ProjectOptionsFn to control loader behavior. |
| 311 | func (o *ProjectOptions) ToProject(ctx context.Context, dockerCli command.Cli, backend api.Compose, services []string, po ...cli.ProjectOptionsFn) (*types.Project, tracing.Metrics, error) { |
| 312 | var metrics tracing.Metrics |
| 313 | remotes := o.remoteLoaders(dockerCli) |
| 314 | |
| 315 | // Setup metrics listener to collect project data |
| 316 | metricsListener := func(event string, metadata map[string]any) { |
| 317 | switch event { |
| 318 | case "extends": |
| 319 | metrics.CountExtends++ |
| 320 | case "include": |
| 321 | paths := metadata["path"].(types.StringList) |
| 322 | for _, path := range paths { |
| 323 | var isRemote bool |
| 324 | for _, r := range remotes { |
| 325 | if r.Accept(path) { |
| 326 | isRemote = true |
| 327 | break |
| 328 | } |
| 329 | } |
| 330 | if isRemote { |
| 331 | metrics.CountIncludesRemote++ |
| 332 | } else { |
| 333 | metrics.CountIncludesLocal++ |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | loadOpts := api.ProjectLoadOptions{ |
| 340 | ProjectName: o.ProjectName, |
| 341 | ConfigPaths: o.ConfigPaths, |
| 342 | WorkingDir: o.ProjectDir, |
| 343 | EnvFiles: o.EnvFiles, |
| 344 | Profiles: o.Profiles, |
| 345 | Services: services, |
| 346 | Offline: o.Offline, |
| 347 | All: o.All, |
| 348 | Compatibility: o.Compatibility, |
| 349 | ProjectOptionsFns: po, |
| 350 | LoadListeners: []api.LoadListener{metricsListener}, |
| 351 | OCI: api.OCIOptions{ |
| 352 | InsecureRegistries: o.insecureRegistries, |
| 353 | }, |
| 354 | } |
| 355 | |
| 356 | project, err := backend.LoadProject(ctx, loadOpts) |
| 357 | if err != nil { |
| 358 | return nil, metrics, err |
| 359 | } |
| 360 | |
| 361 | return project, metrics, nil |
| 362 | } |
| 363 | |
| 364 | func (o *ProjectOptions) remoteLoaders(dockerCli command.Cli) []loader.ResourceLoader { |
| 365 | if o.remoteLoadersOverride != nil { |
no test coverage detected