Closed ghost closed 8 years ago
Hi,
You don't need the dotenv
gem.
The Docker Compose file is loading in the .env
file (which should have all of your custom ENV variables) and it's passing them all to the Rails app when you run it.
There is 1 caveat, and that's this line in the Dockerfile
:
RUN bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:pass@127.0.0.1/dbname ACTION_CABLE_ALLOWED_REQUEST_ORIGINS=foo,bar SECRET_TOKEN=dummytoken assets:precompile
Environment variables aren't loaded when the Docker image gets built. If it's something that Rails thinks is mission critical and it happens to be nil
then you need to put a dummy value there to prevent Rails from complaining.
If you're reading in a custom ENV variable somewhere in your project and the asset pre-compile line explodes then just mock that ENV out in the above line.
Perhaps this could be better explained in the README file as a FAQ item? I sort of hint at this in the associated blog post but I don't think it's covered in enough detail.
ohh, okok, now I see.
I wanted to do rails secret
for the SECRET_TOKEN
and I realized that the envs weren't loading.
good to know!
You would need to start up everything with docker-compose up
and then run:
docker-compose exec --user "$(id -u):$(id -g)" website rails secret
--user
flag.What I think happened here was you have Rails installed on your workstation and you ran rails secret
from inside of your orats generated project and now Rails is like "yo, how the heck am I going to use these ENV variables?", because they weren't loaded in through Docker since you ran Rails without Docker.
I solved this installing the
dotenv
gem.I think is a good practice to put
dotenv
in the Gemfile, however, if your intention was to create something gem-agnostic to load environment variables (allowing the user to choose from Figaro or Dotenv), it would be great to add a section in the README indicating that.So far, so good. Thank you, again, for reducing the boilerplate (and a great documentation to understand the why's configuring the project) :beer:.