@@ -47,6 +47,19 @@ import (
4747 "github.com/docker/compose/v2/pkg/utils"
4848)
4949
50+ const (
51+ // ComposeParallelLimit set the limit running concurrent operation on docker engine
52+ ComposeParallelLimit = "COMPOSE_PARALLEL_LIMIT"
53+ // ComposeProjectName define the project name to be used, instead of guessing from parent directory
54+ ComposeProjectName = "COMPOSE_PROJECT_NAME"
55+ // ComposeCompatibility try to mimic compose v1 as much as possible
56+ ComposeCompatibility = "COMPOSE_COMPATIBILITY"
57+ // ComposeRemoveOrphans remove “orphaned" containers, i.e. containers tagged for current project but not declared as service
58+ ComposeRemoveOrphans = "COMPOSE_REMOVE_ORPHANS"
59+ // ComposeIgnoreOrphans ignore "orphaned" containers
60+ ComposeIgnoreOrphans = "COMPOSE_IGNORE_ORPHANS"
61+ )
62+
5063// Command defines a compose CLI command as a func with args
5164type Command func (context.Context , []string ) error
5265
@@ -145,7 +158,7 @@ func (o *ProjectOptions) projectOrName(services ...string) (*types.Project, stri
145158 if len (o .ConfigPaths ) > 0 || o .ProjectName == "" {
146159 p , err := o .ToProject (services , cli .WithDiscardEnvFile )
147160 if err != nil {
148- envProjectName := os .Getenv ("COMPOSE_PROJECT_NAME" )
161+ envProjectName := os .Getenv (ComposeProjectName )
149162 if envProjectName != "" {
150163 return nil , envProjectName , nil
151164 }
@@ -162,7 +175,7 @@ func (o *ProjectOptions) toProjectName() (string, error) {
162175 return o .ProjectName , nil
163176 }
164177
165- envProjectName := os .Getenv ("COMPOSE_PROJECT_NAME " )
178+ envProjectName := os .Getenv ("ComposeProjectName " )
166179 if envProjectName != "" {
167180 return envProjectName , nil
168181 }
@@ -180,7 +193,7 @@ func (o *ProjectOptions) ToProject(services []string, po ...cli.ProjectOptionsFn
180193 return nil , compose .WrapComposeError (err )
181194 }
182195
183- if o .Compatibility || utils .StringToBool (options .Environment ["COMPOSE_COMPATIBILITY" ]) {
196+ if o .Compatibility || utils .StringToBool (options .Environment [ComposeCompatibility ]) {
184197 api .Separator = "_"
185198 }
186199
@@ -339,10 +352,22 @@ func RootCommand(streams command.Cli, backend api.Service) *cobra.Command { //no
339352 opts .EnvFiles [i ] = file
340353 }
341354 }
342- if v , ok := os .LookupEnv ("COMPOSE_PARALLEL_LIMIT" ); ok && ! cmd .Flags ().Changed ("parallel" ) {
355+
356+ composeCmd := cmd
357+ for {
358+ if composeCmd .Name () == PluginName {
359+ break
360+ }
361+ if ! composeCmd .HasParent () {
362+ return fmt .Errorf ("error parsing command line, expected %q" , PluginName )
363+ }
364+ composeCmd = composeCmd .Parent ()
365+ }
366+
367+ if v , ok := os .LookupEnv (ComposeParallelLimit ); ok && ! composeCmd .Flags ().Changed ("parallel" ) {
343368 i , err := strconv .Atoi (v )
344369 if err != nil {
345- return fmt .Errorf ("COMPOSE_PARALLEL_LIMIT must be an integer (found: %q)" , v )
370+ return fmt .Errorf ("%s must be an integer (found: %q)" , ComposeParallelLimit , v )
346371 }
347372 parallel = i
348373 }
0 commit comments