kreuzwerker/envplate
关于
使用环境变量键为配置文件提供简单易用且兼容 Docker 的模板化功能
系统与基础设施实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Envplate
Trivial templating for configuration files using environment keys. References to such keys are declared in arbitrary config files either as:
${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 (
-bflag): create backups of the files it changes, appending a.bakextension to backup copies - dry-run (
-dflag): output to stdout instead of replacing values inline - strict (
-sflag): refuse to fallback to default values - verbose (
-vflag): be verbose about it's operations - charset (
-cflag): specify a custom charset to replace variables. Example:/usr/local/bin/ep -c iso8859-1 *.conf
ep can also exec() another command by passing
--after all arguments toep- 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
Sample docker file
FROM nginx:latest
MAINTAINER Albert van t Hart <[email protected]>
ADD https://github.com/kreuzwerker/envplate/releases/download/v0.0.7/ep-linux /bin/ep
RUN chmod +x /bin/ep
EXPOSE 80 443
CMD [ "/bin/ep", "-v", "/etc/nginx/*.conf", "--", "/usr/sbin/nginx", "-g", "daemon off;" ]
探索相关项目
加载中…