lazycat-dynamic-deploy
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese懒猫微服动态部署与注入指南
Lazycat MicroServer Dynamic Deployment and Injection Guide
你是一个专业的懒猫微服应用架构师。当开发者需要向用户索要自定义配置(如密码、远程 IP 等),或者需要在不修改原应用代码的情况下,强行向应用的前端页面注入 JavaScript 脚本时,请遵循本指南。
As a professional Lazycat MicroServer application architect, follow this guide when developers need to request custom configurations (such as passwords, remote IPs, etc.) from users, or need to force inject JavaScript scripts into the application's front-end pages without modifying the original application code.
1. 动态部署参数与模板渲染 (v1.3.8+)
1. Dynamic Deployment Parameters and Template Rendering (v1.3.8+)
懒猫微服支持在安装应用前,弹出一个 UI 界面让用户填写参数,然后利用这些参数动态渲染 。
lzc-manifest.ymlLazycat MicroServer supports popping up a UI interface for users to fill in parameters before installing an application, then using these parameters to dynamically render .
lzc-manifest.yml步骤 A: 编写 lzc-deploy-params.yml
lzc-deploy-params.ymlStep A: Write lzc-deploy-params.yml
lzc-deploy-params.yml在项目根目录创建此文件,定义需要用户填写的字段。
yaml
params:
- id: target_ip
type: string
name: "目标服务器 IP"
description: "你要代理的内网服务器 IP"
- id: enable_debug
type: bool
name: "开启 Debug"
default_value: "false"
optional: true类型支持: , , ,
stringboolsecretlzc_uidCreate this file in the project root directory to define the fields that require user input.
yaml
params:
- id: target_ip
type: string
name: "目标服务器 IP"
description: "你要代理的内网服务器 IP"
- id: enable_debug
type: bool
name: "开启 Debug"
default_value: "false"
optional: trueSupported types: , , ,
stringboolsecretlzc_uid步骤 B: 在 lzc-manifest.yml
中使用模板渲染
lzc-manifest.ymlStep B: Use Template Rendering in lzc-manifest.yml
lzc-manifest.yml使用 Go 模板语法 () 读取参数。
{{ ... }}- 用户参数使用 (例如:
.U.参数ID)。如果 ID 包含{{ .U.target_ip }},需使用.(如index)。{{ index .U "my.param" }} - 系统参数使用 (例如:
.S,.S.BoxDomain)。.S.IsMultiInstance - 随机密码生成函数: (同一个微服,相同的 seed 永远生成相同的字符串)。
{{ stable_secret "admin_password" | substr 0 8 }}
示例:
yaml
services:
myapp:
image: xxx
environment:
- REMOTE_IP={{ .U.target_ip }}
- DB_PASS={{ stable_secret "db_root_pass" }}Use Go template syntax () to read parameters.
{{ ... }}- User parameters use (e.g.,
.U.parameterID). If the ID contains{{ .U.target_ip }}, use.(e.g.,index).{{ index .U "my.param" }} - System parameters use (e.g.,
.S,.S.BoxDomain)..S.IsMultiInstance - Random password generation function: (For the same microservice, the same seed will always generate the same string).
{{ stable_secret "admin_password" | substr 0 8 }}
Example:
yaml
services:
myapp:
image: xxx
environment:
- REMOTE_IP={{ .U.target_ip }}
- DB_PASS={{ stable_secret "db_root_pass" }}2. 网页脚本注入 (application.injects
) (v1.5.0+)
application.injects2. Web Page Script Injection (application.injects
) (v1.5.0+)
application.injects适用于在不修改第三方 Docker 镜像前端代码的情况下,向特定网页强行注入 JS 脚本(比如用来自动填充难以修改的默认密码)。
核心逻辑: 只有满足 (白名单)且不命中 (黑名单)的 HTML 页面才会被注入。
includeexclude示例:实现第三方系统的自动登录
yaml
application:
injects:
- id: auto-login
mode: exact # 支持 exact(精确) 或 prefix(前缀)
include:
- "/login" # 当访问 /login 时注入
- "/#signin" # 也能匹配 hash 路由
scripts:
# 使用懒猫内置的表单填充脚本
- src: builtin://simple-inject-password
params:
user: "admin"
password: "{{ stable_secret "app_admin_pass" }}"
autoSubmit: true自定义注入脚本:
如果你想注入自己写的脚本,可以将 JS 文件放在打包目录中,通过 引用。在脚本内部,可以通过 获取传入的 参数。
file:///lzcapp/pkg/content/myscript.js__LZC_INJECT_PARAMS__paramsSuitable for force-injecting JS scripts into specific web pages without modifying the front-end code of third-party Docker images (e.g., to automatically fill in default passwords that are difficult to modify).
Core Logic: Only HTML pages that match the (whitelist) and do not hit the (blacklist) will be injected.
includeexcludeExample: Implement Auto-login for Third-party Systems
yaml
application:
injects:
- id: auto-login
mode: exact # 支持 exact(精确) 或 prefix(前缀)
include:
- "/login" # 当访问 /login 时注入
- "/#signin" # 也能匹配 hash 路由
scripts:
# 使用懒猫内置的表单填充脚本
- src: builtin://simple-inject-password
params:
user: "admin"
password: "{{ stable_secret "app_admin_pass" }}"
autoSubmit: trueCustom Injection Scripts:
If you want to inject your own script, you can place the JS file in the packaging directory and reference it via . Inside the script, you can get the passed via .
file:///lzcapp/pkg/content/myscript.jsparams__LZC_INJECT_PARAMS__平台兼容性说明
Platform Compatibility Notes
如果需要查看详细的内置模板函数列表、系统参数列表()或了解脚本注入的 的详细参数配置(如修改选择器),请主动读取本技能包 目录下的相关 Markdown 文档。
SysParamsbuiltin://simple-inject-passwordreferences/For detailed lists of built-in template functions, system parameters (), or to learn about the detailed parameter configuration of the script injection's (such as modifying selectors), please proactively read the relevant Markdown documents in the directory of this skill package.
SysParamsbuiltin://simple-inject-passwordreferences/