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

[BUG]: AzureWebAppContainer@1 should error if App Service Resource Kind is not a container (such as "app,linux") #19785

Open
6 of 7 tasks
qqii opened this issue Apr 16, 2024 · 1 comment

Comments

@qqii
Copy link

qqii commented Apr 16, 2024

New issue checklist

Task name

AzureWebAppContainer

Task version

1

Issue Description

This is related, but not the same as #14805.

AzureWebAppContainer should validate and error if the App Service Resource Kind is not within the supported osTypeMap

const osTypeMap = new Map([
[ 'app,container,xenon', 'Windows' ],
[ 'app,linux,container', 'Linux' ]
]);

I have just spent a day tracking down why AzureWebAppContainer doesn't work for our configuration. We are migrating to use containers with App Service. Since the docs makes no mention of changing the resource kind, I had foolishly left it as app,linux.

What caused the most confusion was the successful task, and the Azure Portal which showed the correct container image.

image

I dug into this a little bit, and I've figured out what is going wrong. When the App Service Resource Kind is not within the osTypeMap, the getWebAppKind returns osType as undefined.

private static async getWebAppKind(taskParameters: TaskParameters): Promise<any> {
let resourceGroupName: string = (taskParameters.DeployToSlotOrASEFlag) ? taskParameters.ResourceGroupName : "";
let osType: string;
if (!resourceGroupName) {
var resources = new Resources(taskParameters.azureEndpoint);
var appDetails = await resources.getAppDetails(taskParameters.WebAppName);
resourceGroupName = appDetails["resourceGroupName"];
osType = osTypeMap.get(appDetails["kind"]) ? osTypeMap.get(appDetails["kind"]) : appDetails["kind"];
tl.debug(`Resource Group: ${resourceGroupName}`);
}
else {
var appService = new AzureAppService(taskParameters.azureEndpoint, taskParameters.ResourceGroupName, taskParameters.WebAppName);
var configSettings = await appService.get(true);
osType = osTypeMap.get(configSettings.kind) ? osTypeMap.get(configSettings.kind) : configSettings.kind;
}
return {
resourceGroupName: resourceGroupName,
osType: osType
};
}

This propagates uncaught to deployWebAppImage because it uses properties: any, which in turn calls _updateConfigurationDetails.

if(isLinuxApp) {
if(isMultiContainer) {
let fileData = fs.readFileSync(multicontainerConfigFile);
appSettingsNewProperties.linuxFxVersion = {
'value': "COMPOSE|" + (new Buffer(fileData).toString('base64'))
}
}
else {
appSettingsNewProperties.linuxFxVersion = {
'value': "DOCKER|" + imageName
}
}
}
else {
appSettingsNewProperties.windowsFxVersion = {
'value': "DOCKER|" + imageName
}
}

Here, since isLinuxApp = undefined and undefined is falsy, windowsFxVersion gets set to the specified image. This in turn is displayed under the Azure Portal under "Properties > Web App > {Publishing model, Container Image}", fooling me into thinking something else was going wrong.

It would be really useful if AzureWebAppContainer validated the kind parameter and creates a runtime error instead of silently continuing!

Environment type (Please select at least one enviroment where you face this issue)

  • Self-Hosted
  • Microsoft Hosted
  • VMSS Pool
  • Container

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Relevant log output

Starting: *snip*
==============================================================================
Task         : Azure Web App for Containers
Description  : Deploy containers to Azure App Service
Version      : 1.233.1
Author       : Microsoft Corporation
Help         : https://aka.ms/azurewebappcontainertroubleshooting
==============================================================================
Got service connection details for Azure App Service:'*snip*'
Single-container Deployment to the webapp '*snip*' as only the image detail was specified.
Trying to update App Service Configuration settings. Data: {"appCommandLine":null,"windowsFxVersion":"DOCKER|****snip*"}
Updated App Service Configuration settings.
Restarting App Service : *snip*
App Service '*snip*' restarted successfully.
Successfully updated deployment History at *snip*
App Service Application URL: *snip*
Finishing: *snip*

Repro steps

1. Create an app service with kind "app,linux"
2. Run a pipeline with AzureWebAppContainer
3. It succeeds, and the UI now shows "Publishing model" and "Container Image"
@qqii
Copy link
Author

qqii commented Apr 18, 2024

A further bug, when taskParameters.DeployToSlotOrASEFlag = true, getWebAppKind assumes that all slots of the app service has the same kind. This may not be the case.

private static async getWebAppKind(taskParameters: TaskParameters): Promise<any> {
let resourceGroupName: string = (taskParameters.DeployToSlotOrASEFlag) ? taskParameters.ResourceGroupName : "";
let osType: string;
if (!resourceGroupName) {
var resources = new Resources(taskParameters.azureEndpoint);
var appDetails = await resources.getAppDetails(taskParameters.WebAppName);
resourceGroupName = appDetails["resourceGroupName"];
osType = osTypeMap.get(appDetails["kind"]) ? osTypeMap.get(appDetails["kind"]) : appDetails["kind"];
tl.debug(`Resource Group: ${resourceGroupName}`);
}
else {
var appService = new AzureAppService(taskParameters.azureEndpoint, taskParameters.ResourceGroupName, taskParameters.WebAppName);
var configSettings = await appService.get(true);
osType = osTypeMap.get(configSettings.kind) ? osTypeMap.get(configSettings.kind) : configSettings.kind;
}
return {
resourceGroupName: resourceGroupName,
osType: osType
};
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants