manifest.yml 渲染
manifest.yml 的 render 只负责部署阶段才能确定的值,不再承载 dev/release 结构裁剪。
1. 渲染流程
- 开发者在项目根目录下创建 lzc-deploy-params.yml 并随 LPK 一起打包。
- 安装或重新配置实例时,系统收集部署参数。
- 系统使用
text/template渲染/lzcapp/pkg/manifest.yml。 - 渲染结果写入
/lzcapp/run/manifest.yml并作为最终运行配置。
2. 模板参数
当前只提供两类稳定参数:
.UserParams(.U)- 来源于
lzc-deploy-params.yml。
- 来源于
.SysParams(.S)- 系统相关参数,例如:
.BoxName.BoxDomain.OSVersion.AppDomain.IsMultiInstance.DeployUID.DeployID
不再提供包内 envs 注入的 .E / .PkgEnvs。
如果你要控制 dev/release 结构差异,请使用 lzc-build.dev.yml 与 manifest build 预处理,而不是部署阶段 render。
3. 内置模板函数
- sprig 提供的函数(不含
env/expandenv)。 stable_secrt "seed"- 用于生成稳定密码。
- 同一个 seed 在同一台微服、同一个应用内保持稳定。
- 不同应用或不同微服的结果不同。
4. 调试方式
可以临时把全部 render 上下文打印出来:
yml
xx-debug: {{ . }}也可以直接查看最终渲染文件:
yml
application:
route:
- /m=file:///lzcapp/run/manifest.yml或在容器内执行:
bash
cat /lzcapp/run/manifest.yml5. 示例
5.1 更安全的内部密码
yml
services:
mysql:
environment:
- MYSQL_ROOT_PASSWORD={{ stable_secrt "root_password" }}
- MYSQL_PASSWORD={{ stable_secrt "admin_password" | substr 0 6 }}
redmine:
environment:
- DB_PASSWORD={{ stable_secrt "root_password" }}5.2 启动参数由用户配置
yml
# lzc-deploy-params.yml
params:
- id: target
type: string
name: "target"
description: "the target IP you want forward"
- id: listen.port
type: string
name: "listen port"
description: "the forwarder listen port, can't be 80, 81"
default_value: "33"
optional: trueyml
# lzc-manifest.yml
application:
subdomain: netmap
upstreams:
- location: /
backend_launch_command: /lzcapp/pkg/content/netmap -target={{ .U.target }} -port={{ index .U "listen.port" }}6. build 与 deploy 的边界
推荐按下面的原则理解:
- build 阶段决定:包里有什么。
- deploy 阶段决定:这些值在目标微服上取什么值。
- request inject 阶段决定:当前请求如何路由。
也就是说:
- dev/release 结构差异:放到
lzc-build.yml/lzc-build.dev.yml与#@build。 - 用户部署输入:放到
lzc-deploy-params.yml。 - 请求级动态行为:放到 inject script。