Vol*_*ker 7 azure-powershell azure-resource-manager visual-studio-2015 azure-deployment-slots azure-resource-group
我正在尝试进入Visual Studio资源组模板.到目前为止它看起来很好,我已经添加了一些web应用程序的appsettings,但我的问题是,我如何使他们部署插槽具体?json中是否有模板或参数文件的内容?
请尝试添加在ARM模板中剪切的json代码.我测试了它.它运作成功.
"resources": [
{
"apiVersion": "2015-08-01",
"name": "appsettings",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites/Slots', variables('webSiteName'), 'Staging')]"
],
"properties": {
"AppSettingKey1": "Some staging value",
"AppSettingKey2": "My second staging setting",
"AppSettingKey3": "My third staging setting"
}
}
]
Run Code Online (Sandbox Code Playgroud)
以下是我的详细步骤:
1.创建新的Azure资源组项目(更多详细信息,请参阅文档)
2.仅针对Azure网站插槽应用程序设置配置的演示,因此从项目中删除其他资源.
4.发布部署
完整的json代码:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"hostingPlanName": {
"type": "string",
"minLength": 1
},
"skuName": {
"type": "string",
"defaultValue": "S1",
"allowedValues": [
"F1",
"D1",
"B1",
"B2",
"B3",
"S1",
"S2",
"S3",
"P1",
"P2",
"P3",
"P4"
],
"metadata": {
"description": "Describes plan's pricing tier and instance size. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
}
},
"skuCapacity": {
"type": "int",
"defaultValue": 1,
"minValue": 1,
"metadata": {
"description": "Describes plan's instance count"
}
}
},
"variables": {
"webSiteName": "[concat('webSite', uniqueString(resourceGroup().id))]"
},
"resources": [
{
"apiVersion": "2015-08-01",
"name": "[parameters('hostingPlanName')]",
"type": "Microsoft.Web/serverfarms",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "HostingPlan"
},
"sku": {
"name": "[parameters('skuName')]",
"capacity": "[parameters('skuCapacity')]"
},
"properties": {
"name": "[parameters('hostingPlanName')]"
}
},
{
"apiVersion": "2015-08-01",
"dependsOn": [
"[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
],
"location": "[resourceGroup().location]",
"name": "[variables('webSiteName')]",
"properties": {
"name": "[variables('webSiteName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
},
"resources": [
{
"apiVersion": "2015-08-01",
"name": "Staging",
"type": "slots",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
],
"properties": {
},
"resources": [
{
"apiVersion": "2015-08-01",
"name": "appsettings",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites/Slots', variables('webSiteName'), 'Staging')]"
],
"properties": {
"AppSettingKey1": "Some staging value",
"AppSettingKey2": "My second staging setting",
"AppSettingKey3": "My third staging setting"
}
}
]
}
],
"tags": {
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource",
"displayName": "Website"
},
"type": "Microsoft.Web/sites"
}
]
}
Run Code Online (Sandbox Code Playgroud)
如果Azure门户上有任何插槽,我们也可以从azure资源获取插槽类型.
我也在SO中找到了类似的帖子.
公认的答案是正确的,但遗漏了重要的信息。在其当前实现下,交换插槽时,插槽的AppSettings配置将与部署一起交换。如果您担心特定于插槽的配置,那么您可能不希望这样做。
要将配置“固定”到插槽,请在ARM模板中使用以下资源。请注意,slotconfignames部分已从上述Tom的答案添加到ARM模板代码段中。
"resources": [
{
"apiVersion": "2015-08-01",
"name": "appsettings",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites/Slots', variables('webSiteName'), 'Staging')]"
],
"properties": {
"AppSettingKey1": "Some staging value",
"AppSettingKey2": "My second staging setting",
"AppSettingKey3": "My third staging setting"
},
{
"apiVersion": "2015-08-01",
"name": "slotconfignames",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
],
"properties": {
"appSettingNames": [ "AppSettingKey1", "AppSettingKey2" ]
}
}
]
Run Code Online (Sandbox Code Playgroud)
这将使AppSettingKey1和AppSettingKey2粘贴到暂存插槽(它们不会随部署一起交换)。
有关粘性插槽设置以及其他ARM模板提示的更多详细信息,请参见Anthony Chu的“ Azure资源管理器模板的提示和技巧”。
| 归档时间: |
|
| 查看次数: |
3640 次 |
| 最近记录: |