-
-
Notifications
You must be signed in to change notification settings - Fork 168
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
Load env variables from .warden.env #131
Comments
Maybe just moving it to |
This is a terrific idea, but will pose a few challenges to implement. Docker Compose only introduced the I'm going to keep this in here as an enhancement request for now, but it might not get much attention for a bit. Here is what I think makes sense though, from a fallback perspective:
To implement this, there would need to be a bash function to parse the dotenv files, and it would need to properly account for special characters and/or whitespace in values (this will take some trickery since dotenv files do not use quotes and do not require escapes like bash does; different semantics) — There are LOTS of "solutions" on the web for this, but most are flawed or way too basic. As an interim solution, what I've seen done on a Laravel project my colleagues have going is this: a) Commit a b) Have devs copy this file to This obviously has the downside of leaving open potential for basic environment details or Laravel settings like cache drivers or PHP Version to easily become different between local setups, but would prevent the accidental committing of sensitive info to the repo. |
Maybe a way around the multiple files issue would be to create a "compiled" version of the env (echo .env > .warden/.env-compiled; echo .warden.env >> .warden/.env-compiled) and load that with the flag. Of course the issue of the flag being new cannot be worked around, maybe a check can be added for the version and add the flag etc. if the version is high enough |
Perhaps as a fallback we could do something along the lines of:
It is a bit of a hack, admittedly, but it should do the trick if someone is running docker-compose that doesn't support Running export in a sub-shell will also mean that user's shell won't need to interact with those environment variables. Let me know if you'd like me to try something out and submit a PR. |
It looks like it should work. (Edit, one small fix. Remove comments since they do not work with export:
Which ends up with a file like:
If two of the same variables exist in the env files, the last one takes precedence. |
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
The way that I did this, is by setting up another env file that holds the private information. Then inside version: "3.5"
services:
php-fpm:
environment:
- DATABASE_HOST=${DATABASE_HOST}
- DATABASE_NAME=${DATABASE_NAME}
- DATABASE_USER=${DATABASE_USER}
- DATABASE_PASSWORD=${DATABASE_PASSWORD}
- REDIS_SESSION_HOST=${REDIS_SESSION_HOST}
- REDIS_SESSION_PORT=${REDIS_SESSION_PORT}
- REDIS_SESSION_DB=${REDIS_SESSION_DB}
- REDIS_CACHE_HOST=${REDIS_CACHE_HOST}
- REDIS_CACHE_PORT=${REDIS_CACHE_PORT}
- REDIS_CACHE_DB=${REDIS_CACHE_DB}
- REDIS_FPC_HOST=${REDIS_FPC_HOST}
- REDIS_FPC_PORT=${REDIS_FPC_PORT}
- REDIS_FPC_DB=${REDIS_FPC_DB}
- ELASTICSEARCH_HOST=${ELASTICSEARCH_HOST}
- ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT}
- BLACKFIRE_CLIENT_ID=${BLACKFIRE_CLIENT_ID}
- BLACKFIRE_CLIENT_TOKEN=${BLACKFIRE_CLIENT_TOKEN}
- BLACKFIRE_SERVER_ID=${BLACKFIRE_SERVER_ID}
- BLACKFIRE_SERVER_TOKEN=${BLACKFIRE_SERVER_TOKEN}
volumes:
- ./.warden/php/zz-config.ini:/etc/php.d/zz-config.ini
php-debug:
environment:
- DATABASE_HOST=${DATABASE_HOST}
- DATABASE_NAME=${DATABASE_NAME}
- DATABASE_USER=${DATABASE_USER}
- DATABASE_PASSWORD=${DATABASE_PASSWORD}
- REDIS_SESSION_HOST=${REDIS_SESSION_HOST}
- REDIS_SESSION_PORT=${REDIS_SESSION_PORT}
- REDIS_SESSION_DB=${REDIS_SESSION_DB}
- REDIS_CACHE_HOST=${REDIS_CACHE_HOST}
- REDIS_CACHE_PORT=${REDIS_CACHE_PORT}
- REDIS_CACHE_DB=${REDIS_CACHE_DB}
- REDIS_FPC_HOST=${REDIS_FPC_HOST}
- REDIS_FPC_PORT=${REDIS_FPC_PORT}
- REDIS_FPC_DB=${REDIS_FPC_DB}
- ELASTICSEARCH_HOST=${ELASTICSEARCH_HOST}
- ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT}
- BLACKFIRE_CLIENT_ID=${BLACKFIRE_CLIENT_ID}
- BLACKFIRE_CLIENT_TOKEN=${BLACKFIRE_CLIENT_TOKEN}
- BLACKFIRE_SERVER_ID=${BLACKFIRE_SERVER_ID}
- BLACKFIRE_SERVER_TOKEN=${BLACKFIRE_SERVER_TOKEN}
volumes:
- ./.warden/php/zz-config.ini:/etc/php.d/zz-config.ini These variables, and their values will be available inside the docker containers The reason I don't use an environment file, is that that file is not checked into source control, and won't be available in my CI/CD pipelines for example Docker breaks, if you reference an env file that does not exist |
Hi,
Is it possible to load the warden variables from a file like .warden.env instead of .env
Or load it from both files?
This because for Laravel the .env file usually contains system-specific or sensitive information. Which you do not want stored in git.
If it does not get committed, all of the container versions will not stay synced per computer.
I would really like to be able to have a .warden.env like file to commit and keep the containers between computers up-to-date
The text was updated successfully, but these errors were encountered: