-
Notifications
You must be signed in to change notification settings - Fork 485
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
Missing support for variable interpolation in .env files #718
Comments
I can confirm this. It's easy to reproduce with the DB_NAME=databasename
DB_USER=databaseuser
DB_PASS=databasepassword
POSTGRES_DB=${DB_NAME}
POSTGRES_USER=${DB_USER}
POSTGRES_PASSWORD=${DB_PASS} Something like this causes postgres to fail with the following error in
This issue also seems very similar to #721, they might be duplicates. Meanwhile, using the following in the environment:
POSTGRES_DB: ${DB_NAME}
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASS} |
I'm also seeing that complex variables from the .env file like ${SAMPLE:-$PWD} also do not get the $PWD portion resolved in the yaml compose file, such as for volume mounting. |
AFAICT the
|
I took a look at the source code, and it seems like there is no recursion to handle nested interpolation (which is part of the spec): podman-compose/podman_compose.py Lines 267 to 282 in d704622
Edit 1: After some initial experimentation, it seems like I was overly optimistic in assessing the difficulty of this task. It's pretty evident to me now that it would be practically impossible to implement a reliable nested interpolation parser without bringing in a proper lexer dependency (or worse, raw dogging one ourselves). Regex simply isn't cutting it. I'll continue to work on it but don't expect anything quick. Edit 2: After looking away for a few days and coming back in a less sleep-deprived state, I am finding the problem slightly less intimidating but still quite tricky. I think I will be able to make a regex-based POC but there are some unresolved questions, mainly regarding ambiguities in the interpolation spec. We can discuss them in the PR. Edit 3: While writing the PR comments, the more I wrote the more problems I found, and it is quickly spiralling out of control. Recursive string replacement is just not going to be nearly good enough, because fundamentally we cannot distinguish between a lexical token (e.g. |
I hit this today with something like: environment:
- DATABASE_USER=${DATABASE_USER:-postgres}
- DATABASE_URL=${DATABASE_URL:-postgresql://$DATABASE_URL:somepassword@host/database} No variation of the last |
podman-compose deviates from docker-compose in
To Reproduce
FILE: .env
FILE: docker-compose.yml
Commands
Expected behavior
All the variables should be substituted as you would expect. Note that
docker-compose config
just works as expected.Also no need to explicitly pass around variables with -e from when invoking docker-compose.
Actual behavior
Actual behaviour is that $B evaluates to literally foo$A, meaning it doesn't interpolate its value.
$C and $D results in errors, as podman-compose doesn't know about $HOME at all.
Output
Environment:
Linux 6.1.31-2
Additional context
Current tests in repo do not test equality of output between docker-compose and podman-compose. That would possibly make your life easier to keep feature parity.
The text was updated successfully, but these errors were encountered: