Adding dotenv-rails to load ENV in rake tasks


(Dorian) #1

From: Add dotenv-rails gem to have .env loaded in rake tasks by Dorian · Pull Request #5480 · discourse/discourse · GitHub

Otherwise I couldn’t get the GlobalSetting.developer_emails to have the value from .env loaded when doing a rake admin:create.

If there is some sort of require 'foreman/dotenv' that exists, I think it could be placed in Rakefile to have the same result.


Basically the ENV doesn’t contain the variables and values from .env when running rake tasks, I noticed that because rake admin:create gave me a different password length requirement when creating an admin (e.g. 10 vs 15 characters).

I’m pretty sure there are other bugs related to having .env not loaded in rake tasks.


(Matt Palmer) #2

You’re not really doing much to “sell” this change, given that @Sam has expressed doubts about its value in the PR. Personally, I’ve used dotenv in the past, and been decidedly underwhelmed at how it does things.

As far as I’m aware, the .env file is not the “project-standard” way to configure environment variables (the sample and .gitignore files were added as part of “Heroku integration” some years ago and haven’t been touched since). If you’re running the official Docker images, whenever you enter the container the environment is already configured, so there shouldn’t be any problem.

There’s no require 'foreman/dotenv' because foreman isn’t about running arbitrary commands, it’s about maintaining services, and the exporter is supposed to handle the environment configuration in whatever manner is appropriate for the export target.


(Sam Saffron) #3

Why do you need to be a developer in dev? that is assumed

Mini profiler always shows up

Logs are always accessible