Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load: move env var profile detection to option #446

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions cli/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func WithEnv(env []string) ProjectOptionsFn {
}
}

// WithDiscardEnvFiles sets discards the `env_file` section after resolving to
// WithDiscardEnvFile sets discards the `env_file` section after resolving to
// the `environment` section
func WithDiscardEnvFile(o *ProjectOptions) error {
o.loadOptions = append(o.loadOptions, loader.WithDiscardEnvFiles)
Expand All @@ -209,6 +209,15 @@ func WithLoadOptions(loadOptions ...func(*loader.Options)) ProjectOptionsFn {
}
}

// WithDefaultProfiles uses the provided profiles (if any), and falls back to
// profiles specified via the COMPOSE_PROFILES environment variable otherwise.
func WithDefaultProfiles(profile ...string) ProjectOptionsFn {
if len(profile) == 0 {
profile = strings.Split(os.Getenv(consts.ComposeProfiles), ",")
}
return WithProfiles(profile)
}

// WithProfiles sets profiles to be activated
func WithProfiles(profiles []string) ProjectOptionsFn {
return func(o *ProjectOptions) error {
Expand All @@ -228,8 +237,9 @@ func WithOsEnv(o *ProjectOptions) error {
return nil
}

// WithEnvFile set an alternate env file
// deprecated - use WithEnvFiles
// WithEnvFile sets an alternate env file.
//
// Deprecated: use WithEnvFiles instead.
func WithEnvFile(file string) ProjectOptionsFn {
var files []string
if file != "" {
Expand Down
3 changes: 0 additions & 3 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,6 @@ func load(ctx context.Context, configDetails types.ConfigDetails, opts *Options,
}
}

if profiles, ok := project.Environment[consts.ComposeProfiles]; ok && len(opts.Profiles) == 0 {
opts.Profiles = strings.Split(profiles, ",")
}
project.ApplyProfiles(opts.Profiles)

err := project.ResolveServicesEnvironment(opts.discardEnvFiles)
Expand Down
Loading