All Projects → wemake-services → dump-env

wemake-services / dump-env

Licence: MIT license
A utility tool to create .env files

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to dump-env

travis-ci-latex-pdf
Overview of different methods to build LaTeX with GitHub Actions or Travis-CI (idea by @jackolney but completely rewritten by @PHPirates and contributors).
Stars: ✭ 113 (+39.51%)
Mutual labels:  travis-ci, continuous-integration, gitlab-ci
drupal9ci
One-line installers for implementing Continuous Integration in Drupal 9
Stars: ✭ 137 (+69.14%)
Mutual labels:  travis-ci, continuous-integration, gitlab-ci
arduino-ci-script
Bash script for continuous integration of Arduino projects
Stars: ✭ 25 (-69.14%)
Mutual labels:  travis-ci, continuous-integration
continuous-integration-with-python
How to test your python code. How to automatically run your tests for your Python code. How to get reports of the tests coverage
Stars: ✭ 25 (-69.14%)
Mutual labels:  travis-ci, continuous-integration
docker-coala-base
coala base docker image
Stars: ✭ 20 (-75.31%)
Mutual labels:  travis-ci, gitlab-ci
cikit
Continuous Integration Kit (CIKit)
Stars: ✭ 21 (-74.07%)
Mutual labels:  continuous-integration, gitlab-ci
scikit-ci
Simpler and centralized CI configuration for Python extensions.
Stars: ✭ 15 (-81.48%)
Mutual labels:  travis-ci, continuous-integration
travis-ci-tutorial-java
Just to learn how to use travis-ci in a java project!
Stars: ✭ 38 (-53.09%)
Mutual labels:  travis-ci, continuous-integration
nightly-docker-rebuild
Use nightli.es 🌔 to rebuild N docker 🐋 images 📦 on hub.docker.com
Stars: ✭ 13 (-83.95%)
Mutual labels:  travis-ci, continuous-integration
docker-fastpath
Only Build Your Docker Images Once
Stars: ✭ 52 (-35.8%)
Mutual labels:  travis-ci, continuous-integration
developer-ci-benefits
Talk docs—includes CI (Continuous Integration) benefits, description, and setup tips 💡💪
Stars: ✭ 29 (-64.2%)
Mutual labels:  travis-ci, continuous-integration
docker-ci-deploy
Python script to help push Docker images to a registry using CI services
Stars: ✭ 20 (-75.31%)
Mutual labels:  travis-ci, continuous-integration
Mkdkr
Make + Docker + Shell = CI Pipeline
Stars: ✭ 225 (+177.78%)
Mutual labels:  travis-ci, gitlab-ci
HaxeCI
An example of using CI for Haxe projects.
Stars: ✭ 45 (-44.44%)
Mutual labels:  travis-ci, continuous-integration
Greenkeeper Lockfile
🔒 Your lockfile, up to date, all the time
Stars: ✭ 181 (+123.46%)
Mutual labels:  travis-ci, continuous-integration
Nevergreen
🐤 A build monitor with attitude
Stars: ✭ 170 (+109.88%)
Mutual labels:  travis-ci, continuous-integration
koshry
Run on CI, Apply Rules on the Build and Get the Result back to the Pull Request.
Stars: ✭ 59 (-27.16%)
Mutual labels:  travis-ci, continuous-integration
Tic
Tasks Integrating Continuously: CI-Agnostic Workflow Definitions
Stars: ✭ 135 (+66.67%)
Mutual labels:  travis-ci, continuous-integration
Ci Detector
Detect continuous integration environment and get information of current build
Stars: ✭ 138 (+70.37%)
Mutual labels:  travis-ci, continuous-integration
plugin.video.sendtokodi
📺 plays various stream sites on kodi using youtube-dl
Stars: ✭ 86 (+6.17%)
Mutual labels:  travis-ci, continuous-integration

A utility tool to create .env files

wemake.services test codecov Python Version Docs wemake-python-styleguide

dump-env takes an .env.template file and some optional environmental variables to create a new .env file from these two sources. No external dependencies are used.

Why?

Why do we need such a tool? Well, this tool is very helpful when your CI is building docker (or other) images. Previously we had some complex logic of encrypting and decrypting files, importing secret keys and so on. Now we can just create secret variables for our CI, add some prefix to it, and use dump-env to make our life easier.

Installation

$ pip install dump-env

Quickstart

This quick demo will demonstrate the main and the only purpose of dump-env:

$ dump-env --template=.env.template --prefix='SECRET_ENV_' > .env

This command will:

  1. take .env.template
  2. parse its keys and values
  3. read all the variables from the environment starting with SECRET_ENV_
  4. remove this prefix
  5. mix it all together, environment vars may override ones from the template
  6. sort keys in alphabetic order
  7. dump all the keys and values into the .env file

Advanced Usage

Multiple prefixes

$ dump-env -t .env.template -p 'SECRET_ENV_' -p 'ANOTHER_SECRET_ENV_' > .env

This command will do pretty much the same thing as with one prefix. But, it will replace multiple prefixes. Further prefixes always replace previous ones if they are the same. For example:

$ export SECRET_TOKEN='very secret string'
$ export SECRET_ANSWER='13'
$ export ANOTHER_SECRET_ENV_ANSWER='42'
$ export ANOTHER_SECRET_ENV_VALUE='0'
$ dump-env -p SECRET_ -p ANOTHER_SECRET_ENV_
ANSWER=42
TOKEN=very secret string
VALUE=0

Strict env variables

In case you want to be sure that YOUR_VAR exists in your environment when dumping, you can use --strict flag:

$ dump-env --strict YOUR_VAR -p YOUR_
Missing env vars: YOUR_VAR

Oups! We forgot to create it! Now this will work:

$ export YOUR_VAR='abc'
$ dump-env --strict YOUR_VAR -p YOUR_
VAR=abc

Any number of --strict flags can be provided. No more forgotten template overrides or missing env vars!

Source templates

You can use an env template as a source template by using the -s or --source argument. This will restrict any non-prefixed variables found in the environment to only those already defined in your template.

$ cat template.env
ANSWER=13
TOKEN=very secret string
VALUE=0
$ export ANSWER='42'
$ dump-env --source=template.env
ANSWER=42
TOKEN=very secret string
VALUE=0

You can still also use prefixes to add extra variables from the environment

$ export EXTRA_VAR='foo'
$ dump-env -s template.env -p EXTRA_
ANSWER=13
TOKEN=very secret string
VALUE=0
VAR=foo

Strict Source

Using the --strict-source flag has the same effect as defining a --strict flag for every variable defined in the source template.

$ export ANSWER='42'
$ dump-env -s template.env --strict-source
Missing env vars: TOKEN, VALUE

Creating secret variables in some CIs

Real-world usages

Projects that use this tool in production:

Related

You might also be interested in:

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].