Deploy OpenClaw on an Azure VM with an AI Foundry backend and keep your runtime helpers versioned in the same repo.
[
](
https://portal.azure.com/#create/Microsoft.Template/uri/
https%3A%2F%2Fraw.githubusercontent.com%2FHaoHoo%2Fazure-openclaw%2Fmain%2Finfra%2Fmain.json
?repository=https%3A%2F%2Fgithub.com%2FHaoHoo%2Fazure-openclaw&path=infra&branch=main
)
- Infrastructure-first – Two Bicep modules wire up networking, a Linux VM,
Azure OpenAI, and AI Foundry.
infra/main.bicepexposes the knobs (modelName,openclawPort,dynaIP,scriptsRepoUrl, etc.) and forwards them into the resource module, whileinfra/resources.bicepinjects the cloud-init bootstrap and the Custom Script Extension payload. - Setup script workflow – The Custom Script Extension runs
scripts/set-openclaw.sh, which clones this repository, copies the completescripts/directory into the administrator home, records the environment metadata (including whether dynamic IP is enabled), installs OpenClaw, mergesopenclaw.json, and wires cron jobs forupdate-apikey.shandupdate-ddns-a.sh. - Dynamic DNS ready – When dynamic public IP is enabled,
set-openclaw.shrunsset-dync-dns.sh; the helper prompts you to pick a provider (currently Aliyun), saves your credentials/domain/record info under thealiyunsection ofscripts/update-dns/ddns.json, and rewritesupdate-ddns-a.shinto an Aliyun-specific updater that re-reads that JSON on every run (including the latestrecordId/currentIp) before calling the Aliyun CLI, so removing the provider field is now safe and future providers can share the same driver pattern. - Secure metadata refresh –
update-apikey.shsources the generated.azure.env, hits Azure to refresh the OpenAI key, writes the latest metadata toresource.json, and rewrites~/.openclaw/openclaw.jsonso OpenClaw always uses the newest endpoint/key. - Reusable helpers – Because the scripts directory is replaced wholesale via git clone, you can add new helpers (or new DDNS providers) and publish them in this repo;
set-openclaw.shwill pull them down automatically on every deployment.
- 一键部署 –
azd up或az deployment group create会先创建资源组、VM、AI Foundry、OpenAI 账号和模型部署, 再通过 Custom Script 自动运行scripts/set-openclaw.sh。 - azd 自动部署标准布局 – 仓库根目录保留
azure.yaml(引用infra/main.bicep)、infra/、scripts/以及 helper, azd/快速部署按钮可以自动检测模板,并从scripts/set-openclaw.sh启动安装逻辑。 - 脚本如何加载 –
set-openclaw.sh会 clone 指定的scriptsRepoUrl/scriptsRepoRef,把全部scripts/复制到/home/<admin>/scripts、赋予执行权限,并向.azure.env、resource.json、openclaw.json写入最新的环境参数;同时如果动态 公网 IP 启用时会调用set-dync-dns.sh。该脚本也会注册 cron 任务让update-apikey.sh和update-ddns-a.sh在每次重启后执行。 - 动态域名更新 – 运行
set-dync-dns.sh后选择 Aliyun DNS, 脚本会安装 Aliyun CLI、让你输入 Access Key ID/Secret、域名、子域名后 获取 RecordId 并把它们以及currentIp/lastConfigured/lastUpdated写在scripts/update-dns/ddns.json的aliyun区块内,之后update-ddns-a.sh会被重写为每次读取该区块并用最新值调用 Aliyun CLI (如果ddns.json缺失会提示先重跑set-dns-ali.sh)。后续如果新增 其他 DDNS 服务,只需对应服务重写update-ddns-a.sh接口即可。 - 安全更新流水线 –
update-apikey.sh从.azure.env中读取凭据后 调用az cognitiveservices account keys list、更新resource.json元数据、以及重写 OpenClaw 配置,从而避免将 API Key 写入持久存储 任何其它位置。 - 目录结构说明 –
azure.yaml:定义 AZD 服务和运行信息。infra/:Bicep 模板用于资源部署。scripts/:启动后被复制到/home/<admin>/scripts,包含set-openclaw.sh、set-dync-dns.sh、set-dns-ali.sh、update-ddns-a.sh、update-apikey.sh等 helper。
请在部署前确保 vmAdminPassword 等必填参数已经设置。如果需要,通过
scripts/set-dync-dns.sh 填写阿里云 DNS 信息以启用动态公网 IP 更新。
(@20260322)调整openclaw.json的注入,修复不必要的数据引发的报错,提供远程连接等需要的字 (done@20260325)
(@20260322)添加开启远程连接的脚本。目前选项有 禁用设备验证 (面向全网,但不安全,需给提示)、使用Candy(面向全网,等我慢慢玩通)、 使用Tailscale(仅面向受控节点,等我慢慢验证Azure VM的节点)。 SSH方式计划放在md里说明。(disableDevAuth, SSH tunnel done@20260325)
(@20260410)添加Copilot CLI的安装和配置ACP。copilot的aka.ms链接坏了,改gh.io了。(待测)添加小配置VM的优化:opt-vps&arm.sh。发现之前VM配置低有时候响应慢。(待测)