@@ -47,6 +47,19 @@ import (
47
47
"github.com/docker/compose/v2/pkg/utils"
48
48
)
49
49
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
+
50
63
// Command defines a compose CLI command as a func with args
51
64
type Command func (context.Context , []string ) error
52
65
@@ -145,7 +158,7 @@ func (o *ProjectOptions) projectOrName(services ...string) (*types.Project, stri
145
158
if len (o .ConfigPaths ) > 0 || o .ProjectName == "" {
146
159
p , err := o .ToProject (services , cli .WithDiscardEnvFile )
147
160
if err != nil {
148
- envProjectName := os .Getenv ("COMPOSE_PROJECT_NAME" )
161
+ envProjectName := os .Getenv (ComposeProjectName )
149
162
if envProjectName != "" {
150
163
return nil , envProjectName , nil
151
164
}
@@ -162,7 +175,7 @@ func (o *ProjectOptions) toProjectName() (string, error) {
162
175
return o .ProjectName , nil
163
176
}
164
177
165
- envProjectName := os .Getenv ("COMPOSE_PROJECT_NAME " )
178
+ envProjectName := os .Getenv ("ComposeProjectName " )
166
179
if envProjectName != "" {
167
180
return envProjectName , nil
168
181
}
@@ -180,7 +193,7 @@ func (o *ProjectOptions) ToProject(services []string, po ...cli.ProjectOptionsFn
180
193
return nil , compose .WrapComposeError (err )
181
194
}
182
195
183
- if o .Compatibility || utils .StringToBool (options .Environment ["COMPOSE_COMPATIBILITY" ]) {
196
+ if o .Compatibility || utils .StringToBool (options .Environment [ComposeCompatibility ]) {
184
197
api .Separator = "_"
185
198
}
186
199
@@ -339,10 +352,22 @@ func RootCommand(streams command.Cli, backend api.Service) *cobra.Command { //no
339
352
opts .EnvFiles [i ] = file
340
353
}
341
354
}
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" ) {
343
368
i , err := strconv .Atoi (v )
344
369
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 )
346
371
}
347
372
parallel = i
348
373
}
0 commit comments