Passing email API key to container without hardcoding in app.yml

Howdy! I have the discourse configuration app.yml tracked in a git repository (together with the rest of the server’s configuration).

Naturally, I would like to keep the DISCOURSE_SMTP_PASSWORD out of the git repo, so I want to pass it in separately. Is there a recommended way to do this?

I’ve tried:

Using docker-compose’s env_file: section, together with the env:, to try to pass in a separate file:

env_file:
  - path: /var/discourse/containers/creds.env

env:
  LANG: en_US.UTF-8
  # DISCOURSE_DEFAULT_LOCALE: en
  ...


====== creds.env ======
DISCOURSE_SMTP_PASSWORD="..."

but I haven’t been able to get docker to pick up the ENV var.

I tried passing it to ``–docker-args```,
sudo /var/discourse/launcher rebuild app --docker-args DISCOURSE_SMTP_PASSWORD=$DISCOURSE_SMTP_PASSWORD
But that borks immediately:
docker: invalid reference format: repository name must be lowercase.

Thank you for this wonderful software and I hope you’re all keeping safe :)))

2 Likes

Hey, welcome back!

I believe the right syntax would be something like:

./launcher rebuild app --docker-args "-e DISCOURSE_SMTP_PASSWORD=\"password\""

With --env-file, this should work as well:

./launcher rebuild app --docker-args "--env-file=/var/discourse/containers/creds.env"
2 Likes

That worked great!

(for posterity: I needed to tweak the quoting a bit as well, like so:

./launcher rebuild app --docker-args "-e DISCOURSE_SMTP_PASSWORD=$DISCOURSE_SMTP_PASSWORD"

I got **ERROR** - 535 Authentication failed otherwise - and in the last line of the rebuild console output you can see there’s an extra set of quotes in the command line. I think the env_file variable declaration probably should also not have quotes around it, unlike my original post.)

thanks muchly for the help and have a wonderful day!

2 Likes