Sign inSign up

apicore/dotenv-filler

By apicore

•Updated about 4 years ago

A simple environment-to-file script

Image
0

1.1K

apicore/dotenv-filler repository overview

⁠dotenv-filler

A simple environment-to-file script. Match-and-replace values of key-value pairs in a file directly from your environment. Can be used for example in CI pipelines to generate .env files from their example equivalents.

⁠What it does

The script goes through every key in a given key-value file. If a key has a value in the environment, the script replaces its value with the one from the environment. You can also provide a prefix to help keeping your variables separate.

⁠Requirements

⁠Usage

sh dotenv-filler.sh FILE [VAR_PREFIX]

Parameters:

  • FILE The key-value file to apply changes to
  • VAR_PREFIX - Look for the variables with this prefix in the environment. This value is sanitized: All &*+,./:;@|~- characters are replaced with underscores (_) and then all non-alphanumeric characters (except _) are dropped. Finally, the value is changed to all uppercase for a usual env varaible format. This helps when one wants to use strings from other sources (for example git branch names) as prefix.
⁠Examples

Let's take a file named .env with the following content:

FIRST_VARIABLE=
SECOND_VARIABLE=255
⁠Without using a prefix:

Running FIRST_VARIABLE=test sh dotenv-filler.sh .env will change the contents of the file to the following:

FIRST_VARIABLE=test
SECOND_VARIABLE=255
⁠Using a prefix:

Running PRE_SECOND_VARIABLE=hello sh dotenv-filler.sh .env PRE will change the contents of the file to the following:

FIRST_VARIABLE=
SECOND_VARIABLE=hello

Tag summary

Content type

Image

Digest

Size

2.7 MB

Last updated

about 4 years ago

docker pull apicore/dotenv-filler