Skip to content

Commit

Permalink
Enable .env file support
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward J committed Jun 14, 2024
1 parent eaa6d73 commit 089efab
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/pkg/cli/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func TestCreateTarballReader(t *testing.T) {
}
defer g.Close()

expected := []string{".dockerignore", "Dockerfile", "fileName.env"}
expected := []string{".dockerignore", ".env", "Dockerfile", "fileName.env"}
var actual []string
ar := tar.NewReader(g)
for {
Expand Down
8 changes: 6 additions & 2 deletions src/pkg/cli/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,19 @@ func getDefaultProjectOptions(workingDir string, extraOpts ...cli.ProjectOptions
// First apply os.Environment, always win
// -- DISABLED -- cli.WithOsEnv,
// Load PWD/.env if present and no explicit --env-file has been set
// -- NO SUCH PARAM YET -- cli.WithEnvFiles(o.EnvFiles...), TODO: Do we support env files?
cli.WithEnvFiles(), // TODO: Support --env-file to be added as param to this call
// read dot env file to populate project environment
// -- DISABLED -- cli.WithDotEnv,
cli.WithDotEnv,
// get compose file path set by COMPOSE_FILE
cli.WithConfigFileEnv,
// if none was selected, get default compose.yaml file from current dir or parent folder
cli.WithDefaultConfigPath,
// cli.WithName(o.ProjectName)

// .. and then, a project directory != PWD maybe has been set so let's load .env file
cli.WithEnvFiles(), // TODO: Support --env-file to be added as param to this call
cli.WithDotEnv,

// DEFANG SPECIFIC OPTIONS
cli.WithDefaultProfiles("defang"),
cli.WithDiscardEnvFile,
Expand Down
1 change: 1 addition & 0 deletions src/tests/testproj/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DOTENV=enabled
3 changes: 3 additions & 0 deletions src/tests/testproj/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ services:
- dummy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/"]
environment:
- DOTENV
- DOT_ENV_INTERPOLATION=${DOTENV}
# disable: true

# dfnx:
Expand Down
2 changes: 2 additions & 0 deletions src/tests/testproj/compose.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ services:
cpus: 0.25
memory: "268435456"
environment:
DOT_ENV_INTERPOLATION: enabled
DOTENV: enabled
FOO: bar
healthcheck:
test:
Expand Down

0 comments on commit 089efab

Please sign in to comment.