你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

使用相关文件功能引用多个更新文件

需要在单个更新中表达不同更新文件之间的关系时,请使用相关文件功能。

将更新导入到 Device Update for IoT Hub 后,需要包含有关更新有效负载的元数据的导入清单。 在最简单的情况下,导入清单中文件级别的元数据可以是更新有效负载文件的简单列表。 但是,对于更高级的方案,相关文件功能为你提供了一种指定多个更新文件之间的关系的方法。

使用相关文件功能创建导入清单后,可以将相关文件集合添加到一个或多个主有效负载文件。 对于此概念,可以参考 Device Update 的增量更新功能,该功能使用相关文件指定关联到完整映像文件的增量更新。 在增量方案中,相关文件功能可以将完整映像和增量更新都导入为单个更新操作,然后可以将其中任意一个部署到设备。 但是,相关文件功能并不局限于增量更新,因为从设计上而言,该功能是可以由我们的客户根据自身的具体情况进行扩展的。

相关文件功能可用于版本 5 或更高版本的导入清单。

将相关文件添加到导入清单时,请包括以下信息:

  • 文件详细信息

    通过提供文件名、大小和哈希来定义相关文件。

  • 一个下载处理程序

    指定如何处理这些相关文件以生成目标文件。 请通过将 downloadHandler 属性纳入导入清单来指定处理方法。 如果在 file 元素中指定 relatedFiles 的非空集合,则需要包含 downloadHandler。 可使用简单的 id 属性指定 downloadHandler。 下载处理程序 id 的字符数限制为 64 个 ASCII 字符。

  • 相关文件属性

    可以为设备上的更新处理程序提供额外的元数据,以了解如何解释和正确使用已指定为相关文件的文件。 此元数据将作为 properties 属性包的一部分添加到 filerelatedFile 对象。

若要详细了解相关文件的导入架构,请参阅 relatedFiles 对象

以下示例导入清单演示如何使用相关文件功能来导入增量更新。 在此示例中可以看到,在 files 部分有通过 properties 项指定的完整映像 (full-image-file-name)。 properties 项又在其下方有一个关联的 relatedFiles 项。 在 relatedFiles 部分中,可以看到增量更新文件 (delta-from-v1-file-name) 的另一 properties 部分,且列出了具有适当 iddownloadHandler 项 (microsoft/delta:1)。

注意

此示例使用增量更新来演示如何引用相关文件。 如果想要将增量更新作为一项功能来使用,请在增量更新文档中了解详情。

    {
      "updateId": {
        // provider, name, version
      },
      "compatibility": [
        {
          // manufacturer, model, etc.
        }
      ],
      "instructions": {
        "steps": [
          // Inline steps...
        ]
      },
      "files": [
        {  
          // standard file properties
          "fileName": "full-image-file-name",
          "sizeInBytes": 12345,
          "hashes": {
            "SHA256": "full-image-file-hash"
          },
          "mimeType": "application/octet-stream",
          // new properties
          "properties  ": {},
          "relatedFiles": [
            {
              // delta from version 1.0.0.0
              // standard file properties
              "fileName": "delta-from-v1-file-name",
              "sizeInBytes": 1234,
              "hashes": {
                "SHA256": "delta-from-v1-file-hash"
              },
              "mimeType": "application/octet-stream",
              // new properties
              "properties": {
                "microsoft.sourceFileHash": "delta-source-file-hash",
                "microsoft.sourceFileHashAlgorithm": "sha256"
              }
            }  
          ],
          // handler to download/process our related files
      "downloadHandler": {
        "id": "microsoft/delta:1"
      }
    }
  ],
  "createdDateTime": "2021-12-01T01:12:21Z",
  "manifestVersion": "5.0"
    }

用于创建导入清单的 az iot du init v5 命令支持可选的 --related-file 参数。

--related-file 参数采用 pathproperties 键:

--related-file path=<replace with path(s) to your delta file(s), including the full file name> properties='{"microsoft.sourceFileHashAlgorithm": "sha256", "microsoft.sourceFileHash": "<replace with the source SWU image file hash>"}' 

例如:

az iot du update init v5 \
--update-provider Microsoft --update-name myBundled --update-version 2.0 \
--compat manufacturer=Contoso model=SpaceStation \
--step handler=microsoft/script:1 properties='{"arguments": "--pre"}' description="Pre-install script" \
--file path=/my/update/scripts/preinstall.sh downloadHandler=microsoft/delta:1 \
--related-file path=/my/update/scripts/related_preinstall.json properties='{"microsoft.sourceFileHashAlgorithm": "sha256"}' \
--step updateId.provider=Microsoft updateId.name=SwUpdate updateId.version=1.1 \
--step handler=microsoft/script:1 properties='{"arguments": "--post"}' description="Post-install script" \
--file path=/my/update/scripts/postinstall.sh

后续步骤