node-docker-good-defaults
node-docker-good-defaults copied to clipboard
Question: Where to put app config files?
Hi,
usually you have a config/ folder where a basic default.js file is in, which exports an object of configuration values. e.g.:
module.exports = {
session: {
key1: "abcde"
},
mailserver: {
relayHost: "127.0.0.1"
}
// ... a lot more values
}
And then for each env you create a specific copy of that. e.g.: config/production.js. Which is gitignored.
What is your best practice for handling (complex & nested) config values, which are different for each environment? Of course you don't want to use 'docker secret' for that right?
Thank you
Using config files is fine, and here are some thoughts:
- If you're using Swarm or Kubernetes then they support config files, so where you previously would store
prod.json a real server, in this case you would store them on the orchestrator and they would be mountable at runtime for the container. If you wanted to go full automation, you could store them in a git repo (as long as they don't have secrets) and have some CI/CD automation update them in the orchestrator when they change. - If you'll have secrets in that file, then yes the full file should be a secret so the file is never written to disk unencrypted. You could also do something fancy in Swarm (but not Kubernetes) where you use the file in a Swarm config with Go templating to pull in secrets at runtime to the config.
- I'm guessing you'll either use an envvar to indicate the file name of the environment (which I prefer), or a standard filename that the bind-mount gets renamed to at runtime. Either way, the info on how to control the environment file used should be detailed in the Dockerfile (and a default set in a ENV).