diff --git a/azurecontainerapps.ts b/azurecontainerapps.ts index 08cc4bf..e0af165 100644 --- a/azurecontainerapps.ts +++ b/azurecontainerapps.ts @@ -201,7 +201,7 @@ 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 + // 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 @@ -232,40 +232,43 @@ 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; } // 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 + 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; } } + // 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 - 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; } } - // 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 f6a3064..16816be 100644 --- a/dist/index.js +++ b/dist/index.js @@ -220,11 +220,11 @@ var azurecontainerapps = /** @class */ (function () { 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 + // Determine if the Container Appp currently exists _c = this; return [4 /*yield*/, this.appHelper.doesContainerAppExist(this.containerAppName, this.resourceGroup)]; case 3: - // Determine if the Container App currently exists + // Determine if the Container Appp currently exists _c.containerAppExists = _e.sent(); if (!!this.containerAppExists) return [3 /*break*/, 5]; _d = this; @@ -256,21 +256,20 @@ 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; + var location, resourceGroup, containerAppExists, environmentName, containerAppEnvironmentExistsInResourceGroup, _a, containerAppEnvironment, containerAppEnvironmentExists, _b; return __generator(this, function (_c) { switch (_c.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]; } + resourceGroup = this.toolHelper.getInput('resourceGroup', false); 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(); @@ -283,14 +282,15 @@ 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 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: @@ -300,15 +300,15 @@ 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(); 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]; } @@ -5153,13 +5153,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: @@ -5168,7 +5168,12 @@ 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 + 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 82c4134..f56c43e 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,14 @@ 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 + if (!util.isNullOrEmpty(containerappEnvironmentId)) { + containerappEnvironmentId = containerappEnvironmentId.endsWith("/") ? containerappEnvironmentId.slice(0, -1) : containerappEnvironmentId; + } + + return executionResult.exitCode === 0 ? containerappEnvironmentId.split("/").pop().trim() : null; } catch (err) { toolHelper.writeInfo(err.message); return null;