3 个不稳定版本
0.1.1 | 2023年11月20日 |
---|---|
0.1.0 | 2023年11月20日 |
0.0.1 | 2023年11月20日 |
#4 in #dockerfile
79KB
304 代码行
TPP (Tera 预处理器)
tpp
(Tera 预处理器) 是一个通用的 CLI (命令行界面) 工具,用于使用 Tera 模板引擎预处理文件。它从知名的预处理器如 cpp 和 gpp 中汲取灵感,tpp
以其用户友好的命令行界面和高效渲染各种应用程序的模板而脱颖而出。
了解更多关于 Tera 的信息
示例
从模板创建 Dockerfile
Dockerfile.in
FROM {{ base_image }}
LABEL maintainer="{{ maintainer }}"
RUN apt-get update && apt-get install -y \
{{ packages | join(' ') }}
COPY . /app
WORKDIR /app
ENV PORT {{ port }}
EXPOSE {{ port }}
CMD ["{{ entrypoint }}"]
context.json
{
"base_image": "python:3.8-slim",
"maintainer": "[email protected]",
"packages": [
"build-essential",
"libpq-dev"
],
"port": 8080,
"entrypoint": "python app.py"
}
命令
tpp Dockerfile.in -c context.json -o Dockerfile
Dockerfile
FROM python:3.8-slim
LABEL maintainer="[email protected]"
RUN apt-get update && apt-get install -y \
build-essential libpq-dev
COPY . /app
WORKDIR /app
ENV PORT 8080
EXPOSE 8080
CMD ["python app.py"]
用法
Usage: tpp [OPTIONS] <TEMPLATE_FILE>
Arguments:
<TEMPLATE_FILE> Path to the template file you wish to render
Options:
-c, --context-file <CONTEXT_FILE> Optional: Specify the path to context data in JSON, YAML, or TOML format
--stdin Optional: Enable passing context data via standard input. Useful for merging different context files or processing context data with tools like `jq`
-i, --include <INCLUDE> Optional: Define directories (and their subdirectories) to search for additional templates referenced in `<TEMPLATE_FILE>`. Necessary for templates that import or include other files. Note: any relative paths specified in the `import` or `include` statements within templates are resolved relative to the directories indicated by `--include`
--env Optional: Use current environment variables as context data. This can be merged with data from `--context-file` or `--stdin`. Merging occurs after, unless `--env-first` is set. Useful for dynamic template data population
-e, --env-key <ENV_KEY> Optional: Designate a specific key under which all environment variables will be nested in the context data. Requires `--env` to be set
--env-first Optional: Apply environment variable context before any other context. Allows another context to override the env context. Requires `--env` to be set
--fail-on-collision Optional: Command will terminate if there's a conflict between environment variables and other context data. Requires `--env` to be set
-o, --out <OUT> Optional: Specify an output file to write the rendered template. If omitted, the output is directed to standard output (stdout)
--escape Optional: Enable auto-escaping of rendered content, which is particularly useful for HTML
--debug Optional: Enable debug mode to print detailed debug information to standard output (stdout)
-h, --help Print help
-V, --version Print version
依赖
~13–24MB
~340K SLoC