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.yml
Lazycat 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

Step A: Write
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
类型支持:
string
,
bool
,
secret
,
lzc_uid
Create 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: true
Supported types:
string
,
bool
,
secret
,
lzc_uid

步骤 B: 在
lzc-manifest.yml
中使用模板渲染

Step B: Use Template Rendering in
lzc-manifest.yml

使用 Go 模板语法 (
{{ ... }}
) 读取参数。
  • 用户参数使用
    .U.参数ID
    (例如:
    {{ .U.target_ip }}
    )。如果 ID 包含
    .
    ,需使用
    index
    (如
    {{ index .U "my.param" }}
    )。
  • 系统参数使用
    .S
    (例如:
    .S.BoxDomain
    ,
    .S.IsMultiInstance
    )。
  • 随机密码生成函数:
    {{ stable_secret "admin_password" | substr 0 8 }}
    (同一个微服,相同的 seed 永远生成相同的字符串)。
示例:
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
    .U.parameterID
    (e.g.,
    {{ .U.target_ip }}
    ). If the ID contains
    .
    , use
    index
    (e.g.,
    {{ index .U "my.param" }}
    ).
  • System parameters use
    .S
    (e.g.,
    .S.BoxDomain
    ,
    .S.IsMultiInstance
    ).
  • Random password generation function:
    {{ stable_secret "admin_password" | substr 0 8 }}
    (For the same microservice, the same seed will always generate the same string).
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+)

2. Web Page Script Injection (
application.injects
) (v1.5.0+)

适用于在不修改第三方 Docker 镜像前端代码的情况下,向特定网页强行注入 JS 脚本(比如用来自动填充难以修改的默认密码)。
核心逻辑: 只有满足
include
(白名单)且不命中
exclude
(黑名单)的 HTML 页面才会被注入。
示例:实现第三方系统的自动登录
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__
获取传入的
params
参数。
Suitable 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
include
(whitelist) and do not hit the
exclude
(blacklist) will be injected.
Example: 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: true
Custom Injection Scripts: If you want to inject your own script, you can place the JS file in the packaging directory and reference it via
file:///lzcapp/pkg/content/myscript.js
. Inside the script, you can get the passed
params
via
__LZC_INJECT_PARAMS__
.

平台兼容性说明

Platform Compatibility Notes

如果需要查看详细的内置模板函数列表、系统参数列表(
SysParams
)或了解脚本注入的
builtin://simple-inject-password
的详细参数配置(如修改选择器),请主动读取本技能包
references/
目录下的相关 Markdown 文档。
For detailed lists of built-in template functions, system parameters (
SysParams
), or to learn about the detailed parameter configuration of the script injection's
builtin://simple-inject-password
(such as modifying selectors), please proactively read the relevant Markdown documents in the
references/
directory of this skill package.