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

Method buildProjectOptions

pkg/compose/loader.go:81–117  ·  view source on GitHub ↗

buildProjectOptions constructs compose-go ProjectOptions from API options

(options api.ProjectLoadOptions, remoteLoaders []loader.ResourceLoader)

Source from the content-addressed store, hash-verified

79
80// buildProjectOptions constructs compose-go ProjectOptions from API options
81func (s *composeService) buildProjectOptions(options api.ProjectLoadOptions, remoteLoaders []loader.ResourceLoader) (*cli.ProjectOptions, error) {
82 opts := []cli.ProjectOptionsFn{
83 cli.WithWorkingDirectory(options.WorkingDir),
84 cli.WithOsEnv,
85 }
86
87 // Add PWD if not present
88 if _, present := os.LookupEnv("PWD"); !present {
89 if pwd, err := os.Getwd(); err == nil {
90 opts = append(opts, cli.WithEnv([]string{"PWD=" + pwd}))
91 }
92 }
93
94 // Add remote loaders
95 for _, r := range remoteLoaders {
96 opts = append(opts, cli.WithResourceLoader(r))
97 }
98
99 opts = append(opts,
100 // Load PWD/.env if present and no explicit --env-file has been set
101 cli.WithEnvFiles(options.EnvFiles...),
102 // read dot env file to populate project environment
103 cli.WithDotEnv,
104 // get compose file path set by COMPOSE_FILE
105 cli.WithConfigFileEnv,
106 // if none was selected, get default compose.yaml file from current dir or parent folder
107 cli.WithDefaultConfigPath,
108 // .. and then, a project directory != PWD maybe has been set so let's load .env file
109 cli.WithEnvFiles(options.EnvFiles...), //nolint:gocritic // intentionally applying cli.WithEnvFiles twice.
110 cli.WithDotEnv, //nolint:gocritic // intentionally applying cli.WithDotEnv twice.
111 // eventually COMPOSE_PROFILES should have been set
112 cli.WithDefaultProfiles(options.Profiles...),
113 cli.WithName(options.ProjectName),
114 )
115
116 return cli.NewProjectOptions(options.ConfigPaths, append(options.ProjectOptionsFns, opts...)...)
117}
118
119// postProcessProject applies post-loading transformations to the project
120func (s *composeService) postProcessProject(project *types.Project, options api.ProjectLoadOptions) (*types.Project, error) {

Callers 1

LoadProjectMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected