Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart Web App Container after config update #9819

Merged
merged 7 commits into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,11 @@
"loc.messages.FailedToGetResourceID": "Failed to get resource ID for resource type '%s' and resource name '%s'. Error: %s",
"loc.messages.JarPathNotPresent": "Java jar path is not present",
"loc.messages.FailedToUpdateApplicationInsightsResource": "Failed to update Application Insights '%s' Resource. Error: %s",
"loc.messages.InvalidDockerImageName": "Invalid Docker hub image name provided."
"loc.messages.InvalidDockerImageName": "Invalid Docker hub image name provided.",
"loc.messages.RestartingAppService": "Restarting App Service : %s",
"loc.messages.RestartingAppServiceSlot": "Restarting App Service: %s-%s",
"loc.messages.RestartedAppService": "App Service '%s' restarted successfully.",
"loc.messages.RestartedAppServiceSlot": "App Service '%s-%s' restarted successfully.",
"loc.messages.FailedToRestartAppService": "Failed to restart App Service '%s'. Error: %s",
"loc.messages.FailedToRestartAppServiceSlot": "Failed to restart App Service '%s-%s'. Error: %s"
}
2 changes: 2 additions & 0 deletions Tasks/AzureFunctionAppContainerV1/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ describe('AzureFunctionOnContainerDeployment Suite', function() {
assert(tr.stdOutContained('PreDeployment steps for container web app with slot enabled should succeeded'), 'Should have printed: PreDeployment steps for container web app withSlotEnabled should succeeded');
assert(tr.stdOutContained('Resource Group: MOCK_RESOURCE_GROUP_NAME'), 'Should have printed: Resource Group: MOCK_RESOURCE_GROUP_NAME');
assert(tr.stdOutContained('Active DeploymentId :MOCK_DEPLOYMENT_ID'), 'Should have printed: Active DeploymentId :MOCK_DEPLOYMENT_ID.');
assert(tr.stdOutContained('loc_mock_RestartingAppService mytestapp'), 'Should have printed: loc_mock_RestartingAppService mytestapp');
assert(tr.stdOutContained('loc_mock_RestartedAppService mytestapp'), 'Should have printed: loc_mock_RestartedAppService mytestapp');
assert(tr.stdOutContained('loc_mock_UpdatingAppServiceConfigurationSettings {"appCommandLine":null,"linuxFxVersion":"DOCKER|dockernamespace/dockerrepository:DockerImageTag"}'), 'Should have printed: loc_mock_UpdatingAppServiceConfigurationSettings {"appCommandLine":null,"linuxFxVersion":"DOCKER|dockernamespace/dockerrepository:DockerImageTag"}');
assert(tr.stdOutContained('loc_mock_UpdatedAppServiceConfigurationSettings'), 'Should have printed: loc_mock_UpdatedAppServiceConfigurationSettings');
assert(tr.stdOutContained('loc_mock_UpdatedAppServiceApplicationSettings'), 'Should have printed: loc_mock_UpdatedAppServiceApplicationSettings');
Expand Down
12 changes: 11 additions & 1 deletion Tasks/AzureFunctionAppContainerV1/Tests/mock_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export function mockContainerDeploySettings() {
"MSDEPLOY_RENAME_LOCKED_FILES": "1",
"WEBSITE_RUN_FROM_PACKAGE":"0",
"DOCKER_CUSTOM_IMAGE_NAME": "dockernamespace/dockerrepository:DockerImageTag",
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" : "false"
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" : "false",
"port": "1173"
}
}).persist();

Expand Down Expand Up @@ -160,4 +161,13 @@ export function mockContainerDeploySettings() {
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" : "false"
}
}).persist();

nock('https://management.azure.com', {
reqheaders: {
"authorization": "Bearer DUMMY_ACCESS_TOKEN",
"content-type": "application/json; charset=utf-8",
"user-agent": "TFS_useragent"
}
}).post("/subscriptions/MOCK_SUBSCRIPTION_ID/resourceGroups/MOCK_RESOURCE_GROUP_NAME/providers/Microsoft.Web/sites/mytestapp/restart?api-version=2016-08-01")
.reply(200);
}
1 change: 1 addition & 0 deletions Tasks/AzureFunctionAppContainerV1/Tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ export function mockTaskInputParameters(tr) {
tr.setInput('azureSubscription', 'AzureRMSpn');
tr.setInput('appName', 'mytestapp');
tr.setInput('imageName', 'dockernamespace/dockerrepository:DockerImageTag');
tr.setInput('AppSettings', '-port 1173');
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import tl = require('vsts-task-lib/task');
import { addReleaseAnnotation } from 'azurermdeploycommon/operations/ReleaseAnnotationUtility';
import { ContainerBasedDeploymentUtility } from 'azurermdeploycommon/operations/ContainerBasedDeploymentUtility';
const linuxFunctionStorageSetting: string = '-WEBSITES_ENABLE_APP_SERVICE_STORAGE false';
import * as ParameterParser from 'azurermdeploycommon/operations/ParameterParserUtility';

export class AzureFunctionOnContainerDeploymentProvider{
protected taskParams:TaskParameters;
Expand Down Expand Up @@ -44,10 +45,12 @@ export class AzureFunctionOnContainerDeploymentProvider{
public async DeployWebAppStep() {
tl.debug("Performing container based deployment.");

this.taskParams.AppSettings = this.taskParams.AppSettings ? this.taskParams.AppSettings.trim() + " " + linuxFunctionStorageSetting : linuxFunctionStorageSetting;

let containerDeploymentUtility: ContainerBasedDeploymentUtility = new ContainerBasedDeploymentUtility(this.appService);
await containerDeploymentUtility.deployWebAppImage(this.taskParams);

this.taskParams.AppSettings = this.taskParams.AppSettings ? this.taskParams.AppSettings.trim() + " " + linuxFunctionStorageSetting : linuxFunctionStorageSetting;
let customApplicationSettings = ParameterParser.parse(this.taskParams.AppSettings);
await this.appServiceUtility.updateAndMonitorAppSettings(customApplicationSettings);

await this.appServiceUtility.updateScmTypeAndConfigurationDetails();
}
Expand Down
10 changes: 8 additions & 2 deletions Tasks/AzureFunctionAppContainerV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 2
"Patch": 3
},
"minimumAgentVersion": "2.104.1",
"groups": [
Expand Down Expand Up @@ -311,6 +311,12 @@
"FailedToGetResourceID": "Failed to get resource ID for resource type '%s' and resource name '%s'. Error: %s",
"JarPathNotPresent": "Java jar path is not present",
"FailedToUpdateApplicationInsightsResource": "Failed to update Application Insights '%s' Resource. Error: %s",
"InvalidDockerImageName": "Invalid Docker hub image name provided."
"InvalidDockerImageName": "Invalid Docker hub image name provided.",
"RestartingAppService": "Restarting App Service : %s",
"RestartingAppServiceSlot": "Restarting App Service: %s-%s",
"RestartedAppService": "App Service '%s' restarted successfully.",
"RestartedAppServiceSlot": "App Service '%s-%s' restarted successfully.",
"FailedToRestartAppService": "Failed to restart App Service '%s'. Error: %s",
"FailedToRestartAppServiceSlot": "Failed to restart App Service '%s-%s'. Error: %s"
}
}
10 changes: 8 additions & 2 deletions Tasks/AzureFunctionAppContainerV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 2
"Patch": 3
},
"minimumAgentVersion": "2.104.1",
"groups": [
Expand Down Expand Up @@ -310,6 +310,12 @@
"FailedToGetResourceID": "ms-resource:loc.messages.FailedToGetResourceID",
"JarPathNotPresent": "ms-resource:loc.messages.JarPathNotPresent",
"FailedToUpdateApplicationInsightsResource": "ms-resource:loc.messages.FailedToUpdateApplicationInsightsResource",
"InvalidDockerImageName": "ms-resource:loc.messages.InvalidDockerImageName"
"InvalidDockerImageName": "ms-resource:loc.messages.InvalidDockerImageName",
"RestartingAppService": "ms-resource:loc.messages.RestartingAppService",
"RestartingAppServiceSlot": "ms-resource:loc.messages.RestartingAppServiceSlot",
"RestartedAppService": "ms-resource:loc.messages.RestartedAppService",
"RestartedAppServiceSlot": "ms-resource:loc.messages.RestartedAppServiceSlot",
"FailedToRestartAppService": "ms-resource:loc.messages.FailedToRestartAppService",
"FailedToRestartAppServiceSlot": "ms-resource:loc.messages.FailedToRestartAppServiceSlot"
}
}
2 changes: 1 addition & 1 deletion Tasks/AzureFunctionAppV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 4
"Patch": 5
},
"minimumAgentVersion": "2.104.1",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFunctionAppV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 4
"Patch": 5
},
"minimumAgentVersion": "2.104.1",
"groups": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,11 @@
"loc.messages.FailedToGetResourceID": "Failed to get resource ID for resource type '%s' and resource name '%s'. Error: %s",
"loc.messages.JarPathNotPresent": "Java jar path is not present",
"loc.messages.FailedToUpdateApplicationInsightsResource": "Failed to update Application Insights '%s' Resource. Error: %s",
"loc.messages.InvalidDockerImageName": "Invalid Docker hub image name provided."
"loc.messages.InvalidDockerImageName": "Invalid Docker hub image name provided.",
"loc.messages.RestartingAppService": "Restarting App Service : %s",
"loc.messages.RestartingAppServiceSlot": "Restarting App Service: %s-%s",
"loc.messages.RestartedAppService": "App Service '%s' restarted successfully.",
"loc.messages.RestartedAppServiceSlot": "App Service '%s-%s' restarted successfully.",
"loc.messages.FailedToRestartAppService": "Failed to restart App Service '%s'. Error: %s",
"loc.messages.FailedToRestartAppServiceSlot": "Failed to restart App Service '%s-%s'. Error: %s"
}
2 changes: 2 additions & 0 deletions Tasks/AzureWebAppContainerV1/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ describe('AzureWebAppDeployment Suite', function() {
assert(tr.stdOutContained('loc_mock_UpdatingAppServiceConfigurationSettings {"appCommandLine":null,"linuxFxVersion":"DOCKER|dockernamespace/dockerrepository:DockerImageTag"}'), 'Should have printed: loc_mock_UpdatingAppServiceConfigurationSettings {"appCommandLine":null,"linuxFxVersion":"DOCKER|dockernamespace/dockerrepository:DockerImageTag"}');
assert(tr.stdOutContained('loc_mock_UpdatedAppServiceConfigurationSettings'), 'Should have printed: loc_mock_UpdatedAppServiceConfigurationSettings');
assert(tr.stdOutContained('loc_mock_UpdatedAppServiceApplicationSettings'), 'Should have printed: loc_mock_UpdatedAppServiceApplicationSettings');
assert(tr.stdOutContained('loc_mock_RestartingAppService mytestapp'), 'Should have printed: loc_mock_RestartingAppService mytestapp');
assert(tr.stdOutContained('loc_mock_RestartedAppService mytestapp'), 'Should have printed: loc_mock_RestartedAppService mytestapp');
assert(tr.stdOutContained('Web app Deployment steps for container should succeeded'), 'Should have printed: Web app Deployment steps for container should succeeded');
done();
}
Expand Down
12 changes: 11 additions & 1 deletion Tasks/AzureWebAppContainerV1/Tests/mock_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ export function mockContainerDeploySettings() {
"WEBSITE_NODE_DEFAULT_VERSION": "6.9.1",
"MSDEPLOY_RENAME_LOCKED_FILES": "1",
"WEBSITE_RUN_FROM_PACKAGE":"0",
"DOCKER_CUSTOM_IMAGE_NAME": "dockernamespace/dockerrepository:DockerImageTag"
"DOCKER_CUSTOM_IMAGE_NAME": "dockernamespace/dockerrepository:DockerImageTag",
"port": "1173"
}
}).persist();

Expand Down Expand Up @@ -157,4 +158,13 @@ export function mockContainerDeploySettings() {
"DOCKER_CUSTOM_IMAGE_NAME": "dockernamespace/dockerrepository:DockerImageTag"
}
}).persist();

nock('https://management.azure.com', {
reqheaders: {
"authorization": "Bearer DUMMY_ACCESS_TOKEN",
"content-type": "application/json; charset=utf-8",
"user-agent": "TFS_useragent"
}
}).post("/subscriptions/MOCK_SUBSCRIPTION_ID/resourceGroups/MOCK_RESOURCE_GROUP_NAME/providers/Microsoft.Web/sites/mytestapp/restart?api-version=2016-08-01")
.reply(200);
}
1 change: 1 addition & 0 deletions Tasks/AzureWebAppContainerV1/Tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ export function mockTaskInputParameters(tr) {
tr.setInput('azureSubscription', 'AzureRMSpn');
tr.setInput('appName', 'mytestapp');
tr.setInput('imageName', 'dockernamespace/dockerrepository:DockerImageTag');
tr.setInput('AppSettings', '-port 1173');
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { AzureResourceFilterUtility } from 'azurermdeploycommon/operations/Azure
import tl = require('vsts-task-lib/task');
import { addReleaseAnnotation } from 'azurermdeploycommon/operations/ReleaseAnnotationUtility';
import { ContainerBasedDeploymentUtility } from 'azurermdeploycommon/operations/ContainerBasedDeploymentUtility';
import * as ParameterParser from 'azurermdeploycommon/operations/ParameterParserUtility';

export class AzureRmWebAppDeploymentProvider{
protected taskParams:TaskParameters;
Expand Down Expand Up @@ -46,6 +47,11 @@ export class AzureRmWebAppDeploymentProvider{
let containerDeploymentUtility: ContainerBasedDeploymentUtility = new ContainerBasedDeploymentUtility(this.appService);
await containerDeploymentUtility.deployWebAppImage(this.taskParams);

if(this.taskParams.AppSettings) {
var customApplicationSettings = ParameterParser.parse(this.taskParams.AppSettings);
await this.appServiceUtility.updateAndMonitorAppSettings(customApplicationSettings);
}

await this.appServiceUtility.updateScmTypeAndConfigurationDetails();
}

Expand Down
10 changes: 8 additions & 2 deletions Tasks/AzureWebAppContainerV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 3
"Patch": 4
},
"minimumAgentVersion": "2.104.1",
"groups": [
Expand Down Expand Up @@ -309,6 +309,12 @@
"FailedToGetResourceID": "Failed to get resource ID for resource type '%s' and resource name '%s'. Error: %s",
"JarPathNotPresent": "Java jar path is not present",
"FailedToUpdateApplicationInsightsResource": "Failed to update Application Insights '%s' Resource. Error: %s",
"InvalidDockerImageName": "Invalid Docker hub image name provided."
"InvalidDockerImageName": "Invalid Docker hub image name provided.",
"RestartingAppService": "Restarting App Service : %s",
"RestartingAppServiceSlot": "Restarting App Service: %s-%s",
"RestartedAppService": "App Service '%s' restarted successfully.",
"RestartedAppServiceSlot": "App Service '%s-%s' restarted successfully.",
"FailedToRestartAppService": "Failed to restart App Service '%s'. Error: %s",
"FailedToRestartAppServiceSlot": "Failed to restart App Service '%s-%s'. Error: %s"
}
}
10 changes: 8 additions & 2 deletions Tasks/AzureWebAppContainerV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 3
"Patch": 4
},
"minimumAgentVersion": "2.104.1",
"groups": [
Expand Down Expand Up @@ -309,6 +309,12 @@
"FailedToGetResourceID": "ms-resource:loc.messages.FailedToGetResourceID",
"JarPathNotPresent": "ms-resource:loc.messages.JarPathNotPresent",
"FailedToUpdateApplicationInsightsResource": "ms-resource:loc.messages.FailedToUpdateApplicationInsightsResource",
"InvalidDockerImageName": "ms-resource:loc.messages.InvalidDockerImageName"
"InvalidDockerImageName": "ms-resource:loc.messages.InvalidDockerImageName",
"RestartingAppService": "ms-resource:loc.messages.RestartingAppService",
"RestartingAppServiceSlot": "ms-resource:loc.messages.RestartingAppServiceSlot",
"RestartedAppService": "ms-resource:loc.messages.RestartedAppService",
"RestartedAppServiceSlot": "ms-resource:loc.messages.RestartedAppServiceSlot",
"FailedToRestartAppService": "ms-resource:loc.messages.FailedToRestartAppService",
"FailedToRestartAppServiceSlot": "ms-resource:loc.messages.FailedToRestartAppServiceSlot"
}
}
2 changes: 1 addition & 1 deletion Tasks/AzureWebAppV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 4
"Patch": 5
},
"minimumAgentVersion": "2.104.1",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureWebAppV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 4
"Patch": 5
},
"minimumAgentVersion": "2.104.1",
"groups": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,8 @@ export class ContainerBasedDeploymentUtility {
tl.debug("Updating the webapp configuration.");
await this._updateConfigurationDetails(properties["ConfigurationSettings"], properties["StartupCommand"], imageName);

tl.debug('Updating web app settings');
await this._updateApplicationSettings(properties["AppSettings"], imageName);
}

private async _updateApplicationSettings(appSettings: any, imageName: string): Promise<void> {
var appSettingsParameters = appSettings ? appSettings.trim() : "";
appSettingsParameters = await this._getContainerRegistrySettings(imageName, null) + ' ' + appSettingsParameters;
var appSettingsNewProperties = parse(appSettingsParameters);
await this._appServiceUtility.updateAndMonitorAppSettings(appSettingsNewProperties);
tl.debug('making a restart request to app service');
await this._appService.restart();
vincent1173 marked this conversation as resolved.
Show resolved Hide resolved
}

private async _updateConfigurationDetails(configSettings: any, startupCommand: string, imageName: string): Promise<void> {
Expand Down