You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用zipdeploy部署Microsoft.Web/staticSites代码?ARM模板场景问询

通过ARM模板使用Zip包部署Azure Static Web Apps代码

Azure Static Web Apps(即你提到的StaticSite资源)的ARM部署逻辑和普通App Service的zipdeploy有所不同,没有直接的扩展支持,但可以通过以下两种方式实现zip包部署:


方法1:嵌入Base64编码的Zip包(适合小型站点)

将静态文件的zip包转换为Base64编码后,直接嵌入ARM模板的StaticSite资源定义中,适合体积较小的静态站点(ARM模板总大小限制约4MB):

{
  "type": "Microsoft.Web/staticSites",
  "apiVersion": "2023-01-01",
  "name": "[parameters('staticSiteName')]",
  "location": "[parameters('location')]",
  "sku": {
    "name": "Free",
    "tier": "Free"
  },
  "properties": {
    "repositoryUrl": "https://example.com/placeholder", // 必填占位符,无实际作用
    "branch": "main",
    "repositoryToken": "[parameters('tempRepositoryToken')]", // 可填入无权限的临时GitHub令牌,仅用于满足API要求
    "buildProperties": {
      "appLocation": "/",
      "outputLocation": "",
      "skipGithubActionWorkflowGeneration": true // 跳过自动创建GitHub Action工作流
    },
    "templateProperties": {
      "templateUrl": "data:text/plain;base64,[你的Zip包Base64编码内容]"
    }
  }
}

方法2:通过Build资源部署远程Zip包(适合大型站点)

先创建StaticSite基础资源,再通过Microsoft.Web/staticSites/builds资源部署存储在远程位置(如Azure Blob存储)的Zip包,无体积限制:

1. 定义StaticSite基础资源

{
  "type": "Microsoft.Web/staticSites",
  "apiVersion": "2023-01-01",
  "name": "[parameters('staticSiteName')]",
  "location": "[parameters('location')]",
  "sku": {
    "name": "Standard",
    "tier": "Standard"
  },
  "properties": {
    "repositoryUrl": "https://example.com/placeholder",
    "branch": "main",
    "repositoryToken": "[parameters('tempRepositoryToken')]",
    "buildProperties": {
      "skipGithubActionWorkflowGeneration": true
    }
  }
}

2. 添加Build部署资源

{
  "type": "Microsoft.Web/staticSites/builds",
  "apiVersion": "2023-01-01",
  "name": "[concat(parameters('staticSiteName'), '/', 'default')]",
  "dependsOn": [
    "[resourceId('Microsoft.Web/staticSites', parameters('staticSiteName'))]"
  ],
  "properties": {
    "source": {
      "type": "Zip",
      "zipUrl": "[parameters('zipPackageSasUrl')]" // 填入Zip包的可访问URL(如带SAS令牌的Azure Blob地址)
    },
    "buildProperties": {
      "appLocation": "/", // Zip包中静态文件的根路径,若整个包都是静态内容则填"/"
      "outputLocation": "" // 若静态文件在子目录(如dist),则填入对应路径
    }
  }
}

关键注意事项

  • repositoryToken必须提供有效值,可生成一个无任何权限的GitHub临时令牌填充,仅用于满足API的必填要求。
  • 托管应用场景下,需确保托管应用的身份有权限访问zipUrl对应的存储资源(如Blob存储的SAS令牌需赋予读取权限)。
  • 若你的静态站点是预构建完成的静态文件,无需配置构建命令;若需在部署时构建,可在buildProperties中添加appBuildCommand参数指定构建命令。

内容的提问来源于stack exchange,提问作者Oleksa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 19:55:08