From 078fab142a7f2b4d530247d8740292b9d8e10e34 Mon Sep 17 00:00:00 2001 From: snehapar9 Date: Mon, 13 Nov 2023 13:25:49 -0800 Subject: [PATCH 1/7] Fix typo --- azurecontainerapps.ts | 2 +- dist/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/azurecontainerapps.ts b/azurecontainerapps.ts index 9b8e0933..4c41343c 100644 --- a/azurecontainerapps.ts +++ b/azurecontainerapps.ts @@ -265,7 +265,7 @@ export class azurecontainerapps { } } - // Get the default location for if the Container App or Container App Environment was not found in the resource group provided. + // Get the default location if the Container App or Container App Environment was not found in the resource group provided. location = await this.appHelper.getDefaultContainerAppLocation(); return location; diff --git a/dist/index.js b/dist/index.js index 9dbc5bc5..aa04cede 100644 --- a/dist/index.js +++ b/dist/index.js @@ -316,7 +316,7 @@ var azurecontainerapps = /** @class */ (function () { return [2 /*return*/, location]; case 12: return [4 /*yield*/, this.appHelper.getDefaultContainerAppLocation()]; case 13: - // Get the default location for if the Container App or Container App Environment was not found in the resource group provided. + // Get the default location if the Container App or Container App Environment was not found in the resource group provided. location = _c.sent(); return [2 /*return*/, location]; } From 9149993506305459b14cf9dd3da4e5a4db664c10 Mon Sep 17 00:00:00 2001 From: snehapar9 Date: Mon, 13 Nov 2023 13:28:37 -0800 Subject: [PATCH 2/7] Fix typo --- azurecontainerapps.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurecontainerapps.ts b/azurecontainerapps.ts index 4c41343c..3324d6fe 100644 --- a/azurecontainerapps.ts +++ b/azurecontainerapps.ts @@ -257,7 +257,7 @@ export class azurecontainerapps { } } - // Check if Container App Environment is provided and exits in the resource group provided and get the location + // Check if Container App Environment is provided and exists in the resource group provided and get the location let doesContainerAppEnvironmentExist = !this.util.isNullOrEmpty(containerAppEnvironment) ? await this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup) : false; if (doesContainerAppEnvironmentExist) { location = await this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment, resourceGroup); From cfd414e909d4006b4d91d5f01af9bd35b5003ac7 Mon Sep 17 00:00:00 2001 From: snehapar9 Date: Mon, 13 Nov 2023 16:13:19 -0800 Subject: [PATCH 3/7] Fix PR comments --- azurecontainerapps.ts | 47 +++++++++++------------ dist/index.js | 79 ++++++++++++++++++++------------------- src/ContainerAppHelper.ts | 25 ++++++++----- 3 files changed, 79 insertions(+), 72 deletions(-) diff --git a/azurecontainerapps.ts b/azurecontainerapps.ts index 3324d6fe..bc162511 100644 --- a/azurecontainerapps.ts +++ b/azurecontainerapps.ts @@ -201,9 +201,6 @@ export class azurecontainerapps { // Get the resource group to deploy to if it was provided, or generate it from the Container App name this.resourceGroup = await this.getOrCreateResourceGroup(this.containerAppName, this.location); - // Determine if the Container App currently exists - this.containerAppExists = await this.appHelper.doesContainerAppExist(this.containerAppName, this.resourceGroup); - // If the Container App doesn't exist, get/create the Container App Environment to use for the Container App if (!this.containerAppExists) { this.containerAppEnvironment = await this.getOrCreateContainerAppEnvironment(this.containerAppName, this.resourceGroup, this.location); @@ -232,8 +229,6 @@ export class azurecontainerapps { private static async getLocation(): Promise { // Set deployment location, if provided let location: string = this.toolHelper.getInput('location', false); - let resourceGroup: string = this.toolHelper.getInput('resourceGroup', false); - let containerAppEnvironment: string = this.toolHelper.getInput('containerAppEnvironment', false); if (!this.util.isNullOrEmpty(location)) { return location; @@ -241,30 +236,36 @@ export class azurecontainerapps { // If no location was provided, attempt to discover the location of the existing Container App Environment linked to the Container App // or Container App Environment provided in the resource group or use the default location. + let resourceGroup: string = this.toolHelper.getInput('resourceGroup', false); - if (!this.util.isNullOrEmpty(resourceGroup)) { - // Check if Container App exists in the resource group provided and get the location from the Container App Environment linked to it - let doesContainerAppExist = await this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup); - if (doesContainerAppExist) { - // Get the name of the Container App Environment linked to the Container App - var environmentName = await this.appHelper.getExistingContainerAppEnvironmentName(this.containerAppName, resourceGroup); - // Check if environment exists in the resource group provided and get the location - var doesContainerAppEnvironmentExistInResourceGroup = !this.util.isNullOrEmpty(environmentName) ? await this.appHelper.doesContainerAppEnvironmentExist(environmentName, resourceGroup) : false; - if (doesContainerAppEnvironmentExistInResourceGroup) { - // Get the location of the Container App Environment linked to the Container App - location = await this.appHelper.getExistingContainerAppEnvironmentLocation(environmentName, resourceGroup); - return location; - } - } + // Get the resource group if it was provided, or generate it from the Container App name + !this.util.isNullOrEmpty(resourceGroup) ? resourceGroup : `${this.containerAppName}-rg`; + + // Check if Container App exists in the resource group provided and get the location from the Container App Environment linked to it + this.containerAppExists = await this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup); + if (this.containerAppExists) { + // Get the name of the Container App Environment linked to the Container App + var environmentName = await this.appHelper.getExistingContainerAppEnvironmentName(this.containerAppName, resourceGroup); - // Check if Container App Environment is provided and exists in the resource group provided and get the location - let doesContainerAppEnvironmentExist = !this.util.isNullOrEmpty(containerAppEnvironment) ? await this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup) : false; - if (doesContainerAppEnvironmentExist) { - location = await this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment, resourceGroup); + // Check if environment exists in the resource group provided and get the location + var doesContainerAppEnvironmentExistInResourceGroup = !this.util.isNullOrEmpty(environmentName) ? await this.appHelper.doesContainerAppEnvironmentExist(environmentName, resourceGroup) : false; + if (doesContainerAppEnvironmentExistInResourceGroup) { + // Get the location of the Container App Environment linked to the Container App + location = await this.appHelper.getExistingContainerAppEnvironmentLocation(environmentName, resourceGroup); return location; } } + let containerAppEnvironment: string = this.toolHelper.getInput('containerAppEnvironment', false); + + // Check if Container App Environment is provided and exits in the resource group provided and get the location + let doesContainerAppEnvironmentExist = !this.util.isNullOrEmpty(containerAppEnvironment) ? await this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup) : false; + if (doesContainerAppEnvironmentExist) { + location = await this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment, resourceGroup); + return location; + } + + // Get the default location if the Container App or Container App Environment was not found in the resource group provided. location = await this.appHelper.getDefaultContainerAppLocation(); return location; diff --git a/dist/index.js b/dist/index.js index aa04cede..e140b8ac 100644 --- a/dist/index.js +++ b/dist/index.js @@ -210,9 +210,9 @@ var azurecontainerapps = /** @class */ (function () { */ azurecontainerapps.setupResources = function () { return __awaiter(this, void 0, void 0, function () { - var _a, _b, _c, _d; - return __generator(this, function (_e) { - switch (_e.label) { + var _a, _b, _c; + return __generator(this, function (_d) { + switch (_d.label) { case 0: // Get the Container App name if it was provided, or generate it from build variables this.containerAppName = this.getContainerAppName(); @@ -221,26 +221,20 @@ var azurecontainerapps = /** @class */ (function () { return [4 /*yield*/, this.getLocation()]; case 1: // Get the location to deploy resources to, if provided, or use the default location - _a.location = _e.sent(); + _a.location = _d.sent(); // Get the resource group to deploy to if it was provided, or generate it from the Container App name _b = this; return [4 /*yield*/, this.getOrCreateResourceGroup(this.containerAppName, this.location)]; case 2: // Get the resource group to deploy to if it was provided, or generate it from the Container App name - _b.resourceGroup = _e.sent(); - // Determine if the Container App currently exists + _b.resourceGroup = _d.sent(); + if (!!this.containerAppExists) return [3 /*break*/, 4]; _c = this; - return [4 /*yield*/, this.appHelper.doesContainerAppExist(this.containerAppName, this.resourceGroup)]; - case 3: - // Determine if the Container App currently exists - _c.containerAppExists = _e.sent(); - if (!!this.containerAppExists) return [3 /*break*/, 5]; - _d = this; return [4 /*yield*/, this.getOrCreateContainerAppEnvironment(this.containerAppName, this.resourceGroup, this.location)]; - case 4: - _d.containerAppEnvironment = _e.sent(); - _e.label = 5; - case 5: return [2 /*return*/]; + case 3: + _c.containerAppEnvironment = _d.sent(); + _d.label = 4; + case 4: return [2 /*return*/]; } }); }); @@ -264,60 +258,64 @@ var azurecontainerapps = /** @class */ (function () { */ azurecontainerapps.getLocation = function () { return __awaiter(this, void 0, void 0, function () { - var location, resourceGroup, containerAppEnvironment, doesContainerAppExist, environmentName, doesContainerAppEnvironmentExistInResourceGroup, _a, doesContainerAppEnvironmentExist, _b; - return __generator(this, function (_c) { - switch (_c.label) { + var location, resourceGroup, _a, environmentName, doesContainerAppEnvironmentExistInResourceGroup, _b, containerAppEnvironment, doesContainerAppEnvironmentExist, _c; + return __generator(this, function (_d) { + switch (_d.label) { case 0: location = this.toolHelper.getInput('location', false); - resourceGroup = this.toolHelper.getInput('resourceGroup', false); - containerAppEnvironment = this.toolHelper.getInput('containerAppEnvironment', false); if (!this.util.isNullOrEmpty(location)) { return [2 /*return*/, location]; } - if (!!this.util.isNullOrEmpty(resourceGroup)) return [3 /*break*/, 12]; + resourceGroup = this.toolHelper.getInput('resourceGroup', false); + // Get the resource group if it was provided, or generate it from the Container App name + !this.util.isNullOrEmpty(resourceGroup) ? resourceGroup : this.containerAppName + "-rg"; + // Check if Container App exists in the resource group provided and get the location from the Container App Environment linked to it + _a = this; return [4 /*yield*/, this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup)]; case 1: - doesContainerAppExist = _c.sent(); - if (!doesContainerAppExist) return [3 /*break*/, 7]; + // Check if Container App exists in the resource group provided and get the location from the Container App Environment linked to it + _a.containerAppExists = _d.sent(); + if (!this.containerAppExists) return [3 /*break*/, 7]; return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentName(this.containerAppName, resourceGroup)]; case 2: - environmentName = _c.sent(); + environmentName = _d.sent(); if (!!this.util.isNullOrEmpty(environmentName)) return [3 /*break*/, 4]; return [4 /*yield*/, this.appHelper.doesContainerAppEnvironmentExist(environmentName, resourceGroup)]; case 3: - _a = _c.sent(); + _b = _d.sent(); return [3 /*break*/, 5]; case 4: - _a = false; - _c.label = 5; + _b = false; + _d.label = 5; case 5: - doesContainerAppEnvironmentExistInResourceGroup = _a; + doesContainerAppEnvironmentExistInResourceGroup = _b; if (!doesContainerAppEnvironmentExistInResourceGroup) return [3 /*break*/, 7]; return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentLocation(environmentName, resourceGroup)]; case 6: // Get the location of the Container App Environment linked to the Container App - location = _c.sent(); + location = _d.sent(); return [2 /*return*/, location]; case 7: + containerAppEnvironment = this.toolHelper.getInput('containerAppEnvironment', false); if (!!this.util.isNullOrEmpty(containerAppEnvironment)) return [3 /*break*/, 9]; return [4 /*yield*/, this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup)]; case 8: - _b = _c.sent(); + _c = _d.sent(); return [3 /*break*/, 10]; case 9: - _b = false; - _c.label = 10; + _c = false; + _d.label = 10; case 10: - doesContainerAppEnvironmentExist = _b; + doesContainerAppEnvironmentExist = _c; if (!doesContainerAppEnvironmentExist) return [3 /*break*/, 12]; return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment, resourceGroup)]; case 11: - location = _c.sent(); + location = _d.sent(); return [2 /*return*/, location]; case 12: return [4 /*yield*/, this.appHelper.getDefaultContainerAppLocation()]; case 13: // Get the default location if the Container App or Container App Environment was not found in the resource group provided. - location = _c.sent(); + location = _d.sent(); return [2 /*return*/, location]; } }); @@ -5161,13 +5159,13 @@ var ContainerAppHelper = /** @class */ (function () { }); }; /** - * Gets the environment Id of an existing Container App + * Gets the environment name of an existing Container App * @param containerAppName - the name of the Container App * @param resourceGroup - the resource group that the Container App is found in */ ContainerAppHelper.prototype.getExistingContainerAppEnvironmentName = function (containerAppName, resourceGroup) { return __awaiter(this, void 0, void 0, function () { - var command, executionResult, err_14; + var command, executionResult, containerappEnvironmentId, err_14; return __generator(this, function (_a) { switch (_a.label) { case 0: @@ -5176,7 +5174,10 @@ var ContainerAppHelper = /** @class */ (function () { return [4 /*yield*/, util.execute(command)]; case 1: executionResult = _a.sent(); - return [2 /*return*/, executionResult.exitCode === 0 ? executionResult.stdout.split("/").pop() : null]; + containerappEnvironmentId = executionResult.stdout.trim(); + //Remove trailing slash if it exists + containerappEnvironmentId = containerappEnvironmentId.endsWith("/") ? containerappEnvironmentId.slice(0, -1) : containerappEnvironmentId; + return [2 /*return*/, executionResult.exitCode === 0 ? containerappEnvironmentId.split("/").pop() : null]; case 2: err_14 = _a.sent(); toolHelper.writeInfo(err_14.message); diff --git a/src/ContainerAppHelper.ts b/src/ContainerAppHelper.ts index 58ecdd8b..ba2d61bf 100644 --- a/src/ContainerAppHelper.ts +++ b/src/ContainerAppHelper.ts @@ -7,7 +7,7 @@ import fs = require('fs'); const ORYX_CLI_IMAGE: string = 'mcr.microsoft.com/oryx/cli:builder-debian-bullseye-20230926.1'; const ORYX_BULLSEYE_BUILDER_IMAGE: string = 'mcr.microsoft.com/oryx/builder:debian-bullseye-20231107.2' const ORYX_BOOKWORM_BUILDER_IMAGE: string = 'mcr.microsoft.com/oryx/builder:debian-bookworm-20231107.2' -const ORYX_BUILDER_IMAGES: string[] = [ ORYX_BULLSEYE_BUILDER_IMAGE, ORYX_BOOKWORM_BUILDER_IMAGE ]; +const ORYX_BUILDER_IMAGES: string[] = [ORYX_BULLSEYE_BUILDER_IMAGE, ORYX_BOOKWORM_BUILDER_IMAGE]; const IS_WINDOWS_AGENT: boolean = os.platform() == 'win32'; const PACK_CMD: string = IS_WINDOWS_AGENT ? path.join(os.tmpdir(), 'pack') : 'pack'; const toolHelper = new GitHubActionsToolHelper(); @@ -45,13 +45,13 @@ export class ContainerAppHelper { } } - /** - * Creates an Azure Container App. - * @param containerAppName - the name of the Container App - * @param resourceGroup - the resource group that the Container App is found in - * @param optionalCmdArgs - a set of optional command line arguments - */ - public async createOrUpdateContainerAppWithUp( + /** + * Creates an Azure Container App. + * @param containerAppName - the name of the Container App + * @param resourceGroup - the resource group that the Container App is found in + * @param optionalCmdArgs - a set of optional command line arguments + */ + public async createOrUpdateContainerAppWithUp( containerAppName: string, resourceGroup: string, optionalCmdArgs: string[]) { @@ -287,7 +287,7 @@ export class ContainerAppHelper { } /** - * Gets the environment Id of an existing Container App + * Gets the environment name of an existing Container App * @param containerAppName - the name of the Container App * @param resourceGroup - the resource group that the Container App is found in */ @@ -295,7 +295,12 @@ export class ContainerAppHelper { try { let command = `az containerapp show -n ${containerAppName} -g ${resourceGroup} --query properties.environmentId`; let executionResult = await util.execute(command); - return executionResult.exitCode === 0 ? executionResult.stdout.split("/").pop() : null; + let containerappEnvironmentId = executionResult.stdout.trim(); + + //Remove trailing slash if it exists + containerappEnvironmentId = containerappEnvironmentId.endsWith("/") ? containerappEnvironmentId.slice(0, -1) : containerappEnvironmentId; + + return executionResult.exitCode === 0 ? containerappEnvironmentId.split("/").pop() : null; } catch (err) { toolHelper.writeInfo(err.message); return null; From 4faa46488fafdd70f3fbfed2a361df52a3c1c0df Mon Sep 17 00:00:00 2001 From: snehapar9 Date: Mon, 13 Nov 2023 16:38:43 -0800 Subject: [PATCH 4/7] Address PR comments --- azurecontainerapps.ts | 8 ++++---- dist/index.js | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/azurecontainerapps.ts b/azurecontainerapps.ts index bc162511..188300c6 100644 --- a/azurecontainerapps.ts +++ b/azurecontainerapps.ts @@ -236,10 +236,11 @@ export class azurecontainerapps { // If no location was provided, attempt to discover the location of the existing Container App Environment linked to the Container App // or Container App Environment provided in the resource group or use the default location. - let resourceGroup: string = this.toolHelper.getInput('resourceGroup', false); - // Get the resource group if it was provided, or generate it from the Container App name - !this.util.isNullOrEmpty(resourceGroup) ? resourceGroup : `${this.containerAppName}-rg`; + let resourceGroup: string = this.toolHelper.getInput('resourceGroup', false); + if (this.util.isNullOrEmpty(resourceGroup)){ + resourceGroup = `${this.containerAppName}-rg`; + } // Check if Container App exists in the resource group provided and get the location from the Container App Environment linked to it this.containerAppExists = await this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup); @@ -265,7 +266,6 @@ export class azurecontainerapps { return location; } - // Get the default location if the Container App or Container App Environment was not found in the resource group provided. location = await this.appHelper.getDefaultContainerAppLocation(); return location; diff --git a/dist/index.js b/dist/index.js index e140b8ac..f9d17802 100644 --- a/dist/index.js +++ b/dist/index.js @@ -267,8 +267,9 @@ var azurecontainerapps = /** @class */ (function () { return [2 /*return*/, location]; } resourceGroup = this.toolHelper.getInput('resourceGroup', false); - // Get the resource group if it was provided, or generate it from the Container App name - !this.util.isNullOrEmpty(resourceGroup) ? resourceGroup : this.containerAppName + "-rg"; + if (this.util.isNullOrEmpty(resourceGroup)) { + resourceGroup = this.containerAppName + "-rg"; + } // Check if Container App exists in the resource group provided and get the location from the Container App Environment linked to it _a = this; return [4 /*yield*/, this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup)]; From 2d3f30af7aa2f1cb17f14d253e2ee569903ace1a Mon Sep 17 00:00:00 2001 From: snehapar9 Date: Mon, 13 Nov 2023 17:47:20 -0800 Subject: [PATCH 5/7] Revert change to set this.containerrAppExists --- azurecontainerapps.ts | 46 ++++++++++++------------ dist/index.js | 73 ++++++++++++++++++++------------------- src/ContainerAppHelper.ts | 6 ++-- 3 files changed, 66 insertions(+), 59 deletions(-) diff --git a/azurecontainerapps.ts b/azurecontainerapps.ts index 188300c6..c67d6f30 100644 --- a/azurecontainerapps.ts +++ b/azurecontainerapps.ts @@ -201,6 +201,9 @@ export class azurecontainerapps { // Get the resource group to deploy to if it was provided, or generate it from the Container App name this.resourceGroup = await this.getOrCreateResourceGroup(this.containerAppName, this.location); + // Determine if the Container Appp currently exists + this.containerAppExists = await this.appHelper.doesContainerAppExist(this.containerAppName, this.resourceGroup); + // If the Container App doesn't exist, get/create the Container App Environment to use for the Container App if (!this.containerAppExists) { this.containerAppEnvironment = await this.getOrCreateContainerAppEnvironment(this.containerAppName, this.resourceGroup, this.location); @@ -238,32 +241,31 @@ export class azurecontainerapps { // or Container App Environment provided in the resource group or use the default location. // Get the resource group if it was provided, or generate it from the Container App name let resourceGroup: string = this.toolHelper.getInput('resourceGroup', false); - if (this.util.isNullOrEmpty(resourceGroup)){ - resourceGroup = `${this.containerAppName}-rg`; - } - // Check if Container App exists in the resource group provided and get the location from the Container App Environment linked to it - this.containerAppExists = await this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup); - if (this.containerAppExists) { - // Get the name of the Container App Environment linked to the Container App - var environmentName = await this.appHelper.getExistingContainerAppEnvironmentName(this.containerAppName, resourceGroup); - - // Check if environment exists in the resource group provided and get the location - var doesContainerAppEnvironmentExistInResourceGroup = !this.util.isNullOrEmpty(environmentName) ? await this.appHelper.doesContainerAppEnvironmentExist(environmentName, resourceGroup) : false; - if (doesContainerAppEnvironmentExistInResourceGroup) { - // Get the location of the Container App Environment linked to the Container App - location = await this.appHelper.getExistingContainerAppEnvironmentLocation(environmentName, resourceGroup); - return location; + if (!this.util.isNullOrEmpty(resourceGroup)) { + // Check if Container App exists in the resource group provided and get the location from the Container App Environment linked to it + let doesContainerAppExist = await this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup); + if (doesContainerAppExist) { + // Get the name of the Container App Environment linked to the Container App + var environmentName = await this.appHelper.getExistingContainerAppEnvironmentName(this.containerAppName, resourceGroup); + + // Check if environment exists in the resource group provided and get the location + var doesContainerAppEnvironmentExistInResourceGroup = !this.util.isNullOrEmpty(environmentName) ? await this.appHelper.doesContainerAppEnvironmentExist(environmentName, resourceGroup) : false; + if (doesContainerAppEnvironmentExistInResourceGroup) { + // Get the location of the Container App Environment linked to the Container App + location = await this.appHelper.getExistingContainerAppEnvironmentLocation(environmentName, resourceGroup); + return location; + } } - } - let containerAppEnvironment: string = this.toolHelper.getInput('containerAppEnvironment', false); + let containerAppEnvironment: string = this.toolHelper.getInput('containerAppEnvironment', false); - // Check if Container App Environment is provided and exits in the resource group provided and get the location - let doesContainerAppEnvironmentExist = !this.util.isNullOrEmpty(containerAppEnvironment) ? await this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup) : false; - if (doesContainerAppEnvironmentExist) { - location = await this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment, resourceGroup); - return location; + // Check if Container App Environment is provided and exits in the resource group provided and get the location + let doesContainerAppEnvironmentExist = !this.util.isNullOrEmpty(containerAppEnvironment) ? await this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup) : false; + if (doesContainerAppEnvironmentExist) { + location = await this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment, resourceGroup); + return location; + } } // Get the default location if the Container App or Container App Environment was not found in the resource group provided. diff --git a/dist/index.js b/dist/index.js index f9d17802..10256ee9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -210,9 +210,9 @@ var azurecontainerapps = /** @class */ (function () { */ azurecontainerapps.setupResources = function () { return __awaiter(this, void 0, void 0, function () { - var _a, _b, _c; - return __generator(this, function (_d) { - switch (_d.label) { + var _a, _b, _c, _d; + return __generator(this, function (_e) { + switch (_e.label) { case 0: // Get the Container App name if it was provided, or generate it from build variables this.containerAppName = this.getContainerAppName(); @@ -221,20 +221,26 @@ var azurecontainerapps = /** @class */ (function () { return [4 /*yield*/, this.getLocation()]; case 1: // Get the location to deploy resources to, if provided, or use the default location - _a.location = _d.sent(); + _a.location = _e.sent(); // Get the resource group to deploy to if it was provided, or generate it from the Container App name _b = this; return [4 /*yield*/, this.getOrCreateResourceGroup(this.containerAppName, this.location)]; case 2: // Get the resource group to deploy to if it was provided, or generate it from the Container App name - _b.resourceGroup = _d.sent(); - if (!!this.containerAppExists) return [3 /*break*/, 4]; + _b.resourceGroup = _e.sent(); + // Determine if the Container Appp currently exists _c = this; - return [4 /*yield*/, this.getOrCreateContainerAppEnvironment(this.containerAppName, this.resourceGroup, this.location)]; + return [4 /*yield*/, this.appHelper.doesContainerAppExist(this.containerAppName, this.resourceGroup)]; case 3: - _c.containerAppEnvironment = _d.sent(); - _d.label = 4; - case 4: return [2 /*return*/]; + // Determine if the Container Appp currently exists + _c.containerAppExists = _e.sent(); + if (!!this.containerAppExists) return [3 /*break*/, 5]; + _d = this; + return [4 /*yield*/, this.getOrCreateContainerAppEnvironment(this.containerAppName, this.resourceGroup, this.location)]; + case 4: + _d.containerAppEnvironment = _e.sent(); + _e.label = 5; + case 5: return [2 /*return*/]; } }); }); @@ -258,65 +264,60 @@ var azurecontainerapps = /** @class */ (function () { */ azurecontainerapps.getLocation = function () { return __awaiter(this, void 0, void 0, function () { - var location, resourceGroup, _a, environmentName, doesContainerAppEnvironmentExistInResourceGroup, _b, containerAppEnvironment, doesContainerAppEnvironmentExist, _c; - return __generator(this, function (_d) { - switch (_d.label) { + var location, resourceGroup, doesContainerAppExist, environmentName, doesContainerAppEnvironmentExistInResourceGroup, _a, containerAppEnvironment, doesContainerAppEnvironmentExist, _b; + return __generator(this, function (_c) { + switch (_c.label) { case 0: location = this.toolHelper.getInput('location', false); if (!this.util.isNullOrEmpty(location)) { return [2 /*return*/, location]; } resourceGroup = this.toolHelper.getInput('resourceGroup', false); - if (this.util.isNullOrEmpty(resourceGroup)) { - resourceGroup = this.containerAppName + "-rg"; - } - // Check if Container App exists in the resource group provided and get the location from the Container App Environment linked to it - _a = this; + if (!!this.util.isNullOrEmpty(resourceGroup)) return [3 /*break*/, 12]; return [4 /*yield*/, this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup)]; case 1: - // Check if Container App exists in the resource group provided and get the location from the Container App Environment linked to it - _a.containerAppExists = _d.sent(); - if (!this.containerAppExists) return [3 /*break*/, 7]; + doesContainerAppExist = _c.sent(); + if (!doesContainerAppExist) return [3 /*break*/, 7]; return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentName(this.containerAppName, resourceGroup)]; case 2: - environmentName = _d.sent(); + environmentName = _c.sent(); if (!!this.util.isNullOrEmpty(environmentName)) return [3 /*break*/, 4]; return [4 /*yield*/, this.appHelper.doesContainerAppEnvironmentExist(environmentName, resourceGroup)]; case 3: - _b = _d.sent(); + _a = _c.sent(); return [3 /*break*/, 5]; case 4: - _b = false; - _d.label = 5; + _a = false; + _c.label = 5; case 5: - doesContainerAppEnvironmentExistInResourceGroup = _b; + doesContainerAppEnvironmentExistInResourceGroup = _a; if (!doesContainerAppEnvironmentExistInResourceGroup) return [3 /*break*/, 7]; return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentLocation(environmentName, resourceGroup)]; case 6: // Get the location of the Container App Environment linked to the Container App - location = _d.sent(); + location = _c.sent(); return [2 /*return*/, location]; case 7: containerAppEnvironment = this.toolHelper.getInput('containerAppEnvironment', false); if (!!this.util.isNullOrEmpty(containerAppEnvironment)) return [3 /*break*/, 9]; return [4 /*yield*/, this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup)]; case 8: - _c = _d.sent(); + _b = _c.sent(); return [3 /*break*/, 10]; case 9: - _c = false; - _d.label = 10; + _b = false; + _c.label = 10; case 10: - doesContainerAppEnvironmentExist = _c; + doesContainerAppEnvironmentExist = _b; if (!doesContainerAppEnvironmentExist) return [3 /*break*/, 12]; return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment, resourceGroup)]; case 11: - location = _d.sent(); + location = _c.sent(); return [2 /*return*/, location]; case 12: return [4 /*yield*/, this.appHelper.getDefaultContainerAppLocation()]; case 13: // Get the default location if the Container App or Container App Environment was not found in the resource group provided. - location = _d.sent(); + location = _c.sent(); return [2 /*return*/, location]; } }); @@ -5177,8 +5178,10 @@ var ContainerAppHelper = /** @class */ (function () { executionResult = _a.sent(); containerappEnvironmentId = executionResult.stdout.trim(); //Remove trailing slash if it exists - containerappEnvironmentId = containerappEnvironmentId.endsWith("/") ? containerappEnvironmentId.slice(0, -1) : containerappEnvironmentId; - return [2 /*return*/, executionResult.exitCode === 0 ? containerappEnvironmentId.split("/").pop() : null]; + if (!util.isNullOrEmpty(containerappEnvironmentId)) { + containerappEnvironmentId = containerappEnvironmentId.endsWith("/") ? containerappEnvironmentId.slice(0, -1) : containerappEnvironmentId; + } + return [2 /*return*/, executionResult.exitCode === 0 ? containerappEnvironmentId.split("/").pop().trim() : null]; case 2: err_14 = _a.sent(); toolHelper.writeInfo(err_14.message); diff --git a/src/ContainerAppHelper.ts b/src/ContainerAppHelper.ts index ba2d61bf..5894398a 100644 --- a/src/ContainerAppHelper.ts +++ b/src/ContainerAppHelper.ts @@ -298,9 +298,11 @@ export class ContainerAppHelper { let containerappEnvironmentId = executionResult.stdout.trim(); //Remove trailing slash if it exists - containerappEnvironmentId = containerappEnvironmentId.endsWith("/") ? containerappEnvironmentId.slice(0, -1) : containerappEnvironmentId; + if (!util.isNullOrEmpty(containerappEnvironmentId)) { + containerappEnvironmentId = containerappEnvironmentId.endsWith("/") ? containerappEnvironmentId.slice(0, -1) : containerappEnvironmentId; + } - return executionResult.exitCode === 0 ? containerappEnvironmentId.split("/").pop() : null; + return executionResult.exitCode === 0 ? containerappEnvironmentId.split("/").pop().trim() : null; } catch (err) { toolHelper.writeInfo(err.message); return null; From d2d7d4ab6d2134b6b12c8f11dca5e6bfe5c40b94 Mon Sep 17 00:00:00 2001 From: snehapar9 Date: Mon, 13 Nov 2023 18:47:52 -0800 Subject: [PATCH 6/7] Refactor --- azurecontainerapps.ts | 15 +++++++-------- dist/index.js | 14 +++++++------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/azurecontainerapps.ts b/azurecontainerapps.ts index c67d6f30..16e51ff1 100644 --- a/azurecontainerapps.ts +++ b/azurecontainerapps.ts @@ -232,26 +232,25 @@ export class azurecontainerapps { private static async getLocation(): Promise { // Set deployment location, if provided let location: string = this.toolHelper.getInput('location', false); - if (!this.util.isNullOrEmpty(location)) { return location; } // If no location was provided, attempt to discover the location of the existing Container App Environment linked to the Container App // or Container App Environment provided in the resource group or use the default location. - // Get the resource group if it was provided, or generate it from the Container App name + // Get the resource group if it was provided let resourceGroup: string = this.toolHelper.getInput('resourceGroup', false); if (!this.util.isNullOrEmpty(resourceGroup)) { // Check if Container App exists in the resource group provided and get the location from the Container App Environment linked to it - let doesContainerAppExist = await this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup); - if (doesContainerAppExist) { + let containerAppExists = await this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup); + if (containerAppExists) { // Get the name of the Container App Environment linked to the Container App var environmentName = await this.appHelper.getExistingContainerAppEnvironmentName(this.containerAppName, resourceGroup); // Check if environment exists in the resource group provided and get the location - var doesContainerAppEnvironmentExistInResourceGroup = !this.util.isNullOrEmpty(environmentName) ? await this.appHelper.doesContainerAppEnvironmentExist(environmentName, resourceGroup) : false; - if (doesContainerAppEnvironmentExistInResourceGroup) { + var containerAppEnvironmentExistsInResourceGroup = !this.util.isNullOrEmpty(environmentName) ? await this.appHelper.doesContainerAppEnvironmentExist(environmentName, resourceGroup) : false; + if (containerAppEnvironmentExistsInResourceGroup) { // Get the location of the Container App Environment linked to the Container App location = await this.appHelper.getExistingContainerAppEnvironmentLocation(environmentName, resourceGroup); return location; @@ -261,8 +260,8 @@ export class azurecontainerapps { let containerAppEnvironment: string = this.toolHelper.getInput('containerAppEnvironment', false); // Check if Container App Environment is provided and exits in the resource group provided and get the location - let doesContainerAppEnvironmentExist = !this.util.isNullOrEmpty(containerAppEnvironment) ? await this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup) : false; - if (doesContainerAppEnvironmentExist) { + let containerAppEnvironmentExists = !this.util.isNullOrEmpty(containerAppEnvironment) ? await this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup) : false; + if (containerAppEnvironmentExists) { location = await this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment, resourceGroup); return location; } diff --git a/dist/index.js b/dist/index.js index 10256ee9..76714ce3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -264,7 +264,7 @@ var azurecontainerapps = /** @class */ (function () { */ azurecontainerapps.getLocation = function () { return __awaiter(this, void 0, void 0, function () { - var location, resourceGroup, doesContainerAppExist, environmentName, doesContainerAppEnvironmentExistInResourceGroup, _a, containerAppEnvironment, doesContainerAppEnvironmentExist, _b; + var location, resourceGroup, containerAppExists, environmentName, containerAppEnvironmentExistsInResourceGroup, _a, containerAppEnvironment, containerAppEnvironmentExists, _b; return __generator(this, function (_c) { switch (_c.label) { case 0: @@ -276,8 +276,8 @@ var azurecontainerapps = /** @class */ (function () { if (!!this.util.isNullOrEmpty(resourceGroup)) return [3 /*break*/, 12]; return [4 /*yield*/, this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup)]; case 1: - doesContainerAppExist = _c.sent(); - if (!doesContainerAppExist) return [3 /*break*/, 7]; + containerAppExists = _c.sent(); + if (!containerAppExists) return [3 /*break*/, 7]; return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentName(this.containerAppName, resourceGroup)]; case 2: environmentName = _c.sent(); @@ -290,8 +290,8 @@ var azurecontainerapps = /** @class */ (function () { _a = false; _c.label = 5; case 5: - doesContainerAppEnvironmentExistInResourceGroup = _a; - if (!doesContainerAppEnvironmentExistInResourceGroup) return [3 /*break*/, 7]; + containerAppEnvironmentExistsInResourceGroup = _a; + if (!containerAppEnvironmentExistsInResourceGroup) return [3 /*break*/, 7]; return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentLocation(environmentName, resourceGroup)]; case 6: // Get the location of the Container App Environment linked to the Container App @@ -308,8 +308,8 @@ var azurecontainerapps = /** @class */ (function () { _b = false; _c.label = 10; case 10: - doesContainerAppEnvironmentExist = _b; - if (!doesContainerAppEnvironmentExist) return [3 /*break*/, 12]; + containerAppEnvironmentExists = _b; + if (!containerAppEnvironmentExists) return [3 /*break*/, 12]; return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment, resourceGroup)]; case 11: location = _c.sent(); From 0a40db555451461102a856f88d95fa3cb7162bb1 Mon Sep 17 00:00:00 2001 From: snehapar9 Date: Mon, 13 Nov 2023 18:51:50 -0800 Subject: [PATCH 7/7] Add comment --- azurecontainerapps.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/azurecontainerapps.ts b/azurecontainerapps.ts index 16e51ff1..df74d0a1 100644 --- a/azurecontainerapps.ts +++ b/azurecontainerapps.ts @@ -257,6 +257,7 @@ export class azurecontainerapps { } } + // Get the Container App Environment name if it was provided let containerAppEnvironment: string = this.toolHelper.getInput('containerAppEnvironment', false); // Check if Container App Environment is provided and exits in the resource group provided and get the location