I really like the ideas behind the Twelve Factors Manifesto. I am trying to apply them to a small microservice-style deployment for a Python/Django project. The Django project is packaged in a Docker container which is deployed via Docker Hub.
The one thing that I am trying to understand is how to deal with configuration files and environment variables. The common wisdom of 12 factor apps is that configuration should be stored as environment variables, and not in source control. I am thinking of implementing this using django-environ which checks the environment variables, and also a .env
file for use in dev.
How do I set these environment variables in production, then?
- In Docker, it is possible to declare environment variables as
ENV
in the Dockerfile (doc). So I can add this information there, but I check in the Dockerfile with the source code, so this would defeat the purpose. - I could create an additional
.env
file for production, and not check it into source control. I can copy this production.env
file while building the image using theCOPY
command. But this means the developer will have access to the DB credentials. - Set up a custom build trigger, so that when the code is updated in the source control, a build trigger is issued. When the image is being built, this building node adds this
.env
file, and deploys to the server.
I feel like the third option is the only one that makes sense. But even in that case, the config items are still stored in a file, and not really in environment variables.
Any ideas how to go about this?