I will discuss an approach for managing environment variable files. The characteristics of this approach are:
In addition, I will explain how to use these files in the dev, deploy and prod environments.
I will mention the handling of secrets but I will not focus too much on security. I'm not an expert on this topic, and it would distract from the main goals of this article.
Enter the following commands to run a small example that uses compile-env
.
git clone git@github.com:mnieber/blog-sample-apps.git
cd blog-sample-apps/compile-env-sample
# Before proceeding, create a Python virtualenv and activate it
pip install -r requirements.txt
make compile-env
I will first discuss three different environments in which environment variables can be used: dev, prod and deploy. This explanation is not strictly necessary to understand the approach, but I think it adds an interesting context. Then, I will explain how the compile-env tool can be used to generate .env files for these environments from a single source of truth.