• Stars
    star
    328
  • Rank 128,352 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created about 10 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Docker-friendly trivial templating for configuration files using environment keys

Envplate

Release Build Status Documentation Go Report Card

Trivial templating for configuration files using environment keys. References to such keys are declared in arbitrary config files either as:

  1. ${key} or
  • ${key:-default value}

Envplate (ep) parses arbitrary configuration files (using glob patterns) and replaces all references with values from the environment or with default values (if given). These values replace the keys inline (= the files will be changed).

Failure to resolve the supplied glob pattern(s) to at least one file results in an error.

Optionally, ep can:

  • backup (-b flag): create backups of the files it changes, appending a .bak extension to backup copies
  • dry-run (-d flag): output to stdout instead of replacing values inline
  • strict (-s flag): refuse to fallback to default values
  • verbose (-v flag): be verbose about it's operations

ep can also exec() another command by passing

  • -- after all arguments to ep
  • the path to the binary and it's arguments

Example: /usr/local/bin/ep -v *.conf -- /usr/sbin/nginx -c /etc/nginx.conf

This can be used to use ep to parse configs and execute the container process using Dockers CMD

Escaping

In case the file you want to modify already uses the pattern envplate is searching for ( e.g. for reading environment variables ) you can escape the sequence by adding a leading backslash \. It's also possible to escape a leading backslash by adding an additional backslash. Basically a sequence with an even number of leading backslashes will be parsed, is the number of leading backslashes odd the sequence will be escaped.

See https://github.com/kreuzwerker/envplate#full-example

Why?

For apps running Docker which rely (fully or partially) on configuration files instead of being purely configured through environment variables.

You can directly download envplate binaries into your Dockerfile using Github releases like this:

RUN wget -q https://github.com/kreuzwerker/envplate/releases/download/v1.0.2/envplate_1.0.2_$(uname -s)_$(uname -m).tar.gz -O - | tar xz && mv envplate /usr/local/bin/ep && chmod +x /usr/local/bin/ep

...

CMD [ "/usr/local/bin/ep", "-v", "/etc/nginx/nginx.conf", "--", "/usr/sbin/nginx", "-c", "/etc/nginx/nginx.conf" ]

Full example

$ cat /etc/foo.conf
Database=${FOO_DATABASE}
DatabaseSlave=${BAR_DATABASE:-db2.example.com}
Mode=fancy
Escaped1=\${FOO_DATABASE}
NotEscaped1=\\${FOO_DATABASE}
Escaped2=\\\${BAR_DATABASE:-db2.example.com}
NotEscaped2=\\\\${BAR_DATABASE:-db2.example.com}

$ export FOO_DATABASE=db.example.com

$ ep /etc/f*.conf

$ cat /etc/foo.conf
Database=db.example.com
DatabaseSlave=db2.example.com
Mode=fancy
Escaped1=${FOO_DATABASE}
NotEscaped1=\db.example.com
Escaped2=\${BAR_DATABASE:-db2.example.com}
NotEscaped2=\\db2.example.com

More Repositories

1

terraform-provider-docker

Terraform Docker provider
Go
608
star
2

m1-terraform-provider-helper

CLI to support with downloading and compiling terraform providers for Mac with M1 chip
Go
486
star
3

awsu

Enhanced account switching for AWS, supports Yubikey as MFA source
Go
175
star
4

envsec

Encrypted environment variables via AWS KMS
Go
29
star
5

Call-AWS-API-With-Bash

Shell
14
star
6

kreuzlaker

Python
11
star
7

kafka-consumer-testing

demo application for testing a Kafka consumer with Avro message schema with Testcontainers using Kafka with embedded Zookeeper and no Schema Registry container
Java
9
star
8

DKT.huginn_readability_agent

Ruby
8
star
9

aws-game-day-2022-squirrel-force

Squirrel Force to the Win
6
star
10

awssd

Utility that creates Route53 A records for EC2 instances following a tag convention
Go
6
star
11

tacks

Executable CloudFormation stacks
Go
6
star
12

yess

yess enables splitting secrets into shares using a Yubikey-based threshold schema
Go
5
star
13

homebrew-taps

Brew support for various kreuzwerker tools
Ruby
5
star
14

ecr-proxy

nginx configuration for proxying requests against an AWS EC2 Container Registry
Nginx
5
star
15

blog-bidirectional-contract-testing-consumer

Java
5
star
16

blog-bidirectional-contract-testing-provider

Java
4
star
17

parallel-docker-uats

Ruby
3
star
18

DKT.huginn_dkt_curation_agents

Ruby
3
star
19

gva

Varnish CLI interface in golang
Go
3
star
20

blog-testing-with-cdk

Examples from blog post https://kreuzwerker.de/post/infrastructure-tests-with-cdk
TypeScript
2
star
21

DKT.huginn_website_metadata_agent

HTML
2
star
22

aodb

Atlassian OnDemand backup
Ruby
2
star
23

awsips

Client utility to query IP addresses used by Amazon Web Services
Go
2
star
24

awhois

Determine if IP addresses belong to AWS
Go
1
star
25

cdk-nag-example

How to
TypeScript
1
star
26

arebot

Go
1
star
27

vmimport-terraform

Terraform provisioning for AWS VM import
HCL
1
star
28

terraform-aws-es

Terraform configurations to launch an Amazon Elasticsearch cluster in a VPC
HCL
1
star
29

safed

😍🔒 - readme driven development workshop
1
star
30

did-you-hear-publisher

Slack bot backend for daily news publication
TypeScript
1
star