@@ -383,32 +383,38 @@ func (o *ProjectOptions) remoteLoaders(dockerCli command.Cli) []loader.ResourceL
383383}
384384
385385func (o * ProjectOptions ) toProjectOptions (po ... cli.ProjectOptionsFn ) (* cli.ProjectOptions , error ) {
386- pwd , err := os .Getwd ()
387- if err != nil {
388- return nil , err
386+ envOptions := []cli.ProjectOptionsFn {
387+ cli .WithWorkingDirectory (o .ProjectDir ),
388+ // First apply os.Environment, always win
389+ cli .WithOsEnv ,
390+ }
391+
392+ if _ , present := os .LookupEnv ("PWD" ); ! present {
393+ if pwd , err := os .Getwd (); err != nil {
394+ return nil , err
395+ } else {
396+ envOptions = append (envOptions , cli .WithEnv ([]string {"PWD=" + pwd }))
397+ }
389398 }
390399
391- return cli .NewProjectOptions (o .ConfigPaths ,
392- append (po ,
393- cli .WithWorkingDirectory (o .ProjectDir ),
394- // First apply os.Environment, always win
395- cli .WithOsEnv ,
396- // set PWD as this variable is not consistently supported on Windows
397- cli .WithEnv ([]string {"PWD=" + pwd }),
398- // Load PWD/.env if present and no explicit --env-file has been set
399- cli .WithEnvFiles (o .EnvFiles ... ),
400- // read dot env file to populate project environment
401- cli .WithDotEnv ,
402- // get compose file path set by COMPOSE_FILE
403- cli .WithConfigFileEnv ,
404- // if none was selected, get default compose.yaml file from current dir or parent folder
405- cli .WithDefaultConfigPath ,
406- // .. and then, a project directory != PWD maybe has been set so let's load .env file
407- cli .WithEnvFiles (o .EnvFiles ... ),
408- cli .WithDotEnv ,
409- // eventually COMPOSE_PROFILES should have been set
410- cli .WithDefaultProfiles (o .Profiles ... ),
411- cli .WithName (o .ProjectName ))... )
400+ envOptions = append (envOptions ,
401+ // Load PWD/.env if present and no explicit --env-file has been set
402+ cli .WithEnvFiles (o .EnvFiles ... ),
403+ // read dot env file to populate project environment
404+ cli .WithDotEnv ,
405+ // get compose file path set by COMPOSE_FILE
406+ cli .WithConfigFileEnv ,
407+ // if none was selected, get default compose.yaml file from current dir or parent folder
408+ cli .WithDefaultConfigPath ,
409+ // .. and then, a project directory != PWD maybe has been set so let's load .env file
410+ cli .WithEnvFiles (o .EnvFiles ... ),
411+ cli .WithDotEnv ,
412+ // eventually COMPOSE_PROFILES should have been set
413+ cli .WithDefaultProfiles (o .Profiles ... ),
414+ cli .WithName (o .ProjectName ),
415+ )
416+
417+ return cli .NewProjectOptions (o .ConfigPaths , append (po , envOptions ... )... )
412418}
413419
414420// PluginName is the name of the plugin
0 commit comments