Environment variables for app.yml?


(Zach Alexander) #1

I wish I could specify values in app.yml (or data.yml and web_only.yml, which I’m switching to) with something similar to environment variables. For two reasons:

  1. I keep app.yml in version control, and passwords/API keys should be kept out of version control.
  2. I have a staging server, and I’d like to use the same app.yml repo for both. (The bigger issue for me)

In other words, something like the following pseudocode:

// app.yml
DISCOURSE_SMTP_ADDRESS = ENV['DISCOURSE_SMTP_ADDRESS']

ENV['DISCOURSE_SMTP_ADDRESS'] could be set to smtp.mailgun.org on my production server, and to mailtrap.io on staging. The launcher on each server would then evaluate app.yml and set up each container appropriately.

Is there a way to do this?


(Sam Saffron) #2

hmmm, am I missing something, this sets env vars

env: 
   WHATEVER: 1 

(Zach Alexander) #3

Yes. I’m talking about something one step more meta than this.

  1. Host has (meta) environment variables (e.g. on the staging server, SMTP = mailtrap.io, on prod, SMTP = mailgun.org)
  2. app.yml has the same contents on both
  3. app.yml is evaluated differently on each because of the different (meta) environment variables per #1
  4. Containers have different (ordinary) env vars set due to #3

Currently, I have lines like these in my app.yml:

  # DISCOURSE_SMTP_ADDRESS: mailtrap.io # staging
  # DISCOURSE_SMTP_ADDRESS: smtp.mailgun.org # production

and then uncomment them as appropriate, when I would rather do this:

  DISCOURSE_SMTP_ADDRESS: SOMETHING['DISCOURSE_SMTP_ADDRESS']

I’m partly asking because I feel like there is a straightforward linuxy way to do this. But maybe this is overkill and I should just manage the differences manually.


(Sam Saffron) #4

Ahh yeah, I was thinking about a way of passing in ENV, all the way through to pups … it would require changes to ./launcher though.


(Benjamin lupton) #5

This would be nice to have as DISCOURSE_SMTP_PASSWORD is the thing that prevents me from having the configuration file in a public git repo. If it could become and env var, then I can set it on the server, and have the repos public.