MCPcopy Create free account
hub / github.com/compose-spec/compose-go / ModelToProject

Function ModelToProject

loader/loader.go:593–663  ·  view source on GitHub ↗

ModelToProject binds a canonical yaml dict into compose-go structs

(dict map[string]interface{}, opts *Options, configDetails types.ConfigDetails)

Source from the content-addressed store, hash-verified

591
592// ModelToProject binds a canonical yaml dict into compose-go structs
593func ModelToProject(dict map[string]interface{}, opts *Options, configDetails types.ConfigDetails) (*types.Project, error) {
594 project := &types.Project{
595 Name: opts.projectName,
596 WorkingDir: configDetails.WorkingDir,
597 Environment: configDetails.Environment,
598 }
599 delete(dict, "name") // project name set by yaml must be identified by caller as opts.projectName
600
601 var err error
602 dict, err = processExtensions(dict, tree.NewPath(), opts.KnownExtensions)
603 if err != nil {
604 return nil, err
605 }
606
607 err = Transform(dict, project)
608 if err != nil {
609 return nil, err
610 }
611
612 if opts.ConvertWindowsPaths {
613 for i, service := range project.Services {
614 for j, volume := range service.Volumes {
615 service.Volumes[j] = convertVolumePath(volume)
616 }
617 project.Services[i] = service
618 }
619 }
620
621 if project, err = project.WithProfiles(opts.Profiles); err != nil {
622 return nil, err
623 }
624
625 if !opts.SkipConsistencyCheck {
626 err := checkConsistency(project)
627 if err != nil {
628 return nil, err
629 }
630 }
631
632 if len(opts.SelectedServices) > 0 {
633 // WithServicesEnabled must precede WithSelectedServices: the latter walks
634 // only active services, so any selected service currently sitting in
635 // DisabledServices (e.g. gated by a profile) would otherwise be invisible.
636 project, err = project.WithServicesEnabled(opts.SelectedServices...)
637 if err != nil {
638 return nil, err
639 }
640 project, err = project.WithSelectedServices(opts.SelectedServices)
641 if err != nil {
642 return nil, err
643 }
644 }
645
646 if opts.PruneUnnecessaryResources {
647 project = project.WithoutUnnecessaryResources()
648 }
649
650 if !opts.SkipResolveEnvironment {

Callers 1

LoadWithContextFunction · 0.85

Calls 11

WithProfilesMethod · 0.95
WithServicesEnabledMethod · 0.95
WithSelectedServicesMethod · 0.95
NewPathFunction · 0.92
processExtensionsFunction · 0.85
TransformFunction · 0.85
convertVolumePathFunction · 0.85
checkConsistencyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…