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

Support parsing docker-compose style defaults, e.g. FOO="${FOO:-FOO_ENV_DEFAULT}" #153

Open
charlesritchea opened this issue Aug 13, 2021 · 1 comment

Comments

@charlesritchea
Copy link

The latest docker-compose v2 has a regression where it can't load defaults from .env files, which it could in v1, this is "blamed" on the use godotenv, specifically
https://github.com/joho/godotenv/blob/ddf83eb33bbb136f62617a409142b74b91dbcff3/godotenv.go#L330

func expandVariables(v string, m map[string]string) string {
	return expandVarRegex.ReplaceAllStringFunc(v, func(s string) string {
		submatch := expandVarRegex.FindStringSubmatch(s)

		if submatch == nil {
			return s
		}
		if submatch[1] == "\\" || submatch[2] == "(" {
			return submatch[0][1:]
		} else if submatch[4] != "" {
			return m[submatch[4]]
		}
		return s
	})
}

See the discussion here: https://github.com/docker/compose-cli/issues/1900

.env

FOO="${FOO:-FOO_ENV_DEFAULT}"
BAR="${BAR:-BAR_ENV_DEFAULT}"
@joho
Copy link
Owner

joho commented Aug 16, 2021

Generally I've been resistant to accepting non-standard syntax that isn't present in the upstream/original ruby library

That said, docker is docker, and a flagship in the go ecosystem so I'd be happy to accept a PR supporting it and cut a fresh release (which I'm way overdue for)

hoshsadiq added a commit to hoshsadiq/godotenv that referenced this issue Dec 13, 2021
This PR adds some basic support for POSIX like parameter expansion. This
includes the following four scenarios:

- ${VAR:-STRING}	If VAR is empty or unset, use STRING as its value.
- ${VAR-STRING}		If VAR is unset, use STRING as its value.
- ${VAR:+STRING}	If VAR is not empty, use STRING as its value.
- ${VAR+STRING}		If VAR is set, use STRING as its value.

This is in addition to the usual "${VAR}" scenario.

Fixes joho/godotenv#153
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants