From 8860c84a0a3d18b9a15ae001aed7547de969cd44 Mon Sep 17 00:00:00 2001 From: Disha Khakhar Date: Tue, 20 Jun 2017 11:58:59 +0530 Subject: [PATCH] enable deploy to slot option for linux apps (#4581) * enable deploy to slot option for linux apps * review comments --- .../resources.resjson/en-US/resources.resjson | 12 ++-- .../azurermwebappcontainerdeployment.ts | 38 +++++------ .../azurermwebappdeployment.ts | 6 +- Tasks/AzureRmWebAppDeployment/task.json | 68 +++++++++---------- Tasks/AzureRmWebAppDeployment/task.loc.json | 68 +++++++++---------- 5 files changed, 93 insertions(+), 99 deletions(-) diff --git a/Tasks/AzureRmWebAppDeployment/Strings/resources.resjson/en-US/resources.resjson b/Tasks/AzureRmWebAppDeployment/Strings/resources.resjson/en-US/resources.resjson index 2bc174b31989..fb0eac802382 100644 --- a/Tasks/AzureRmWebAppDeployment/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/AzureRmWebAppDeployment/Strings/resources.resjson/en-US/resources.resjson @@ -14,6 +14,12 @@ "loc.input.help.WebAppName": "Enter or Select the name of an existing Azure App Service.", "loc.input.label.ServerfarmId": "Serverfarm id", "loc.input.label.WebAppKind": "Web app kind", + "loc.input.label.DeployToSlotFlag": "Deploy to slot", + "loc.input.help.DeployToSlotFlag": "Select the option to deploy to an existing slot other than the Production slot. If this option is not selected, then the Azure App Service will be deployed to the Production slot.", + "loc.input.label.ResourceGroupName": "Resource group", + "loc.input.help.ResourceGroupName": "Enter or Select the Azure Resource group that contains the Azure App Service specified above.", + "loc.input.label.SlotName": "Slot", + "loc.input.help.SlotName": "Enter or Select an existing Slot other than the Production slot.", "loc.input.label.DockerNamespace": "Registry or Namespace", "loc.input.help.DockerNamespace": "A globally unique top-level domain name for your specific registry or namespace.
Note: Fully qualified image name will be of the format: '`/`:`'. For example, 'myregistry.azurecr.io/nginx:latest'.", "loc.input.label.DockerRepository": "Repository", @@ -22,12 +28,6 @@ "loc.input.help.DockerImageTag": "Tags are optional, it is the mechanism that registries use to give Docker images a version.
Note: Fully qualified image name will be of the format: '`/`:`'. For example, 'myregistry.azurecr.io/nginx:latest'.", "loc.input.label.StartupCommand": "Startup command ", "loc.input.help.StartupCommand": "Enter the start up command.", - "loc.input.label.DeployToSlotFlag": "Deploy to slot", - "loc.input.help.DeployToSlotFlag": "Select the option to deploy to an existing slot other than the Production slot. If this option is not selected, then the Azure App Service will be deployed to the Production slot.", - "loc.input.label.ResourceGroupName": "Resource group", - "loc.input.help.ResourceGroupName": "Enter or Select the Azure Resource group that contains the Azure App Service specified above.", - "loc.input.label.SlotName": "Slot", - "loc.input.help.SlotName": "Enter or Select an existing Slot other than the Production slot.", "loc.input.label.VirtualApplication": "Virtual application", "loc.input.help.VirtualApplication": "Specify the name of the Virtual application that has been configured in the Azure portal. The option is not required for deployments to the App Service root.", "loc.input.label.Package": "Package or folder", diff --git a/Tasks/AzureRmWebAppDeployment/azurermwebappcontainerdeployment.ts b/Tasks/AzureRmWebAppDeployment/azurermwebappcontainerdeployment.ts index e1f680fdfd17..3be4cb0c8c00 100644 --- a/Tasks/AzureRmWebAppDeployment/azurermwebappcontainerdeployment.ts +++ b/Tasks/AzureRmWebAppDeployment/azurermwebappcontainerdeployment.ts @@ -4,7 +4,7 @@ import util = require('util'); var azureRESTUtility = require ('azurerest-common/azurerestutility.js'); var parameterParser = require("./parameterparser.js").parse; -export async function deployWebAppImage(endPoint, resourceGroupName, webAppName) { +export async function deployWebAppImage(endPoint, resourceGroupName, webAppName, deployToSlotFlag, slotName) { var startupCommand = tl.getInput('StartupCommand', false); var appSettings = tl.getInput('AppSettings', false); var imageSourceAndTag; @@ -29,29 +29,27 @@ export async function deployWebAppImage(endPoint, resourceGroupName, webAppName) imageSourceAndTag = dockerNamespace + "/" + dockerRepository; } - if(imageSourceAndTag) - { - tl.debug("Deploying the image " + imageSourceAndTag + " to the webapp " + webAppName); + var appName = deployToSlotFlag ? webAppName + "-" + slotName : webAppName; + tl.debug("Deploying the image " + imageSourceAndTag + " to the webapp " + appName); - tl.debug("Updating the webapp configuration."); - var updatedConfigDetails = JSON.stringify({ - "properties": { - "appCommandLine": startupCommand, - "linuxFxVersion": "DOCKER|" + imageSourceAndTag - } - }); + tl.debug("Updating the webapp configuration."); + var updatedConfigDetails = JSON.stringify({ + "properties": { + "appCommandLine": startupCommand, + "linuxFxVersion": "DOCKER|" + imageSourceAndTag + } + }); - await azureRESTUtility.updateAzureRMWebAppConfigDetails(endPoint, webAppName, resourceGroupName, false, null, updatedConfigDetails); + await azureRESTUtility.updateAzureRMWebAppConfigDetails(endPoint, webAppName, resourceGroupName, deployToSlotFlag, slotName, updatedConfigDetails); - tl.debug("Updating the webapp application settings."); - appSettings = appSettings ? appSettings.trim() : ""; - appSettings = "-DOCKER_CUSTOM_IMAGE_NAME " + imageSourceAndTag + " " + appSettings; + tl.debug("Updating the webapp application settings."); + appSettings = appSettings ? appSettings.trim() : ""; + appSettings = "-DOCKER_CUSTOM_IMAGE_NAME " + imageSourceAndTag + " " + appSettings; - // Update webapp application setting - var webAppSettings = await azureRESTUtility.getWebAppAppSettings(endPoint, webAppName, resourceGroupName, false, null); - mergeAppSettings(appSettings, webAppSettings); - await azureRESTUtility.updateWebAppAppSettings(endPoint, webAppName, resourceGroupName, false, null, webAppSettings); - } + // Update webapp application setting + var webAppSettings = await azureRESTUtility.getWebAppAppSettings(endPoint, webAppName, resourceGroupName, deployToSlotFlag, slotName); + mergeAppSettings(appSettings, webAppSettings); + await azureRESTUtility.updateWebAppAppSettings(endPoint, webAppName, resourceGroupName, deployToSlotFlag, slotName, webAppSettings); } function mergeAppSettings(appSettings, webAppSettings) { diff --git a/Tasks/AzureRmWebAppDeployment/azurermwebappdeployment.ts b/Tasks/AzureRmWebAppDeployment/azurermwebappdeployment.ts index 4501c23e4de9..64df1230ba4d 100644 --- a/Tasks/AzureRmWebAppDeployment/azurermwebappdeployment.ts +++ b/Tasks/AzureRmWebAppDeployment/azurermwebappdeployment.ts @@ -53,10 +53,6 @@ async function run() { endPoint["envAuthUrl"] = tl.getEndpointDataParameter(connectedServiceName, 'environmentAuthorityUrl', true); endPoint["url"] = tl.getEndpointUrl(connectedServiceName, true); - if(webAppKind && webAppKind === "linux") { - deployToSlotFlag = false; - } - if(deployToSlotFlag) { if (slotName.toLowerCase() === "production") { deployToSlotFlag = false; @@ -74,7 +70,7 @@ async function run() { { tl.debug("Performing container based deployment."); - await deployWebAppImage(endPoint, resourceGroupName, webAppName); + await deployWebAppImage(endPoint, resourceGroupName, webAppName, deployToSlotFlag, slotName); } else { diff --git a/Tasks/AzureRmWebAppDeployment/task.json b/Tasks/AzureRmWebAppDeployment/task.json index c644f609658d..1864641032bd 100644 --- a/Tasks/AzureRmWebAppDeployment/task.json +++ b/Tasks/AzureRmWebAppDeployment/task.json @@ -16,7 +16,7 @@ "version": { "Major": 3, "Minor": 3, - "Patch": 8 + "Patch": 9 }, "releaseNotes": "What's new in Version 3.0:
  Supports File Transformations (XDT)
  Supports Variable Substitutions(XML, JSON)
Click [here](https://aka.ms/azurermwebdeployreadme) for more Information.", "minimumAgentVersion": "2.104.1", @@ -90,6 +90,39 @@ "PopulateDefaultValue": "true" } }, + { + "name": "DeployToSlotFlag", + "type": "boolean", + "label": "Deploy to slot", + "defaultValue": "false", + "required": false, + "helpMarkDown": "Select the option to deploy to an existing slot other than the Production slot. If this option is not selected, then the Azure App Service will be deployed to the Production slot.", + "visibleRule": "WebAppKind = app || WebAppKind = functionapp || WebAppKind = linux" + }, + { + "name": "ResourceGroupName", + "type": "pickList", + "label": "Resource group", + "defaultValue": "", + "required": true, + "properties": { + "EditableOptions": "True" + }, + "helpMarkDown": "Enter or Select the Azure Resource group that contains the Azure App Service specified above.", + "visibleRule": "DeployToSlotFlag = true" + }, + { + "name": "SlotName", + "type": "pickList", + "label": "Slot", + "defaultValue": "", + "required": true, + "properties": { + "EditableOptions": "True" + }, + "helpMarkDown": "Enter or Select an existing Slot other than the Production slot.", + "visibleRule": "DeployToSlotFlag = true" + }, { "name": "DockerNamespace", "type": "string", @@ -126,39 +159,6 @@ "visibleRule": "WebAppKind = linux", "helpMarkDown": "Enter the start up command." }, - { - "name": "DeployToSlotFlag", - "type": "boolean", - "label": "Deploy to slot", - "defaultValue": "false", - "required": false, - "helpMarkDown": "Select the option to deploy to an existing slot other than the Production slot. If this option is not selected, then the Azure App Service will be deployed to the Production slot.", - "visibleRule": "WebAppKind = app || WebAppKind = functionapp" - }, - { - "name": "ResourceGroupName", - "type": "pickList", - "label": "Resource group", - "defaultValue": "", - "required": true, - "properties": { - "EditableOptions": "True" - }, - "helpMarkDown": "Enter or Select the Azure Resource group that contains the Azure App Service specified above.", - "visibleRule": "DeployToSlotFlag = true" - }, - { - "name": "SlotName", - "type": "pickList", - "label": "Slot", - "defaultValue": "", - "required": true, - "properties": { - "EditableOptions": "True" - }, - "helpMarkDown": "Enter or Select an existing Slot other than the Production slot.", - "visibleRule": "DeployToSlotFlag = true" - }, { "name": "VirtualApplication", "type": "string", diff --git a/Tasks/AzureRmWebAppDeployment/task.loc.json b/Tasks/AzureRmWebAppDeployment/task.loc.json index 602c3961c95a..b75fb9709b39 100644 --- a/Tasks/AzureRmWebAppDeployment/task.loc.json +++ b/Tasks/AzureRmWebAppDeployment/task.loc.json @@ -16,7 +16,7 @@ "version": { "Major": 3, "Minor": 3, - "Patch": 8 + "Patch": 9 }, "releaseNotes": "ms-resource:loc.releaseNotes", "minimumAgentVersion": "2.104.1", @@ -90,6 +90,39 @@ "PopulateDefaultValue": "true" } }, + { + "name": "DeployToSlotFlag", + "type": "boolean", + "label": "ms-resource:loc.input.label.DeployToSlotFlag", + "defaultValue": "false", + "required": false, + "helpMarkDown": "ms-resource:loc.input.help.DeployToSlotFlag", + "visibleRule": "WebAppKind = app || WebAppKind = functionapp || WebAppKind = linux" + }, + { + "name": "ResourceGroupName", + "type": "pickList", + "label": "ms-resource:loc.input.label.ResourceGroupName", + "defaultValue": "", + "required": true, + "properties": { + "EditableOptions": "True" + }, + "helpMarkDown": "ms-resource:loc.input.help.ResourceGroupName", + "visibleRule": "DeployToSlotFlag = true" + }, + { + "name": "SlotName", + "type": "pickList", + "label": "ms-resource:loc.input.label.SlotName", + "defaultValue": "", + "required": true, + "properties": { + "EditableOptions": "True" + }, + "helpMarkDown": "ms-resource:loc.input.help.SlotName", + "visibleRule": "DeployToSlotFlag = true" + }, { "name": "DockerNamespace", "type": "string", @@ -126,39 +159,6 @@ "visibleRule": "WebAppKind = linux", "helpMarkDown": "ms-resource:loc.input.help.StartupCommand" }, - { - "name": "DeployToSlotFlag", - "type": "boolean", - "label": "ms-resource:loc.input.label.DeployToSlotFlag", - "defaultValue": "false", - "required": false, - "helpMarkDown": "ms-resource:loc.input.help.DeployToSlotFlag", - "visibleRule": "WebAppKind = app || WebAppKind = functionapp" - }, - { - "name": "ResourceGroupName", - "type": "pickList", - "label": "ms-resource:loc.input.label.ResourceGroupName", - "defaultValue": "", - "required": true, - "properties": { - "EditableOptions": "True" - }, - "helpMarkDown": "ms-resource:loc.input.help.ResourceGroupName", - "visibleRule": "DeployToSlotFlag = true" - }, - { - "name": "SlotName", - "type": "pickList", - "label": "ms-resource:loc.input.label.SlotName", - "defaultValue": "", - "required": true, - "properties": { - "EditableOptions": "True" - }, - "helpMarkDown": "ms-resource:loc.input.help.SlotName", - "visibleRule": "DeployToSlotFlag = true" - }, { "name": "VirtualApplication", "type": "string",