vifreefly / procsd

Manage your application processes in production hassle-free like Heroku CLI with Procfile and Systemd

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to read environment variables from outside the yml file?

n4cr opened this issue · comments

Hi and thanks for this library. I'm very interested but I have a need which I didn't see in the documentation.
I prefer not to commit my environment variables to the git repo and read them from a .env on the production machine. Would it be possible to read the environment from a file?

Hi @n4cr !

Procsd ENV variables (inside procsd.yml file) should store only production-mode specific variables required for your application, like for example HOST, PORT, etc.

All other sensitive data should go inside .env file and it could be read by your application itself. For example for Ruby there is https://github.com/bkeepers/dotenv , for Python https://github.com/theskumar/python-dotenv and so on.

Once again, inside procsd.yml you should store variables which are only production mode specific. Everything else put inside .env file and read it from your application.

But, if you still want it, you can :)

Your .env file should be located in the same folder with procsd.yml. To use env variables from .env file inside procsd.yml use following syntax:

# .env

SOME_API_KEY="234rsfsdfw423rfes"
# procsd.yml

app: sample_app
environment:
  API_KEY: <%= ENV['SOME_API_KEY'] %>

Thanks @vifreefly for the response. The reason I asked for this was because foreman exports the .env into the Service file so then it is accessible through reading them from the environment variables. But I guess your point to read them directly from .env file stands. As well as your solution.
Great work. I'm investigating procsd and probably start using it.