From b7705b3eca983aacedf783a6f617e703d4157da4 Mon Sep 17 00:00:00 2001 From: snehapar9 Date: Tue, 19 Sep 2023 16:23:14 -0700 Subject: [PATCH] Delete unnecessary files --- index.ts => azurecontainerapps.ts | 0 dist/index.js | 166 +++---- index.js | 631 -------------------------- src/CommandHelper.js | 168 ------- src/ContainerAppHelper.js | 725 ------------------------------ src/ContainerAppHelper.ts | 57 +-- src/ContainerRegistryHelper.js | 139 ------ src/Strings/en-Us/resources.json | 85 ---- src/TelemetryHelper.js | 155 ------- src/Utility.js | 117 ----- 10 files changed, 76 insertions(+), 2167 deletions(-) rename index.ts => azurecontainerapps.ts (100%) delete mode 100644 index.js delete mode 100644 src/CommandHelper.js delete mode 100644 src/ContainerAppHelper.js delete mode 100644 src/ContainerRegistryHelper.js delete mode 100644 src/Strings/en-Us/resources.json delete mode 100644 src/TelemetryHelper.js delete mode 100644 src/Utility.js diff --git a/index.ts b/azurecontainerapps.ts similarity index 100% rename from index.ts rename to azurecontainerapps.ts diff --git a/dist/index.js b/dist/index.js index 5e9317d0..6c495437 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,7 +1,7 @@ /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ -/***/ 5506: +/***/ 3238: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; @@ -4902,28 +4902,24 @@ var ContainerAppHelper = /** @class */ (function () { */ ContainerAppHelper.prototype.updateContainerApp = function (containerAppName, resourceGroup, imageToDeploy, optionalCmdArgs) { return __awaiter(this, void 0, void 0, function () { - var command_2, _a, stdout, stderr, err_3; - return __generator(this, function (_b) { - switch (_b.label) { + var command_2, err_3; + return __generator(this, function (_a) { + switch (_a.label) { case 0: core.debug("Attempting to update Container App with name \"" + containerAppName + "\" in resource group \"" + resourceGroup + "\" based from image \"" + imageToDeploy + "\""); - _b.label = 1; + _a.label = 1; case 1: - _b.trys.push([1, 3, , 4]); + _a.trys.push([1, 3, , 4]); command_2 = "az containerapp update -n " + containerAppName + " -g " + resourceGroup + " -i " + imageToDeploy; optionalCmdArgs.forEach(function (val) { command_2 += " " + val; }); return [4 /*yield*/, cpExec("" + command_2)]; case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.warning(stderr); - throw new Error(stderr); - } + _a.sent(); return [3 /*break*/, 4]; case 3: - err_3 = _b.sent(); + err_3 = _a.sent(); core.error(err_3.message); throw err_3; case 4: return [2 /*return*/]; @@ -4942,15 +4938,15 @@ var ContainerAppHelper = /** @class */ (function () { */ ContainerAppHelper.prototype.updateContainerAppWithUp = function (containerAppName, resourceGroup, imageToDeploy, optionalCmdArgs, ingress, targetPort) { return __awaiter(this, void 0, void 0, function () { - var util, command_3, _a, stdout, stderr, err_4; - return __generator(this, function (_b) { - switch (_b.label) { + var util, command_3, err_4; + return __generator(this, function (_a) { + switch (_a.label) { case 0: core.debug("Attempting to update Container App with name \"" + containerAppName + "\" in resource group \"" + resourceGroup + "\" based from image \"" + imageToDeploy + "\""); util = new Utility_1.Utility(); - _b.label = 1; + _a.label = 1; case 1: - _b.trys.push([1, 3, , 4]); + _a.trys.push([1, 3, , 4]); command_3 = "az containerapp up -n " + containerAppName + " -g " + resourceGroup + " -i " + imageToDeploy; optionalCmdArgs.forEach(function (val) { command_3 += " " + val; @@ -4963,14 +4959,10 @@ var ContainerAppHelper = /** @class */ (function () { } return [4 /*yield*/, cpExec("" + command_3)]; case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.warning(stderr); - throw new Error(stderr); - } + _a.sent(); return [3 /*break*/, 4]; case 3: - err_4 = _b.sent(); + err_4 = _a.sent(); core.error(err_4.message); throw err_4; case 4: return [2 /*return*/]; @@ -4986,25 +4978,21 @@ var ContainerAppHelper = /** @class */ (function () { */ ContainerAppHelper.prototype.updateContainerAppFromYaml = function (containerAppName, resourceGroup, yamlConfigPath) { return __awaiter(this, void 0, void 0, function () { - var command, _a, stdout, stderr, err_5; - return __generator(this, function (_b) { - switch (_b.label) { + var command, err_5; + return __generator(this, function (_a) { + switch (_a.label) { case 0: core.debug("Attempting to update Container App with name \"" + containerAppName + "\" in resource group \"" + resourceGroup + "\" from provided YAML \"" + yamlConfigPath + "\""); - _b.label = 1; + _a.label = 1; case 1: - _b.trys.push([1, 3, , 4]); + _a.trys.push([1, 3, , 4]); command = "az containerapp update -n " + containerAppName + " -g " + resourceGroup + " --yaml " + yamlConfigPath; return [4 /*yield*/, cpExec("" + command)]; case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.warning(stderr); - throw new Error(stderr); - } + _a.sent(); return [3 /*break*/, 4]; case 3: - err_5 = _b.sent(); + err_5 = _a.sent(); core.error(err_5.message); throw err_5; case 4: return [2 /*return*/]; @@ -5137,25 +5125,21 @@ var ContainerAppHelper = /** @class */ (function () { */ ContainerAppHelper.prototype.createResourceGroup = function (name, location) { return __awaiter(this, void 0, void 0, function () { - var command, _a, stdout, stderr, err_10; - return __generator(this, function (_b) { - switch (_b.label) { + var command, err_10; + return __generator(this, function (_a) { + switch (_a.label) { case 0: core.debug("Attempting to create resource group \"" + name + "\" in location \"" + location + "\""); - _b.label = 1; + _a.label = 1; case 1: - _b.trys.push([1, 3, , 4]); + _a.trys.push([1, 3, , 4]); command = "az group create -n " + name + " -l " + location; return [4 /*yield*/, cpExec("" + command)]; case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.error('Failed to create resource group, Error: ' + stderr); - throw new Error(stderr); - } + _a.sent(); return [3 /*break*/, 4]; case 3: - err_10 = _b.sent(); + err_10 = _a.sent(); core.error(err_10.message); throw err_10; case 4: return [2 /*return*/]; @@ -5200,29 +5184,25 @@ var ContainerAppHelper = /** @class */ (function () { */ ContainerAppHelper.prototype.createContainerAppEnvironment = function (name, resourceGroup, location) { return __awaiter(this, void 0, void 0, function () { - var util, command, _a, stdout, stderr, err_12; - return __generator(this, function (_b) { - switch (_b.label) { + var util, command, err_12; + return __generator(this, function (_a) { + switch (_a.label) { case 0: util = new Utility_1.Utility(); core.debug("Attempting to create Container App Environment with name \"" + name + "\" in resource group \"" + resourceGroup + "\""); - _b.label = 1; + _a.label = 1; case 1: - _b.trys.push([1, 3, , 4]); + _a.trys.push([1, 3, , 4]); command = "az containerapp env create -n " + name + " -g " + resourceGroup; if (!util.isNullOrEmpty(location)) { command += " -l " + location; } return [4 /*yield*/, cpExec("" + command)]; case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.error('Failed to create Container App Environment, Error: ' + stderr); - throw new Error(stderr); - } + _a.sent(); return [3 /*break*/, 4]; case 3: - err_12 = _b.sent(); + err_12 = _a.sent(); core.error(err_12.message); throw err_12; case 4: return [2 /*return*/]; @@ -5237,25 +5217,21 @@ var ContainerAppHelper = /** @class */ (function () { */ ContainerAppHelper.prototype.disableContainerAppIngress = function (name, resourceGroup) { return __awaiter(this, void 0, void 0, function () { - var command, _a, stdout, stderr, err_13; - return __generator(this, function (_b) { - switch (_b.label) { + var command, err_13; + return __generator(this, function (_a) { + switch (_a.label) { case 0: core.debug("Attempting to disable ingress for Container App with name \"" + name + "\" in resource group \"" + resourceGroup + "\""); - _b.label = 1; + _a.label = 1; case 1: - _b.trys.push([1, 3, , 4]); + _a.trys.push([1, 3, , 4]); command = "az containerapp ingress disable -n " + name + " -g " + resourceGroup; return [4 /*yield*/, cpExec("" + command)]; case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.warning('Failed to disable ingress for Container App, Error: ' + stderr); - throw new Error(stderr); - } + _a.sent(); return [3 /*break*/, 4]; case 3: - err_13 = _b.sent(); + err_13 = _a.sent(); core.error(err_13.message); throw err_13; case 4: return [2 /*return*/]; @@ -5273,25 +5249,21 @@ var ContainerAppHelper = /** @class */ (function () { */ ContainerAppHelper.prototype.updateContainerAppRegistryDetails = function (name, resourceGroup, acrName, acrUsername, acrPassword) { return __awaiter(this, void 0, void 0, function () { - var command, _a, stdout, stderr, err_14; - return __generator(this, function (_b) { - switch (_b.label) { + var command, err_14; + return __generator(this, function (_a) { + switch (_a.label) { case 0: core.debug("Attempting to set the ACR details for Container App with name \"" + name + "\" in resource group \"" + resourceGroup + "\""); - _b.label = 1; + _a.label = 1; case 1: - _b.trys.push([1, 3, , 4]); + _a.trys.push([1, 3, , 4]); command = "az containerapp registry set -n " + name + " -g " + resourceGroup + " --server " + acrName + ".azurecr.io --username " + acrUsername + " --password " + acrPassword; return [4 /*yield*/, cpExec("" + command)]; case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.warning('Failed to set the ACR details for Container App, Error: ' + stderr); - throw new Error(stderr); - } + _a.sent(); return [3 /*break*/, 4]; case 3: - err_14 = _b.sent(); + err_14 = _a.sent(); core.error(err_14.message); throw err_14; case 4: return [2 /*return*/]; @@ -5307,28 +5279,24 @@ var ContainerAppHelper = /** @class */ (function () { */ ContainerAppHelper.prototype.createRunnableAppImage = function (imageToDeploy, appSourcePath, runtimeStack) { return __awaiter(this, void 0, void 0, function () { - var telemetryArg, _a, stdout, stderr, err_15; - return __generator(this, function (_b) { - switch (_b.label) { + var telemetryArg, err_15; + return __generator(this, function (_a) { + switch (_a.label) { case 0: core.debug("Attempting to create a runnable application image using the Oryx++ Builder with image name \"" + imageToDeploy + "\""); - _b.label = 1; + _a.label = 1; case 1: - _b.trys.push([1, 3, , 4]); + _a.trys.push([1, 3, , 4]); telemetryArg = "--env \"CALLER_ID=azure-pipelines-rc-v1\""; if (this.disableTelemetry) { telemetryArg = "--env \"ORYX_DISABLE_TELEMETRY=true\""; } return [4 /*yield*/, cpExec(PACK_CMD + " build " + imageToDeploy + " --path " + appSourcePath + " --builder " + ORYX_BUILDER_IMAGE + " --run-image mcr.microsoft.com/oryx/" + runtimeStack + " " + telemetryArg)]; case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.error("Failed to create runnable application image using the Oryx++ Builder with image name \"" + imageToDeploy + "\". Error: " + stderr); - throw new Error(stderr); - } + _a.sent(); return [3 /*break*/, 4]; case 3: - err_15 = _b.sent(); + err_15 = _a.sent(); core.error(err_15.message); throw err_15; case 4: return [2 /*return*/]; @@ -5427,24 +5395,20 @@ var ContainerAppHelper = /** @class */ (function () { */ ContainerAppHelper.prototype.setDefaultBuilder = function () { return __awaiter(this, void 0, void 0, function () { - var _a, stdout, stderr, err_18; - return __generator(this, function (_b) { - switch (_b.label) { + var err_18; + return __generator(this, function (_a) { + switch (_a.label) { case 0: core.info('Setting the Oryx++ Builder as the default builder via the pack CLI'); - _b.label = 1; + _a.label = 1; case 1: - _b.trys.push([1, 3, , 4]); + _a.trys.push([1, 3, , 4]); return [4 /*yield*/, cpExec("pack config default-builder " + ORYX_BUILDER_IMAGE)]; case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.error("Failed to set the Oryx++ Builder as the default builder via the pack CLI. Error: " + stderr); - throw new Error(stderr); - } + _a.sent(); return [3 /*break*/, 4]; case 3: - err_18 = _b.sent(); + err_18 = _a.sent(); core.setFailed(err_18.message); throw err_18; case 4: return [2 /*return*/]; @@ -6090,7 +6054,7 @@ module.exports = require("util"); /******/ // startup /******/ // Load entry module and return exports /******/ // This entry module is referenced by other modules so it can't be inlined -/******/ var __webpack_exports__ = __nccwpck_require__(5506); +/******/ var __webpack_exports__ = __nccwpck_require__(3238); /******/ module.exports = __webpack_exports__; /******/ /******/ })() diff --git a/index.js b/index.js deleted file mode 100644 index 6c20f819..00000000 --- a/index.js +++ /dev/null @@ -1,631 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -exports.__esModule = true; -exports.azurecontainerapps = void 0; -var core = require("@actions/core"); -var fs = require("fs"); -var path = require("path"); -var ContainerAppHelper_1 = require("./src/ContainerAppHelper"); -var ContainerRegistryHelper_1 = require("./src/ContainerRegistryHelper"); -var TelemetryHelper_1 = require("./src/TelemetryHelper"); -var Utility_1 = require("./src/Utility"); -var util = new Utility_1.Utility(); -var azurecontainerapps = /** @class */ (function () { - function azurecontainerapps() { - } - azurecontainerapps.runMain = function () { - return __awaiter(this, void 0, void 0, function () { - var disableTelemetry, err_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - disableTelemetry = core.getInput('disableTelemetry').toLowerCase() === 'true'; - this.initializeHelpers(disableTelemetry); - _a.label = 1; - case 1: - _a.trys.push([1, 8, 9, 11]); - // Validate that the arguments provided can be used for one of the supported scenarios - this.validateSupportedScenarioArguments(); - // Set up the Azure CLI to be used for this task - this.setupAzureCli(); - // Set up the resources required to deploy a Container App - return [4 /*yield*/, this.setupResources()]; - case 2: - // Set up the resources required to deploy a Container App - _a.sent(); - if (!!util.isNullOrEmpty(this.acrName)) return [3 /*break*/, 4]; - return [4 /*yield*/, this.authenticateAzureContainerRegistryAsync()]; - case 3: - _a.sent(); - _a.label = 4; - case 4: - if (!!util.isNullOrEmpty(this.appSourcePath)) return [3 /*break*/, 6]; - return [4 /*yield*/, this.buildAndPushImageAsync()]; - case 5: - _a.sent(); - _a.label = 6; - case 6: - // If no application source was provided, set up the scenario for deploying an existing image - if (util.isNullOrEmpty(this.appSourcePath)) { - this.setupExistingImageScenario(); - } - // If no YAML configuration file was provided, set up the Container App properties - if (util.isNullOrEmpty(this.yamlConfigPath)) { - this.setupContainerAppProperties(); - } - // Create/update the Container App - return [4 /*yield*/, this.createOrUpdateContainerApp()]; - case 7: - // Create/update the Container App - _a.sent(); - // If telemetry is enabled, log that the task completed successfully - this.telemetryHelper.setSuccessfulResult(); - return [3 /*break*/, 11]; - case 8: - err_1 = _a.sent(); - core.setFailed(err_1.message); - this.telemetryHelper.setFailedResult(err_1.message); - return [3 /*break*/, 11]; - case 9: - // Logout of Azure if logged in during this task session - // this.authHelper.logoutAzure(); - // If telemetry is enabled, will log metadata for this task run - return [4 /*yield*/, this.telemetryHelper.sendLogs()]; - case 10: - // Logout of Azure if logged in during this task session - // this.authHelper.logoutAzure(); - // If telemetry is enabled, will log metadata for this task run - _a.sent(); - return [7 /*endfinally*/]; - case 11: return [2 /*return*/]; - } - }); - }); - }; - /** - * Initializes the helpers used by this task. - * @param disableTelemetry - Whether or not to disable telemetry for this task. - */ - azurecontainerapps.initializeHelpers = function (disableTelemetry) { - // Set up TelemetryHelper for managing telemetry calls - this.telemetryHelper = new TelemetryHelper_1.TelemetryHelper(disableTelemetry); - // Set up AzureAuthenticationHelper for managing logging in and out of Azure CLI using provided service connection - // this.authHelper = new AzureAuthenticationHelper(); - // Set up ContainerAppHelper for managing calls around the Container App - this.appHelper = new ContainerAppHelper_1.ContainerAppHelper(disableTelemetry); - // Set up ContainerRegistryHelper for managing calls around ACR - this.registryHelper = new ContainerRegistryHelper_1.ContainerRegistryHelper(); - }; - /** - * Validates the arguments provided to the task for supported scenarios. - * @throws Error if a valid combination of the support scenario arguments is not provided. - */ - azurecontainerapps.validateSupportedScenarioArguments = function () { - // Get the path to the application source to build and run, if provided - this.appSourcePath = core.getInput('appSourcePath', { required: false }); - // Get the name of the ACR instance to push images to, if provided - this.acrName = core.getInput('acrName', { required: false }); - // Get the previously built image to deploy, if provided - this.imageToDeploy = core.getInput('imageToDeploy', { required: false }); - // Get the YAML configuration file, if provided - this.yamlConfigPath = core.getInput('yamlConfigPath', { required: false }); - // Ensure that acrName is also provided if appSourcePath is provided - if (!util.isNullOrEmpty(this.appSourcePath) && util.isNullOrEmpty(this.acrName)) { - core.error("The 'acrName' argument must be provided when the 'appSourcePath' argument is provided."); - throw Error("The 'acrName' argument must be provided when the 'appSourcePath' argument is provided."); - } - // Ensure that one of appSourcePath, imageToDeploy, or yamlConfigPath is provided - if (util.isNullOrEmpty(this.appSourcePath) && util.isNullOrEmpty(this.imageToDeploy) && util.isNullOrEmpty(this.yamlConfigPath)) { - core.error("One of the following arguments must be provided: 'appSourcePath', 'imageToDeploy', or 'yamlConfigPath'."); - } - }; - /** - * Sets up the Azure CLI to be used for this task by logging in to Azure with the provided service connection and - * setting the Azure CLI to dynamically install missing extensions. - */ - azurecontainerapps.setupAzureCli = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - // Set the Azure CLI to dynamically install missing extensions - return [4 /*yield*/, util.setAzureCliDynamicInstall()]; - case 1: - // Set the Azure CLI to dynamically install missing extensions - _a.sent(); - return [2 /*return*/]; - } - }); - }); - }; - /** - * Sets up the resources required to deploy a Container App. This includes the following: - * - Getting or generating the Container App name - * - Getting or discovering the location to deploy resources to - * - Getting or creating the resource group - * - Getting or creating the Container App Environment - */ - azurecontainerapps.setupResources = function () { - return __awaiter(this, void 0, void 0, function () { - 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(); - // Get the location to deploy resources to, if provided, or use the default location - _a = this; - 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(); - // 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 - _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*/]; - } - }); - }); - }; - /** - * Gets the name of the Container App to use for the task. If the 'containerAppName' argument is not provided, - * then a default name will be generated in the form 'ado-task-app--'. - * @returns The name of the Container App to use for the task. - */ - azurecontainerapps.getContainerAppName = function () { - var containerAppName = core.getInput('containerAppName', { required: false }); - if (util.isNullOrEmpty(containerAppName)) { - containerAppName = "app-" + this.buildId + "-" + this.buildNumber; - // Replace all '.' characters with '-' characters in the Container App name - containerAppName = containerAppName.replace(/\./gi, "-"); - core.info("Default Container App name: " + containerAppName); - } - return containerAppName; - }; - /** - * Gets the location to deploy resources to. If the 'location' argument is not provided, then the default location - * for the Container App service will be used. - * @returns The location to deploy resources to. - */ - azurecontainerapps.getLocation = function () { - return __awaiter(this, void 0, void 0, function () { - var location; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - location = core.getInput('location', { required: false }); - if (!util.isNullOrEmpty(location)) return [3 /*break*/, 2]; - return [4 /*yield*/, this.appHelper.getDefaultContainerAppLocation()]; - case 1: - location = _a.sent(); - _a.label = 2; - case 2: return [2 /*return*/, location]; - } - }); - }); - }; - /** - * Gets the name of the resource group to use for the task. If the 'resourceGroup' argument is not provided, - * then a default name will be generated in the form '-rg'. If the generated resource group does - * not exist, it will be created. - * @param containerAppName - The name of the Container App to use for the task. - * @param location - The location to deploy resources to. - * @returns The name of the resource group to use for the task. - */ - azurecontainerapps.getOrCreateResourceGroup = function (containerAppName, location) { - return __awaiter(this, void 0, void 0, function () { - var resourceGroup, resourceGroupExists; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - resourceGroup = core.getInput('resourceGroup', { required: false }); - if (!util.isNullOrEmpty(resourceGroup)) return [3 /*break*/, 3]; - resourceGroup = containerAppName + "-rg"; - core.info("Default resource group name: " + resourceGroup); - return [4 /*yield*/, this.appHelper.doesResourceGroupExist(resourceGroup)]; - case 1: - resourceGroupExists = _a.sent(); - if (!!resourceGroupExists) return [3 /*break*/, 3]; - return [4 /*yield*/, this.appHelper.createResourceGroup(resourceGroup, location)]; - case 2: - _a.sent(); - _a.label = 3; - case 3: return [2 /*return*/, resourceGroup]; - } - }); - }); - }; - /** - * Gets the name of the Container App Environment to use for the task. If the 'containerAppEnvironment' argument - * is not provided, then the task will attempt to discover an existing Container App Environment in the resource - * group. If no existing Container App Environment is found, then a default name will be generated in the form - * '-env'. If the Container App Environment does not exist, it will be created. - * @param containerAppName - The name of the Container App to use for the task. - * @param resourceGroup - The name of the resource group to use for the task. - * @param location - The location to deploy resources to. - * @returns The name of the Container App Environment to use for the task. - */ - azurecontainerapps.getOrCreateContainerAppEnvironment = function (containerAppName, resourceGroup, location) { - return __awaiter(this, void 0, void 0, function () { - var containerAppEnvironment, existingContainerAppEnvironment, containerAppEnvironmentExists; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - containerAppEnvironment = core.getInput('containerAppEnvironment', { required: false }); - if (!util.isNullOrEmpty(containerAppEnvironment)) return [3 /*break*/, 2]; - return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironment(resourceGroup)]; - case 1: - existingContainerAppEnvironment = _a.sent(); - if (!util.isNullOrEmpty(existingContainerAppEnvironment)) { - core.info("Existing Container App environment found in resource group: " + existingContainerAppEnvironment); - return [2 /*return*/, existingContainerAppEnvironment]; - } - _a.label = 2; - case 2: - // Generate the Container App environment name if it was not provided - if (util.isNullOrEmpty(containerAppEnvironment)) { - containerAppEnvironment = containerAppName + "-env"; - core.info("Default Container App environment name: " + containerAppEnvironment); - } - return [4 /*yield*/, this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup)]; - case 3: - containerAppEnvironmentExists = _a.sent(); - if (!!containerAppEnvironmentExists) return [3 /*break*/, 5]; - return [4 /*yield*/, this.appHelper.createContainerAppEnvironment(containerAppEnvironment, resourceGroup, location)]; - case 4: - _a.sent(); - _a.label = 5; - case 5: return [2 /*return*/, containerAppEnvironment]; - } - }); - }); - }; - /** - * Authenticates calls to the provided Azure Container Registry. - */ - azurecontainerapps.authenticateAzureContainerRegistryAsync = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.acrUsername = core.getInput('acrUsername', { required: false }); - this.acrPassword = core.getInput('acrPassword', { required: false }); - if (!(!util.isNullOrEmpty(this.acrUsername) && !util.isNullOrEmpty(this.acrPassword))) return [3 /*break*/, 2]; - core.info("Logging in to ACR instance \"" + this.acrName + "\" with username and password credentials"); - return [4 /*yield*/, this.registryHelper.loginAcrWithUsernamePassword(this.acrName, this.acrUsername, this.acrPassword)]; - case 1: - _a.sent(); - return [3 /*break*/, 4]; - case 2: - core.info("No ACR credentials provided; attempting to log in to ACR instance \"" + this.acrName + "\" with access token"); - return [4 /*yield*/, this.registryHelper.loginAcrWithAccessTokenAsync(this.acrName)]; - case 3: - _a.sent(); - _a.label = 4; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Sets up the scenario where an existing image is used for the Container App. - */ - azurecontainerapps.setupExistingImageScenario = function () { - // If telemetry is enabled, log that the previously built image scenario was targeted for this task - this.telemetryHelper.setImageScenario(); - }; - /** - * Builds a runnable application image using a Dockerfile or the builder and pushes it to ACR. - */ - azurecontainerapps.buildAndPushImageAsync = function () { - return __awaiter(this, void 0, void 0, function () { - var dockerfilePath, rootDockerfilePath; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - // Get the name of the image to build if it was provided, or generate it from build variables - this.imageToBuild = core.getInput('imageToBuild', { required: false }); - if (util.isNullOrEmpty(this.imageToBuild)) { - this.imageToBuild = this.acrName + ".azurecr.io/ado-task/container-app:" + this.buildId + "." + this.buildNumber; - core.info("Default image to build: " + this.imageToBuild); - } - // Get the name of the image to deploy if it was provided, or set it to the value of 'imageToBuild' - if (util.isNullOrEmpty(this.imageToDeploy)) { - this.imageToDeploy = this.imageToBuild; - core.info("Default image to deploy: " + this.imageToDeploy); - } - dockerfilePath = core.getInput('dockerfilePath', { required: false }); - if (!util.isNullOrEmpty(dockerfilePath)) return [3 /*break*/, 4]; - core.info("No Dockerfile path provided; checking for Dockerfile at root of application source."); - rootDockerfilePath = path.join(this.appSourcePath, 'Dockerfile'); - if (!fs.existsSync(rootDockerfilePath)) return [3 /*break*/, 1]; - core.info("Dockerfile found at root of application source."); - dockerfilePath = rootDockerfilePath; - return [3 /*break*/, 3]; - case 1: - // No Dockerfile found or provided, build the image using the builder - return [4 /*yield*/, this.buildImageFromBuilderAsync(this.appSourcePath, this.imageToBuild)]; - case 2: - // No Dockerfile found or provided, build the image using the builder - _a.sent(); - _a.label = 3; - case 3: return [3 /*break*/, 5]; - case 4: - dockerfilePath = path.join(this.appSourcePath, dockerfilePath); - _a.label = 5; - case 5: - if (!!util.isNullOrEmpty(dockerfilePath)) return [3 /*break*/, 7]; - // Build the image from the provided/discovered Dockerfile - return [4 /*yield*/, this.builderImageFromDockerfile(this.appSourcePath, dockerfilePath, this.imageToBuild)]; - case 6: - // Build the image from the provided/discovered Dockerfile - _a.sent(); - _a.label = 7; - case 7: - // Push the image to ACR - return [4 /*yield*/, this.registryHelper.pushImageToAcr(this.imageToBuild)]; - case 8: - // Push the image to ACR - _a.sent(); - return [2 /*return*/]; - } - }); - }); - }; - /** - * Builds a runnable application image using the builder. - * @param appSourcePath - The path to the application source code. - * @param imageToBuild - The name of the image to build. - */ - azurecontainerapps.buildImageFromBuilderAsync = function (appSourcePath, imageToBuild) { - return __awaiter(this, void 0, void 0, function () { - var _a; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - // Install the pack CLI - return [4 /*yield*/, this.appHelper.installPackCliAsync()]; - case 1: - // Install the pack CLI - _b.sent(); - core.info("Successfully installed the pack CLI."); - // Get the runtime stack if provided, or determine it using Oryx - this.runtimeStack = core.getInput('runtimeStack', { required: false }); - if (!util.isNullOrEmpty(this.runtimeStack)) return [3 /*break*/, 3]; - _a = this; - return [4 /*yield*/, this.appHelper.determineRuntimeStackAsync(appSourcePath)]; - case 2: - _a.runtimeStack = _b.sent(); - core.info("Runtime stack determined to be: " + this.runtimeStack); - _b.label = 3; - case 3: - core.info("Building image \"" + imageToBuild + "\" using the Oryx++ Builder"); - // Set the Oryx++ Builder as the default builder locally - return [4 /*yield*/, this.appHelper.setDefaultBuilder()]; - case 4: - // Set the Oryx++ Builder as the default builder locally - _b.sent(); - // Create a runnable application image - return [4 /*yield*/, this.appHelper.createRunnableAppImage(imageToBuild, appSourcePath, this.runtimeStack)]; - case 5: - // Create a runnable application image - _b.sent(); - // If telemetry is enabled, log that the builder scenario was targeted for this task - this.telemetryHelper.setBuilderScenario(); - return [2 /*return*/]; - } - }); - }); - }; - /** - * Builds a runnable application image using a provided or discovered Dockerfile. - * @param appSourcePath - The path to the application source code. - * @param dockerfilePath - The path to the Dockerfile to build. - * @param imageToBuild - The name of the image to build. - */ - azurecontainerapps.builderImageFromDockerfile = function (appSourcePath, dockerfilePath, imageToBuild) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - core.info("Building image \"" + imageToBuild + "\" using the provided Dockerfile"); - return [4 /*yield*/, this.appHelper.createRunnableAppImageFromDockerfile(imageToBuild, appSourcePath, dockerfilePath)]; - case 1: - _a.sent(); - // If telemetry is enabled, log that the Dockerfile scenario was targeted for this task - this.telemetryHelper.setDockerfileScenario(); - return [2 /*return*/]; - } - }); - }); - }; - /** - * Sets up the Container App properties that will be passed through to the Azure CLI when a YAML configuration - * file is not provided. - */ - azurecontainerapps.setupContainerAppProperties = function () { - this.commandLineArgs = []; - // Get the ingress inputs - this.ingress = core.getInput('ingress', { required: false }); - this.targetPort = core.getInput('targetPort', { required: false }); - // If both ingress and target port were not provided for an existing Container App, or if ingress is to be disabled, - // use the 'update' command, otherwise we should use the 'up' command that performs a PATCH operation on the ingress properties. - this.shouldUseUpdateCommand = this.containerAppExists && - util.isNullOrEmpty(this.targetPort) && - (util.isNullOrEmpty(this.ingress) || this.ingress == 'disabled'); - // Pass the ACR credentials when creating a Container App or updating a Container App via the 'up' command - if (!util.isNullOrEmpty(this.acrName) && !util.isNullOrEmpty(this.acrUsername) && !util.isNullOrEmpty(this.acrPassword) && - (!this.containerAppExists || (this.containerAppExists && !this.shouldUseUpdateCommand))) { - this.commandLineArgs.push("--registry-server " + this.acrName + ".azurecr.io", "--registry-username " + this.acrUsername, "--registry-password " + this.acrPassword); - } - // Determine default values only for the 'create' scenario to avoid overriding existing values for the 'update' scenario - if (!this.containerAppExists) { - this.ingressEnabled = true; - // Set the ingress value to 'external' if it was not provided - if (util.isNullOrEmpty(this.ingress)) { - this.ingress = 'external'; - core.info("Default ingress value: " + this.ingress); - } - // Set the value of ingressEnabled to 'false' if ingress was provided as 'disabled' - if (this.ingress == 'disabled') { - this.ingressEnabled = false; - core.info("Ingress is disabled for this Container App."); - } - // Handle setup for ingress values when enabled - if (this.ingressEnabled) { - // Get the target port if provided, or determine it based on the application type - this.targetPort = core.getInput('targetPort', { required: false }); - if (util.isNullOrEmpty(this.targetPort)) { - if (!util.isNullOrEmpty(this.runtimeStack) && this.runtimeStack.startsWith('python:')) { - this.targetPort = '80'; - } - else { - this.targetPort = '8080'; - } - core.info("Default target port: " + this.targetPort); - } - // Set the target port to 80 if it was not provided or determined - if (util.isNullOrEmpty(this.targetPort)) { - this.targetPort = '80'; - core.info("Default target port: " + this.targetPort); - } - // Add the ingress value and target port to the optional arguments array - // Note: this step should be skipped if we're updating an existing Container App (ingress is enabled via a separate command) - this.commandLineArgs.push("--ingress " + this.ingress); - this.commandLineArgs.push("--target-port " + this.targetPort); - } - } - var environmentVariables = core.getInput('environmentVariables', { required: false }); - // Add user-specified environment variables - if (!util.isNullOrEmpty(environmentVariables)) { - // The --replace-env-vars flag is only used for the 'update' command, - // otherwise --env-vars is used for 'create' and 'up' - if (this.shouldUseUpdateCommand) { - this.commandLineArgs.push("--replace-env-vars " + environmentVariables); - } - else { - this.commandLineArgs.push("--env-vars " + environmentVariables); - } - } - }; - /** - * Creates or updates the Container App. - */ - azurecontainerapps.createOrUpdateContainerApp = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!!this.containerAppExists) return [3 /*break*/, 5]; - if (!!util.isNullOrEmpty(this.yamlConfigPath)) return [3 /*break*/, 2]; - // Create the Container App from the YAML configuration file - return [4 /*yield*/, this.appHelper.createContainerAppFromYaml(this.containerAppName, this.resourceGroup, this.yamlConfigPath)]; - case 1: - // Create the Container App from the YAML configuration file - _a.sent(); - return [3 /*break*/, 4]; - case 2: - // Create the Container App from command line arguments - return [4 /*yield*/, this.appHelper.createContainerApp(this.containerAppName, this.resourceGroup, this.containerAppEnvironment, this.imageToDeploy, this.commandLineArgs)]; - case 3: - // Create the Container App from command line arguments - _a.sent(); - _a.label = 4; - case 4: return [2 /*return*/]; - case 5: - if (!!util.isNullOrEmpty(this.yamlConfigPath)) return [3 /*break*/, 7]; - // Update the Container App from the YAML configuration file - return [4 /*yield*/, this.appHelper.updateContainerAppFromYaml(this.containerAppName, this.resourceGroup, this.yamlConfigPath)]; - case 6: - // Update the Container App from the YAML configuration file - _a.sent(); - return [2 /*return*/]; - case 7: - if (!this.shouldUseUpdateCommand) return [3 /*break*/, 11]; - if (!(!util.isNullOrEmpty(this.acrName) && !util.isNullOrEmpty(this.acrUsername) && !util.isNullOrEmpty(this.acrPassword))) return [3 /*break*/, 9]; - return [4 /*yield*/, this.appHelper.updateContainerAppRegistryDetails(this.containerAppName, this.resourceGroup, this.acrName, this.acrUsername, this.acrPassword)]; - case 8: - _a.sent(); - _a.label = 9; - case 9: - // Update the Container App using the 'update' command - return [4 /*yield*/, this.appHelper.updateContainerApp(this.containerAppName, this.resourceGroup, this.imageToDeploy, this.commandLineArgs)]; - case 10: - // Update the Container App using the 'update' command - _a.sent(); - return [3 /*break*/, 13]; - case 11: - // Update the Container App using the 'up' command - return [4 /*yield*/, this.appHelper.updateContainerAppWithUp(this.containerAppName, this.resourceGroup, this.imageToDeploy, this.commandLineArgs, this.ingress, this.targetPort)]; - case 12: - // Update the Container App using the 'up' command - _a.sent(); - _a.label = 13; - case 13: - if (!(this.ingress == 'disabled')) return [3 /*break*/, 15]; - return [4 /*yield*/, this.appHelper.disableContainerAppIngress(this.containerAppName, this.resourceGroup)]; - case 14: - _a.sent(); - _a.label = 15; - case 15: return [2 /*return*/]; - } - }); - }); - }; - // Azure DevOps build properties - azurecontainerapps.buildId = process.env.GITHUB_RUN_ID; - azurecontainerapps.buildNumber = process.env.GITHUB_RUN_NUMBER; - return azurecontainerapps; -}()); -exports.azurecontainerapps = azurecontainerapps; -azurecontainerapps.runMain(); diff --git a/src/CommandHelper.js b/src/CommandHelper.js deleted file mode 100644 index 8c8648e5..00000000 --- a/src/CommandHelper.js +++ /dev/null @@ -1,168 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -exports.__esModule = true; -exports.CommandHelper = void 0; -var os = require("os"); -var core = require("@actions/core"); -var exec = require("@actions/exec"); -var CommandHelper = /** @class */ (function () { - function CommandHelper() { - } - /** - * Runs a command based on the OS of the agent running this task. - * @param command - the command to execute - * @returns the string output from the command - */ - CommandHelper.prototype.execCommandAsync = function (command) { - return __awaiter(this, void 0, void 0, function () { - var _a; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - if (!(os.platform() == 'win32')) return [3 /*break*/, 2]; - return [4 /*yield*/, this.execPwshCommandAsync(command)]; - case 1: - _a = _b.sent(); - return [3 /*break*/, 4]; - case 2: return [4 /*yield*/, this.execBashCommandAsync(command)]; - case 3: - _a = _b.sent(); - _b.label = 4; - case 4: return [2 /*return*/, _a]; - } - }); - }); - }; - /** - * @param command - the command to execute in Bash - * @returns the string output from the command - */ - CommandHelper.prototype.execBashCommandAsync = function (command) { - return __awaiter(this, void 0, void 0, function () { - var bashOutput, errorStream, options, exitCode, err_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - bashOutput = ''; - errorStream = ''; - options = { - listeners: { - stdout: function (data) { - bashOutput += data.toString(); - core.info(data.toString()); - }, - stderr: function (data) { - errorStream += data.toString(); - core.error(data.toString()); - } - }, - failOnStdErr: true, - ignoreReturnCode: false, - errStream: process.stderr, - outStream: process.stdout - }; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, exec.exec('bash', ['-c', command], options)]; - case 2: - exitCode = _a.sent(); - if (exitCode !== 0) { - throw new Error("Command failed with exit code " + exitCode + ". Error stream: " + errorStream); - } - return [2 /*return*/, bashOutput.trim()]; - case 3: - err_1 = _a.sent(); - core.setFailed(err_1.message); - throw err_1; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Executes a given command using the pwsh executable. - * @param command - the command to execute in PowerShell - * @returns the string output from the command - */ - CommandHelper.prototype.execPwshCommandAsync = function (command) { - return __awaiter(this, void 0, void 0, function () { - var pwshOutput, errorStream, options, exitCode, err_2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - pwshOutput = ''; - errorStream = ''; - options = { - listeners: { - stdout: function (data) { - pwshOutput += data.toString(); - core.info(data.toString()); - }, - stderr: function (data) { - errorStream += data.toString(); - core.error(data.toString()); - } - }, - failOnStdErr: true, - ignoreReturnCode: false, - errStream: process.stderr, - outStream: process.stdout - }; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, exec.exec('pwsh', [command], options)]; - case 2: - exitCode = _a.sent(); - if (exitCode !== 0) { - throw new Error("Command failed with exit code " + exitCode + ". Error stream: " + errorStream); - } - return [2 /*return*/, pwshOutput.trim()]; - case 3: - err_2 = _a.sent(); - core.setFailed(err_2.message); - throw err_2; - case 4: return [2 /*return*/]; - } - }); - }); - }; - return CommandHelper; -}()); -exports.CommandHelper = CommandHelper; diff --git a/src/ContainerAppHelper.js b/src/ContainerAppHelper.js deleted file mode 100644 index 6308a656..00000000 --- a/src/ContainerAppHelper.js +++ /dev/null @@ -1,725 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -exports.__esModule = true; -exports.ContainerAppHelper = void 0; -var core = require("@actions/core"); -var io = require("@actions/io"); -var path = require("path"); -var os = require("os"); -var CommandHelper_1 = require("./CommandHelper"); -var Utility_1 = require("./Utility"); -var util = require('util'); -var cpExec = util.promisify(require('child_process').exec); -var ORYX_CLI_IMAGE = 'mcr.microsoft.com/oryx/cli:builder-debian-buster-20230208.1'; -var ORYX_BUILDER_IMAGE = 'mcr.microsoft.com/oryx/builder:20230208.1'; -var IS_WINDOWS_AGENT = os.platform() == 'win32'; -var PACK_CMD = IS_WINDOWS_AGENT ? path.join(os.tmpdir(), 'pack') : 'pack'; -var ContainerAppHelper = /** @class */ (function () { - function ContainerAppHelper(disableTelemetry) { - this.disableTelemetry = false; - this.disableTelemetry = disableTelemetry; - } - /** - * Creates an Azure Container App based from an image that was previously built. - * @param containerAppName - the name of the Container App - * @param resourceGroup - the resource group that the Container App is found in - * @param environment - the Container App Environment that will be associated with the Container App - * @param imageToDeploy - the name of the runnable application image that the Container App will be based from - * @param optionalCmdArgs - a set of optional command line arguments - */ - ContainerAppHelper.prototype.createContainerApp = function (containerAppName, resourceGroup, environment, imageToDeploy, optionalCmdArgs) { - return __awaiter(this, void 0, void 0, function () { - var command_1, err_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - core.debug("Attempting to create Container App with name \"" + containerAppName + "\" in resource group \"" + resourceGroup + "\" based from image \"" + imageToDeploy + "\""); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - command_1 = "az containerapp create -n " + containerAppName + " -g " + resourceGroup + " -i " + imageToDeploy + " --environment " + environment; - optionalCmdArgs.forEach(function (val) { - command_1 += " " + val; - }); - return [4 /*yield*/, cpExec("" + command_1)]; - case 2: - _a.sent(); - return [3 /*break*/, 4]; - case 3: - err_1 = _a.sent(); - core.error(err_1.message); - throw err_1; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Creates an Azure Container App based from a YAML configuration file. - * @param containerAppName - the name of the Container App - * @param resourceGroup - the resource group that the Container App is found in - * @param yamlConfigPath - the path to the YAML configuration file that the Container App properties will be based from - */ - ContainerAppHelper.prototype.createContainerAppFromYaml = function (containerAppName, resourceGroup, yamlConfigPath) { - return __awaiter(this, void 0, void 0, function () { - var command, err_2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - core.debug("Attempting to create Container App with name \"" + containerAppName + "\" in resource group \"" + resourceGroup + "\" from provided YAML \"" + yamlConfigPath + "\""); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - command = "az containerapp create -n " + containerAppName + " -g " + resourceGroup + " --yaml " + yamlConfigPath; - return [4 /*yield*/, cpExec("" + command)]; - case 2: - _a.sent(); - return [3 /*break*/, 4]; - case 3: - err_2 = _a.sent(); - core.error(err_2.message); - throw err_2; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Updates an existing Azure Container App based from an image that was previously built. - * @param containerAppName - the name of the existing Container App - * @param resourceGroup - the resource group that the existing Container App is found in - * @param imageToDeploy - the name of the runnable application image that the Container App will be based from - * @param optionalCmdArgs - a set of optional command line arguments - */ - ContainerAppHelper.prototype.updateContainerApp = function (containerAppName, resourceGroup, imageToDeploy, optionalCmdArgs) { - return __awaiter(this, void 0, void 0, function () { - var command_2, _a, stdout, stderr, err_3; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - core.debug("Attempting to update Container App with name \"" + containerAppName + "\" in resource group \"" + resourceGroup + "\" based from image \"" + imageToDeploy + "\""); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - command_2 = "az containerapp update -n " + containerAppName + " -g " + resourceGroup + " -i " + imageToDeploy; - optionalCmdArgs.forEach(function (val) { - command_2 += " " + val; - }); - return [4 /*yield*/, cpExec("" + command_2)]; - case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.warning(stderr); - throw new Error(stderr); - } - return [3 /*break*/, 4]; - case 3: - err_3 = _b.sent(); - core.error(err_3.message); - throw err_3; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Updates an existing Azure Container App using the 'az containerapp up' command. - * @param containerAppName - the name of the existing Container App - * @param resourceGroup - the resource group that the existing Container App is found in - * @param imageToDeploy - the name of the runnable application image that the Container App will be based from - * @param optionalCmdArgs - a set of optional command line arguments - * @param ingress - the ingress that the Container App will be exposed on - * @param targetPort - the target port that the Container App will be exposed on - */ - ContainerAppHelper.prototype.updateContainerAppWithUp = function (containerAppName, resourceGroup, imageToDeploy, optionalCmdArgs, ingress, targetPort) { - return __awaiter(this, void 0, void 0, function () { - var util, command_3, _a, stdout, stderr, err_4; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - core.debug("Attempting to update Container App with name \"" + containerAppName + "\" in resource group \"" + resourceGroup + "\" based from image \"" + imageToDeploy + "\""); - util = new Utility_1.Utility(); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - command_3 = "az containerapp up -n " + containerAppName + " -g " + resourceGroup + " -i " + imageToDeploy; - optionalCmdArgs.forEach(function (val) { - command_3 += " " + val; - }); - if (!util.isNullOrEmpty(ingress)) { - command_3 += " --ingress " + ingress; - } - if (!util.isNullOrEmpty(targetPort)) { - command_3 += " --target-port " + targetPort; - } - return [4 /*yield*/, cpExec("" + command_3)]; - case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.warning(stderr); - throw new Error(stderr); - } - return [3 /*break*/, 4]; - case 3: - err_4 = _b.sent(); - core.error(err_4.message); - throw err_4; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Updates an existing Azure Container App based from a YAML configuration file. - * @param containerAppName - the name of the existing Container App - * @param resourceGroup - the resource group that the existing Container App is found in - * @param yamlConfigPath - the path to the YAML configuration file that the Container App properties will be based from - */ - ContainerAppHelper.prototype.updateContainerAppFromYaml = function (containerAppName, resourceGroup, yamlConfigPath) { - return __awaiter(this, void 0, void 0, function () { - var command, _a, stdout, stderr, err_5; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - core.debug("Attempting to update Container App with name \"" + containerAppName + "\" in resource group \"" + resourceGroup + "\" from provided YAML \"" + yamlConfigPath + "\""); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - command = "az containerapp update -n " + containerAppName + " -g " + resourceGroup + " --yaml " + yamlConfigPath; - return [4 /*yield*/, cpExec("" + command)]; - case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.warning(stderr); - throw new Error(stderr); - } - return [3 /*break*/, 4]; - case 3: - err_5 = _b.sent(); - core.error(err_5.message); - throw err_5; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Determines if the provided Container App exists in the provided resource group. - * @param containerAppName - the name of the Container App - * @param resourceGroup - the resource group that the Container App is found in - * @returns true if the Container App exists, false otherwise - */ - ContainerAppHelper.prototype.doesContainerAppExist = function (containerAppName, resourceGroup) { - return __awaiter(this, void 0, void 0, function () { - var command, _a, stdout, stderr, err_6; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - core.debug("Attempting to determine if Container App with name \"" + containerAppName + "\" exists in resource group \"" + resourceGroup + "\""); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - command = "az containerapp show -n " + containerAppName + " -g " + resourceGroup + " -o none"; - return [4 /*yield*/, cpExec("" + command)]; - case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - return [2 /*return*/, !stderr]; - case 3: - err_6 = _b.sent(); - core.warning(err_6.message); - return [2 /*return*/, false]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Determines if the provided Container App Environment exists in the provided resource group. - * @param containerAppEnvironment - the name of the Container App Environment - * @param resourceGroup - the resource group that the Container App Environment is found in - * @returns true if the Container App Environment exists, false otherwise - */ - ContainerAppHelper.prototype.doesContainerAppEnvironmentExist = function (containerAppEnvironment, resourceGroup) { - return __awaiter(this, void 0, void 0, function () { - var command, _a, stdout, stderr, err_7; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - core.debug("Attempting to determine if Container App Environment with name \"" + containerAppEnvironment + "\" exists in resource group \"" + resourceGroup + "\""); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - command = "az containerapp env show -n " + containerAppEnvironment + " -g " + resourceGroup + " -o none"; - return [4 /*yield*/, cpExec("" + command)]; - case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - return [2 /*return*/, !stderr]; - case 3: - err_7 = _b.sent(); - core.warning(err_7.message); - return [2 /*return*/, false]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Determines if the provided resource group exists. - * @param resourceGroup - the name of the resource group - * @returns true if the resource group exists, false otherwise - */ - ContainerAppHelper.prototype.doesResourceGroupExist = function (resourceGroup) { - return __awaiter(this, void 0, void 0, function () { - var command, _a, stdout, stderr, err_8; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - core.debug("Attempting to determine if resource group \"" + resourceGroup + "\" exists"); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - command = "az group show -n " + resourceGroup + " -o none"; - return [4 /*yield*/, cpExec("" + command)]; - case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - return [2 /*return*/, !stderr]; - case 3: - err_8 = _b.sent(); - core.warning(err_8.message); - return [2 /*return*/, false]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Gets the default location for the Container App provider. - * @returns the default location if found, otherwise 'eastus2' - */ - ContainerAppHelper.prototype.getDefaultContainerAppLocation = function () { - return __awaiter(this, void 0, void 0, function () { - var command, _a, stdout, stderr, err_9; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - core.debug("Attempting to get the default location for the Container App service for the subscription."); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - command = "az provider show -n Microsoft.App --query \"resourceTypes[?resourceType=='containerApps'].locations[] | [0]\""; - return [4 /*yield*/, cpExec("" + command)]; - case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - // If successful, strip out double quotes, spaces and parentheses from the first location returned - return [2 /*return*/, !stderr ? stdout.toLowerCase().replace(/["() ]/g, "") : "eastus2"]; - case 3: - err_9 = _b.sent(); - core.warning(err_9.message); - return [2 /*return*/, "eastus2"]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Creates a new resource group in the provided location. - * @param name - the name of the resource group to create - * @param location - the location to create the resource group in - */ - ContainerAppHelper.prototype.createResourceGroup = function (name, location) { - return __awaiter(this, void 0, void 0, function () { - var command, _a, stdout, stderr, err_10; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - core.debug("Attempting to create resource group \"" + name + "\" in location \"" + location + "\""); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - command = "az group create -n " + name + " -l " + location; - return [4 /*yield*/, cpExec("" + command)]; - case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.error('Failed to create resource group, Error: ' + stderr); - throw new Error(stderr); - } - return [3 /*break*/, 4]; - case 3: - err_10 = _b.sent(); - core.error(err_10.message); - throw err_10; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Gets the name of an existing Container App Environment in the provided resource group. - * @param resourceGroup - the resource group to check for an existing Container App Environment - * @returns the name of the existing Container App Environment, null if none exists - */ - ContainerAppHelper.prototype.getExistingContainerAppEnvironment = function (resourceGroup) { - return __awaiter(this, void 0, void 0, function () { - var command, _a, stdout, stderr, err_11; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - core.debug("Attempting to get the existing Container App Environment in resource group \"" + resourceGroup + "\""); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - command = "az containerapp env list -g " + resourceGroup + " --query [0].name\""; - return [4 /*yield*/, cpExec("" + command)]; - case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - return [2 /*return*/, !stderr ? stdout : null]; - case 3: - err_11 = _b.sent(); - core.warning(err_11.message); - return [2 /*return*/, null]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Creates a new Azure Container App Environment in the provided resource group. - * @param name - the name of the Container App Environment - * @param resourceGroup - the resource group that the Container App Environment will be created in - * @param location - the location that the Container App Environment will be created in - */ - ContainerAppHelper.prototype.createContainerAppEnvironment = function (name, resourceGroup, location) { - return __awaiter(this, void 0, void 0, function () { - var util, command, _a, stdout, stderr, err_12; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - util = new Utility_1.Utility(); - core.debug("Attempting to create Container App Environment with name \"" + name + "\" in resource group \"" + resourceGroup + "\""); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - command = "az containerapp env create -n " + name + " -g " + resourceGroup; - if (!util.isNullOrEmpty(location)) { - command += " -l " + location; - } - return [4 /*yield*/, cpExec("" + command)]; - case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.error('Failed to create Container App Environment, Error: ' + stderr); - throw new Error(stderr); - } - return [3 /*break*/, 4]; - case 3: - err_12 = _b.sent(); - core.error(err_12.message); - throw err_12; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Disables ingress on an existing Container App. - * @param name - the name of the Container App - * @param resourceGroup - the resource group that the Container App is found in - */ - ContainerAppHelper.prototype.disableContainerAppIngress = function (name, resourceGroup) { - return __awaiter(this, void 0, void 0, function () { - var command, _a, stdout, stderr, err_13; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - core.debug("Attempting to disable ingress for Container App with name \"" + name + "\" in resource group \"" + resourceGroup + "\""); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - command = "az containerapp ingress disable -n " + name + " -g " + resourceGroup; - return [4 /*yield*/, cpExec("" + command)]; - case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.warning('Failed to disable ingress for Container App, Error: ' + stderr); - throw new Error(stderr); - } - return [3 /*break*/, 4]; - case 3: - err_13 = _b.sent(); - core.error(err_13.message); - throw err_13; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Updates the ACR details on an existing Container App. - * @param name - the name of the Container App - * @param resourceGroup - the resource group that the Container App is found in - * @param acrName - the name of the Azure Container Registry (without the .azurecr.io suffix) - * @param acrUsername - the username used to authenticate with the Azure Container Registry - * @param acrPassword - the password used to authenticate with the Azure Container Registry - */ - ContainerAppHelper.prototype.updateContainerAppRegistryDetails = function (name, resourceGroup, acrName, acrUsername, acrPassword) { - return __awaiter(this, void 0, void 0, function () { - var command, _a, stdout, stderr, err_14; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - core.debug("Attempting to set the ACR details for Container App with name \"" + name + "\" in resource group \"" + resourceGroup + "\""); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - command = "az containerapp registry set -n " + name + " -g " + resourceGroup + " --server " + acrName + ".azurecr.io --username " + acrUsername + " --password " + acrPassword; - return [4 /*yield*/, cpExec("" + command)]; - case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.warning('Failed to set the ACR details for Container App, Error: ' + stderr); - throw new Error(stderr); - } - return [3 /*break*/, 4]; - case 3: - err_14 = _b.sent(); - core.error(err_14.message); - throw err_14; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Using the Oryx++ Builder, creates a runnable application image from the provided application source. - * @param imageToDeploy - the name of the runnable application image that is created and can be later deployed - * @param appSourcePath - the path to the application source on the machine - * @param runtimeStack - the runtime stack to use in the image layer that runs the application - */ - ContainerAppHelper.prototype.createRunnableAppImage = function (imageToDeploy, appSourcePath, runtimeStack) { - return __awaiter(this, void 0, void 0, function () { - var telemetryArg, _a, stdout, stderr, err_15; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - core.debug("Attempting to create a runnable application image using the Oryx++ Builder with image name \"" + imageToDeploy + "\""); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - telemetryArg = "--env \"CALLER_ID=azure-pipelines-rc-v1\""; - if (this.disableTelemetry) { - telemetryArg = "--env \"ORYX_DISABLE_TELEMETRY=true\""; - } - return [4 /*yield*/, cpExec(PACK_CMD + " build " + imageToDeploy + " --path " + appSourcePath + " --builder " + ORYX_BUILDER_IMAGE + " --run-image mcr.microsoft.com/oryx/" + runtimeStack + " " + telemetryArg)]; - case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.error("Failed to create runnable application image using the Oryx++ Builder with image name \"" + imageToDeploy + "\". Error: " + stderr); - throw new Error(stderr); - } - return [3 /*break*/, 4]; - case 3: - err_15 = _b.sent(); - core.error(err_15.message); - throw err_15; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Using a Dockerfile that was provided or found at the root of the application source, - * creates a runable application image. - * @param imageToDeploy - the name of the runnable application image that is created and can be later deployed - * @param appSourcePath - the path to the application source on the machine - * @param dockerfilePath - the path to the Dockerfile to build and tag with the provided image name - */ - ContainerAppHelper.prototype.createRunnableAppImageFromDockerfile = function (imageToDeploy, appSourcePath, dockerfilePath) { - return __awaiter(this, void 0, void 0, function () { - var dockerTool, err_16; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - core.debug("Attempting to create a runnable application image from the provided/found Dockerfile \"" + dockerfilePath + "\" with image name \"" + imageToDeploy + "\""); - _a.label = 1; - case 1: - _a.trys.push([1, 4, , 5]); - return [4 /*yield*/, io.which("docker", true)]; - case 2: - dockerTool = _a.sent(); - return [4 /*yield*/, new Utility_1.Utility().executeAndthrowIfError(dockerTool, ['build', '--file', "" + dockerfilePath, "" + appSourcePath, '--tag', "" + imageToDeploy])]; - case 3: - _a.sent(); - core.debug("Successfully created runnable application image from the provided/found Dockerfile \"" + dockerfilePath + "\" with image name \"" + imageToDeploy + "\""); - return [3 /*break*/, 5]; - case 4: - err_16 = _a.sent(); - core.setFailed(err_16.message); - throw err_16; - case 5: return [2 /*return*/]; - } - }); - }); - }; - /** - * Determines the runtime stack to use for the runnable application image. - * @param appSourcePath - the path to the application source on the machine - * @returns a string representing the runtime stack that can be used for the Oryx MCR runtime images - */ - ContainerAppHelper.prototype.determineRuntimeStackAsync = function (appSourcePath) { - return __awaiter(this, void 0, void 0, function () { - var dockerTool, oryxRuntimeTxtPath, command, runtimeStack, err_17; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - core.debug('Attempting to determine the runtime stack needed for the provided application source'); - _a.label = 1; - case 1: - _a.trys.push([1, 6, , 7]); - return [4 /*yield*/, io.which("docker", true)]; - case 2: - dockerTool = _a.sent(); - // Use 'oryx dockerfile' command to determine the runtime stack to use and write it to a temp file - return [4 /*yield*/, new Utility_1.Utility().executeAndthrowIfError(dockerTool, ['run', '--rm', '-v', appSourcePath + ":/app", "" + ORYX_CLI_IMAGE, '/bin/bash', '-c', "oryx dockerfile /app | head -n 1 | sed 's/ARG RUNTIME=//' >> /app/oryx-runtime.txt"]) - // Read the temp file to get the runtime stack into a variable - ]; - case 3: - // Use 'oryx dockerfile' command to determine the runtime stack to use and write it to a temp file - _a.sent(); - oryxRuntimeTxtPath = path.join(appSourcePath, 'oryx-runtime.txt'); - command = "head -n 1 " + oryxRuntimeTxtPath; - if (IS_WINDOWS_AGENT) { - command = "Get-Content -Path " + oryxRuntimeTxtPath + " -Head 1"; - } - return [4 /*yield*/, new CommandHelper_1.CommandHelper().execCommandAsync(command)]; - case 4: - runtimeStack = _a.sent(); - // Delete the temp file - command = "rm " + oryxRuntimeTxtPath; - if (IS_WINDOWS_AGENT) { - command = "Remove-Item -Path " + oryxRuntimeTxtPath; - } - return [4 /*yield*/, new CommandHelper_1.CommandHelper().execCommandAsync(command)]; - case 5: - _a.sent(); - return [2 /*return*/, runtimeStack]; - case 6: - err_17 = _a.sent(); - core.setFailed(err_17.message); - throw err_17; - case 7: return [2 /*return*/]; - } - }); - }); - }; - /** - * Sets the default builder on the machine to the Oryx++ Builder to prevent an exception from being thrown due - * to no default builder set. - */ - ContainerAppHelper.prototype.setDefaultBuilder = function () { - return __awaiter(this, void 0, void 0, function () { - var _a, stdout, stderr, err_18; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - core.info('Setting the Oryx++ Builder as the default builder via the pack CLI'); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - return [4 /*yield*/, cpExec("pack config default-builder " + ORYX_BUILDER_IMAGE)]; - case 2: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.error("Failed to set the Oryx++ Builder as the default builder via the pack CLI. Error: " + stderr); - throw new Error(stderr); - } - return [3 /*break*/, 4]; - case 3: - err_18 = _b.sent(); - core.setFailed(err_18.message); - throw err_18; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Installs the pack CLI that will be used to build a runnable application image. - * For more information about the pack CLI can be found here: https://buildpacks.io/docs/tools/pack/ - */ - ContainerAppHelper.prototype.installPackCliAsync = function () { - return __awaiter(this, void 0, void 0, function () { - var command, packZipDownloadUri, packZipDownloadFilePath, tgzSuffix, err_19; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - core.debug('Attempting to install the pack CLI'); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - command = ''; - if (IS_WINDOWS_AGENT) { - packZipDownloadUri = 'https://github.com/buildpacks/pack/releases/download/v0.27.0/pack-v0.27.0-windows.zip'; - packZipDownloadFilePath = path.join(PACK_CMD, 'pack-windows.zip'); - command = "New-Item -ItemType Directory -Path " + PACK_CMD + " -Force | Out-Null;" + - ("Invoke-WebRequest -Uri " + packZipDownloadUri + " -OutFile " + packZipDownloadFilePath + "; ") + - ("Expand-Archive -LiteralPath " + packZipDownloadFilePath + " -DestinationPath " + PACK_CMD + "; ") + - ("Remove-Item -Path " + packZipDownloadFilePath); - } - else { - tgzSuffix = os.platform() == 'darwin' ? 'macos' : 'linux'; - command = "(curl -sSL \"https://github.com/buildpacks/pack/releases/download/v0.27.0/pack-v0.27.0-" + tgzSuffix + ".tgz\" | " + - 'tar -C /usr/local/bin/ --no-same-owner -xzv pack)'; - } - return [4 /*yield*/, new CommandHelper_1.CommandHelper().execCommandAsync(command)]; - case 2: - _a.sent(); - return [3 /*break*/, 4]; - case 3: - err_19 = _a.sent(); - core.error("Unable to install the pack CLI. Error: " + err_19.message); - core.setFailed(err_19.message); - throw err_19; - case 4: return [2 /*return*/]; - } - }); - }); - }; - return ContainerAppHelper; -}()); -exports.ContainerAppHelper = ContainerAppHelper; diff --git a/src/ContainerAppHelper.ts b/src/ContainerAppHelper.ts index c76f7395..4a456b48 100644 --- a/src/ContainerAppHelper.ts +++ b/src/ContainerAppHelper.ts @@ -4,7 +4,7 @@ import * as path from 'path'; import * as os from 'os'; import { CommandHelper } from './CommandHelper'; import { Utility } from './Utility'; -const util = require('util'); +import util = require('util'); const cpExec = util.promisify(require('child_process').exec); const ORYX_CLI_IMAGE: string = 'mcr.microsoft.com/oryx/cli:builder-debian-buster-20230208.1'; @@ -85,11 +85,7 @@ export class ContainerAppHelper { command += ` ${val}`; }); - const {stdout, stderr} = await cpExec(`${command}`); - if (stderr) { - core.warning(stderr); - throw new Error(stderr); - } + await cpExec(`${command}`); } catch (err) { core.error(err.message); throw err; @@ -128,11 +124,7 @@ export class ContainerAppHelper { command += ` --target-port ${targetPort}`; } - const {stdout, stderr} = await cpExec(`${command}`); - if (stderr) { - core.warning(stderr); - throw new Error(stderr); - } + await cpExec(`${command}`); } catch (err) { core.error(err.message); throw err; @@ -152,11 +144,7 @@ export class ContainerAppHelper { core.debug(`Attempting to update Container App with name "${containerAppName}" in resource group "${resourceGroup}" from provided YAML "${yamlConfigPath}"`); try { let command = `az containerapp update -n ${containerAppName} -g ${resourceGroup} --yaml ${yamlConfigPath}`; - const {stdout, stderr} = await cpExec(`${command}`); - if (stderr) { - core.warning(stderr); - throw new Error(stderr); - } + await cpExec(`${command}`); } catch (err) { core.error(err.message); throw err; @@ -242,11 +230,8 @@ export class ContainerAppHelper { core.debug(`Attempting to create resource group "${name}" in location "${location}"`); try { const command = `az group create -n ${name} -l ${location}`; - const {stdout, stderr} = await cpExec(`${command}`); - if (stderr) { - core.error('Failed to create resource group, Error: ' + stderr); - throw new Error(stderr); - } + await cpExec(`${command}`); + } catch (err) { core.error(err.message); throw err; @@ -284,11 +269,7 @@ export class ContainerAppHelper { if (!util.isNullOrEmpty(location)) { command += ` -l ${location}`; } - const {stdout, stderr} = await cpExec(`${command}`); - if (stderr) { - core.error('Failed to create Container App Environment, Error: ' + stderr); - throw new Error(stderr); - } + await cpExec(`${command}`); } catch (err) { core.error(err.message); throw err; @@ -304,11 +285,7 @@ export class ContainerAppHelper { core.debug(`Attempting to disable ingress for Container App with name "${name}" in resource group "${resourceGroup}"`); try { const command = `az containerapp ingress disable -n ${name} -g ${resourceGroup}`; - const {stdout, stderr} = await cpExec(`${command}`); - if (stderr) { - core.warning('Failed to disable ingress for Container App, Error: ' + stderr); - throw new Error(stderr); - } + await cpExec(`${command}`); } catch (err) { core.error(err.message); throw err; @@ -327,11 +304,7 @@ export class ContainerAppHelper { core.debug(`Attempting to set the ACR details for Container App with name "${name}" in resource group "${resourceGroup}"`); try { const command = `az containerapp registry set -n ${name} -g ${resourceGroup} --server ${acrName}.azurecr.io --username ${acrUsername} --password ${acrPassword}`; - const {stdout, stderr} = await cpExec(`${command}`); - if (stderr) { - core.warning('Failed to set the ACR details for Container App, Error: ' + stderr); - throw new Error(stderr); - } + await cpExec(`${command}`); } catch (err) { core.error(err.message); throw err; @@ -354,11 +327,7 @@ export class ContainerAppHelper { if (this.disableTelemetry) { telemetryArg = `--env "ORYX_DISABLE_TELEMETRY=true"`; } - const {stdout, stderr} = await cpExec(`${PACK_CMD} build ${imageToDeploy} --path ${appSourcePath} --builder ${ORYX_BUILDER_IMAGE} --run-image mcr.microsoft.com/oryx/${runtimeStack} ${telemetryArg}`); - if (stderr) { - core.error(`Failed to create runnable application image using the Oryx++ Builder with image name "${imageToDeploy}". Error: ${stderr}`); - throw new Error(stderr); - } + await cpExec(`${PACK_CMD} build ${imageToDeploy} --path ${appSourcePath} --builder ${ORYX_BUILDER_IMAGE} --run-image mcr.microsoft.com/oryx/${runtimeStack} ${telemetryArg}`); } catch (err) { core.error(err.message); throw err; @@ -431,11 +400,7 @@ export class ContainerAppHelper { core.info('Setting the Oryx++ Builder as the default builder via the pack CLI'); try { - const {stdout, stderr} = await cpExec(`pack config default-builder ${ORYX_BUILDER_IMAGE}`); - if (stderr) { - core.error(`Failed to set the Oryx++ Builder as the default builder via the pack CLI. Error: ${stderr}`); - throw new Error(stderr); - } + await cpExec(`pack config default-builder ${ORYX_BUILDER_IMAGE}`); } catch (err) { core.setFailed(err.message); diff --git a/src/ContainerRegistryHelper.js b/src/ContainerRegistryHelper.js deleted file mode 100644 index c43ce856..00000000 --- a/src/ContainerRegistryHelper.js +++ /dev/null @@ -1,139 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -exports.__esModule = true; -exports.ContainerRegistryHelper = void 0; -var core = require("@actions/core"); -var exec = require("@actions/exec"); -var io = require("@actions/io"); -var CommandHelper_1 = require("./CommandHelper"); -var Utility_1 = require("./Utility"); -var ContainerRegistryHelper = /** @class */ (function () { - function ContainerRegistryHelper() { - } - /** - * Authorizes Docker to make calls to the provided ACR instance using username and password. - * @param acrName - the name of the ACR instance to authenticate calls to - * @param acrUsername - the username for authentication - * @param acrPassword - the password for authentication - */ - ContainerRegistryHelper.prototype.loginAcrWithUsernamePassword = function (acrName, acrUsername, acrPassword) { - return __awaiter(this, void 0, void 0, function () { - var err_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - core.debug("Attempting to log in to ACR instance \"" + acrName + "\" with username and password credentials"); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, exec.exec('docker', ["login", "--password-stdin", "--username", "" + acrUsername, acrName + ".azurecr.io"], { input: Buffer.from(acrPassword) })]; - case 2: - _a.sent(); - return [3 /*break*/, 4]; - case 3: - err_1 = _a.sent(); - core.error("Failed to log in to ACR instance \"" + acrName + "\" with username and password credentials"); - throw err_1; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Authorizes Docker to make calls to the provided ACR instance using an access token that is generated via - * the 'az acr login --expose-token' command. - * @param acrName - the name of the ACR instance to authenticate calls to. - */ - ContainerRegistryHelper.prototype.loginAcrWithAccessTokenAsync = function (acrName) { - return __awaiter(this, void 0, void 0, function () { - var command, err_2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - core.debug("Attempting to log in to ACR instance \"" + acrName + "\" with access token"); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - command = "CA_ADO_TASK_ACR_ACCESS_TOKEN=$(az acr login --name " + acrName + " --output json --expose-token --only-show-errors | jq -r '.accessToken'); docker login " + acrName + ".azurecr.io -u 00000000-0000-0000-0000-000000000000 -p $CA_ADO_TASK_ACR_ACCESS_TOKEN > /dev/null 2>&1"; - return [4 /*yield*/, new CommandHelper_1.CommandHelper().execCommandAsync(command)]; - case 2: - _a.sent(); - return [3 /*break*/, 4]; - case 3: - err_2 = _a.sent(); - core.error("Failed to log in to ACR instance \"" + acrName + "\" with access token"); - throw err_2; - case 4: return [2 /*return*/]; - } - }); - }); - }; - /** - * Pushes an image to the ACR instance that was previously authenticated against. - * @param imageToPush - the name of the image to push to ACR - */ - ContainerRegistryHelper.prototype.pushImageToAcr = function (imageToPush) { - return __awaiter(this, void 0, void 0, function () { - var dockerTool, err_3; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - core.debug("Attempting to push image \"" + imageToPush + "\" to ACR"); - _a.label = 1; - case 1: - _a.trys.push([1, 4, , 5]); - return [4 /*yield*/, io.which("docker", true)]; - case 2: - dockerTool = _a.sent(); - return [4 /*yield*/, new Utility_1.Utility().executeAndthrowIfError(dockerTool, ["push", "" + imageToPush])]; - case 3: - _a.sent(); - return [3 /*break*/, 5]; - case 4: - err_3 = _a.sent(); - core.error("Failed to push image \"" + imageToPush + "\" to ACR. Error: " + err_3.message); - core.setFailed(err_3.message); - throw err_3; - case 5: return [2 /*return*/]; - } - }); - }); - }; - return ContainerRegistryHelper; -}()); -exports.ContainerRegistryHelper = ContainerRegistryHelper; diff --git a/src/Strings/en-Us/resources.json b/src/Strings/en-Us/resources.json deleted file mode 100644 index ab4a530c..00000000 --- a/src/Strings/en-Us/resources.json +++ /dev/null @@ -1,85 +0,0 @@ -{ - "loc.friendlyName": "Azure Container Apps Deploy (Release Candidate)", - "loc.helpMarkDown": "[Learn more about this task](http://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureContainerAppsV0/README.md)", - "loc.description": "An Azure DevOps Task to build and deploy Azure Container Apps.", - "loc.instanceNameFormat": "Azure Container Apps Deploy (Release Candidate)", - "loc.releaseNotes": "Update telemetry caller ID to reflect new version of RC task.", - "loc.input.label.cwd": "Working Directory", - "loc.input.help.cwd": "Current working directory where the script is run. Empty is the root of the repo (build) or artifacts (release), which is $(System.DefaultWorkingDirectory)", - "loc.input.label.appSourcePath": "Application source path", - "loc.input.help.appSourcePath": "Absolute path on the runner of the source application code to be built. If not provided, the 'imageToDeploy' argument must be provided to ensure the Container App has an image to reference.", - "loc.input.label.connectedServiceNameARM": "Azure Resource Manager connection", - "loc.input.help.connectedServiceNameARM": "Select an Azure Resource Manager service connection for the deployment", - "loc.input.label.acrName": "Azure Container Registry name", - "loc.input.help.acrName": "The name of the Azure Container Registry that the runnable application image will be pushed to.", - "loc.input.label.acrUsername": "Azure Container Registry username", - "loc.input.help.acrUsername": "The username used to authenticate push requests to the provided Azure Container Registry. If not provided, an access token will be generated via 'az acr login' and provided to 'docker login' to authenticate the requests.", - "loc.input.label.acrPassword": "Azure Container Registry password", - "loc.input.help.acrPassword": "The password used to authenticate push requests to the provided Azure Container Registry. If not provided, an access token will be generated via 'az acr login' and provided to 'docker login' to authenticate the requests.", - "loc.input.label.dockerfilePath": "Dockerfile path", - "loc.input.help.dockerfilePath": "Relative path to the Dockerfile in the provided application source that should be used to build the image that is then pushed to ACR and deployed to the Container App. If not provided, this task will check if there is a file named 'Dockerfile' at the root of the provided application source and use that to build the image. Otherwise, the Oryx++ Builder will be used to create the image.", - "loc.input.label.imageToBuild": "Docker image to build", - "loc.input.help.imageToBuild": "The custom name of the image that is to be built, pushed to ACR and deployed to the Container App by this task. Note: this image name should include the ACR server; e.g., .azurecr.io/:. If this argument is not provided, a default image name will be constructed in the form of `.azurecr.io/ado-task/container-app:.`.", - "loc.input.label.imageToDeploy": "Docker image to deploy", - "loc.input.help.imageToDeploy": "The custom name of the image that has already been pushed to ACR and will be deployed to the Container App by this task. Note: the image name should include the ACR server; e.g., .azurecr.io/:. If this argument is not provided, the value provided (or determined) for the 'imageToBuild' argument will be used.", - "loc.input.label.containerAppName": "Azure Container App name", - "loc.input.help.containerAppName": "The name of the Azure Container App that will be created or updated. If not provided, this value will be in the form of `ado-task-app--`.", - "loc.input.label.resourceGroup": "Azure resource group name", - "loc.input.help.resourceGroup": "The existing resource group that the Azure Container App will be created in. If not provided, this value will be `-rg` and its existence will first be checked before attempting to create it.", - "loc.input.label.containerAppEnvironment": "Azure Container App environment", - "loc.input.help.containerAppEnvironment": "The name of the Azure Container App environment to use with the application. If not provided, an existing environment in the resource group of the Container App will be used, otherwise, an environment will be created in the form of `-env`.", - "loc.input.label.runtimeStack": "Application runtime stack", - "loc.input.help.runtimeStack": "The platform version stack that the application runs in when deployed to the Azure Container App. This should be provided in the form of `:`. If not provided, this value is determined by Oryx based on the contents of the provided application. Please view the following document for more information on the supported runtime stacks for Oryx: https://github.com/microsoft/Oryx/blob/main/doc/supportedRuntimeVersions.md", - "loc.input.label.targetPort": "Application target port", - "loc.input.help.targetPort": "The designated port for the application to run on. If no value is provided and the builder is used to build the runnable application image, the target port will be set to 80 for Python applications and 8080 for all other platform applications. If no value is provided when creating a Container App, the target port will default to 80. Note: when using this task to update a Container App, the target port may be updated if not provided based on changes to the ingress property.", - "loc.input.label.location": "Location of the Container App", - "loc.input.help.location": "The location that the Container App (and other created resources) will be deployed to.", - "loc.input.label.environmentVariables": "Environment variables", - "loc.input.help.environmentVariables": "A list of environment variable(s) for the container. Space-separated values in 'key=value' format. Empty string to clear existing values. Prefix value with 'secretref:' to reference a secret.", - "loc.input.label.ingress": "Ingress setting", - "loc.input.help.ingress": "Possible options: external, internal, disabled. If set to `external` (default value if not provided when creating a Container App), the Container App will be visible from the internet or a VNET, depending on the app environment endpoint configured. If set to `internal`, the Container App will be visible from within the app environment only. If set to `disabled`, ingress will be disabled for this Container App and will not have an HTTP or TCP endpoint.", - "loc.input.label.yamlConfigPath": "YAML configuration file path", - "loc.input.help.yamlConfigPath": "Full path (on the executing Azure Pipelines agent) to the YAML file detailing the configuration of the Container App.", - "loc.input.label.disableTelemetry": "Disable telemetry", - "loc.input.help.disableTelemetry": "If set to 'true', no telemetry will be collected by this Azure DevOps Task. If set to 'false', or if this argument is not provided, telemetry will be sent to Microsoft about the Container App build and deploy scenario targeted by this Azure DevOps Task.", - "AcrAccessTokenAuthFailed": "Unable to authenticate against ACR instance '%s.azurecr.io' with access token.", - "AcrAccessTokenLoginMessage": "Logging in to Azure Container Registry using access token to be generated via Azure CLI.", - "AcrUsernamePasswordAuthFailed": "Unable to authenticate against ACR instance '%s.azurecr.io' with username/password.", - "AcrUsernamePasswordLoginMessage": "Logging in to Azure Container Registry using provided acrUsername and acrPassword arguments.", - "AzureCliDynamicInstallFailed": "Unable to set the Azure CLI to dynamically install missing extensions.", - "BashCommandFailed": "`Unable to run provided bash command '%s'.", - "CheckForAppSourceDockerfileMessage": "No dockerfilePath argument provided; checking for 'Dockerfile' at the root of app source path '%s' to build image from.", - "ContainerAppEnvironmentUsedMessage": "Using the provided containerAppEnvironment value provided '%s' when deploying the Container App.", - "CreateContainerAppEnvironmentFailed": "Unable to create Container App Environment.", - "CreateContainerAppFailed": "Unable to create Azure Container App via 'az containerapp create' command.", - "CreateContainerAppFromYamlFailed": "Unable to create Azure Container App from YAML configuration file via 'az containerapp create' command.", - "CreateImageWithBuilderFailed": "Unable to create runnable application image using Oryx++ Builder.", - "CreateImageWithBuilderMessage": "No Dockerfile was provided or found for the application source; attempting to create a runnable application image using the Oryx++ Builder.", - "CreateImageWithDockerfileFailed": "Unable to create runnable application image using provided or discovered Dockerfile.", - "CreateImageWithDockerfileMessage": "A Dockerfile was provided or found for the application source; attempting to build the image from Dockerfile '%s'.", - "CreateResourceGroupFailed": "Unable to create resource group '%s'.", - "DefaultContainerAppNameMessage": "No containerAppName argument was provided; setting the name of the Container App to create/update to '%s'.", - "DefaultContainerAppEnvironmentMessage": "No containerAppEnvironment argument was provided; setting the Container App to create/update to '%s'.", - "DefaultImageToBuildMessage": "No imageToBuild argument was provided; setting the image to be built to '%s'.", - "DefaultImageToDeployMessage": "No imageToDeploy argument was provided; setting the image to deploy to '%s'.", - "DefaultIngressMessage": "No ingress argument was provided, setting the ingress value to '%s'.", - "DefaultResourceGroupMessage": "No resourceGroup argument was provided; setting the resource group for deployment to '%s'.", - "DefaultRuntimeStackMessage": "No runtimeStack argument was provided; using the runtime stack that was found for the app '%s'.", - "DefaultTargetPortMessage": "No targetPort argument was provided; using the target port '%s' for the application.", - "DetermineRuntimeStackFailed": "`Unable to determine runtime stack from application source '%s'.", - "DisableContainerAppIngressFailed": "Unable to disable ingress for the Container App.", - "DisabledIngressMessage": "Ingress will be disabled for the Container App.", - "EnableContainerAppIngressFailed": "Unable to enable ingress for the Container App.", - "ErrorCodeFormat": "Error Code: {errorCode}", - "ErrorMessageFormat": "Error: {errorMessage}", - "ExistingContainerAppEnvironmentMessage": "Discovered existing Container App Environment, '%s', to use with the Container App.", - "FoundAppSourceDockerfileMessage": "Found existing Dockerfile in provided application source at path '%s'; image will be built from this Dockerfile.", - "MissingAcrNameMessage": "The acrName argument must also be provided if the appSourcePath argument is provided.", - "MissingRequiredArgumentMessage": "One of the following arguments must be provided: appSourcePath, imageToDeploy, yamlConfigPath", - "PackCliInstallFailed": "Unable to install pack CLI.", - "PushImageToAcrFailed": "Unable to push image '%s' to ACR.", - "SetDefaultBuilderFailed": "Unable to set the Oryx++ Builder as the default builder.", - "UpdateContainerAppFailed": "Unable to update Azure Container App via 'az containerapp update' command.", - "UpdateContainerAppFromYamlFailed": "Unable to update Azure Container App from YAML configuration file via 'az containerapp update' command.", - "UpdateContainerAppRegistryDetailsFailed": "Unable to update Azure Container App ACR details via 'az containerapp registry set' command." - } \ No newline at end of file diff --git a/src/TelemetryHelper.js b/src/TelemetryHelper.js deleted file mode 100644 index ca5bec03..00000000 --- a/src/TelemetryHelper.js +++ /dev/null @@ -1,155 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -exports.__esModule = true; -exports.TelemetryHelper = void 0; -var core = require("@actions/core"); -var Utility_1 = require("./Utility"); -var io = require("@actions/io"); -var ORYX_CLI_IMAGE = "mcr.microsoft.com/oryx/cli:debian-buster-20230207.2"; -var SUCCESSFUL_RESULT = "succeeded"; -var FAILED_RESULT = "failed"; -var BUILDER_SCENARIO = "used-builder"; -var DOCKERFILE_SCENARIO = "used-dockerfile"; -var IMAGE_SCENARIO = "used-image"; -var util = new Utility_1.Utility(); -var TelemetryHelper = /** @class */ (function () { - function TelemetryHelper(disableTelemetry) { - this.disableTelemetry = disableTelemetry; - this.taskStartMilliseconds = Date.now(); - } - /** - * Marks that the task was successful in telemetry. - */ - TelemetryHelper.prototype.setSuccessfulResult = function () { - this.result = SUCCESSFUL_RESULT; - }; - /** - * Marks that the task failed in telemetry. - */ - TelemetryHelper.prototype.setFailedResult = function (errorMessage) { - this.result = FAILED_RESULT; - this.errorMessage = errorMessage; - }; - /** - * Marks that the task used the builder scenario. - */ - TelemetryHelper.prototype.setBuilderScenario = function () { - this.scenario = BUILDER_SCENARIO; - }; - /** - * Marks that the task used the Dockerfile scenario. - */ - TelemetryHelper.prototype.setDockerfileScenario = function () { - this.scenario = DOCKERFILE_SCENARIO; - }; - /** - * Marks that the task used the previously built image scenario. - */ - TelemetryHelper.prototype.setImageScenario = function () { - this.scenario = IMAGE_SCENARIO; - }; - /** - * If telemetry is enabled, uses the "oryx telemetry" command to log metadata about this task execution. - */ - TelemetryHelper.prototype.sendLogs = function () { - return __awaiter(this, void 0, void 0, function () { - var taskLengthMilliseconds, resultArg, scenarioArg, errorMessageArg, args, err_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - taskLengthMilliseconds = Date.now() - this.taskStartMilliseconds; - if (!!this.disableTelemetry) return [3 /*break*/, 4]; - core.info("Telemetry enabled; logging metadata about task result, length and scenario targeted."); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - resultArg = ''; - if (!util.isNullOrEmpty(this.result)) { - resultArg = "--property 'result=" + this.result + "'"; - } - scenarioArg = ''; - if (!util.isNullOrEmpty(this.scenario)) { - scenarioArg = "--property 'scenario=" + this.scenario + "'"; - } - errorMessageArg = ''; - if (!util.isNullOrEmpty(this.errorMessage)) { - errorMessageArg = "--property 'errorMessage=" + this.errorMessage + "'"; - } - args = ["run", "--rm", "" + ORYX_CLI_IMAGE, "/bin/bash", "-c", "oryx telemetry --event-name 'ContainerAppsPipelinesTaskRCV1' " + ("--processing-time '" + taskLengthMilliseconds + "' " + resultArg + " " + scenarioArg + " " + errorMessageArg + "\"")]; - // Don't use Utility's throwIfError() since it will still record an error in the pipeline logs, but won't fail the task - return [4 /*yield*/, executeDockerCommand(args, true)]; - case 2: - // Don't use Utility's throwIfError() since it will still record an error in the pipeline logs, but won't fail the task - _a.sent(); - return [3 /*break*/, 4]; - case 3: - err_1 = _a.sent(); - core.warning("Skipping telemetry logging due to the following exception: " + err_1.message); - return [3 /*break*/, 4]; - case 4: return [2 /*return*/]; - } - }); - }); - }; - return TelemetryHelper; -}()); -exports.TelemetryHelper = TelemetryHelper; -var executeDockerCommand = function (args, continueOnError) { - if (continueOnError === void 0) { continueOnError = false; } - return __awaiter(void 0, void 0, void 0, function () { - var dockerTool, err_2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - _a.trys.push([0, 3, , 4]); - return [4 /*yield*/, io.which("docker", true)]; - case 1: - dockerTool = _a.sent(); - return [4 /*yield*/, new Utility_1.Utility().executeAndthrowIfError(dockerTool, args, continueOnError)]; - case 2: - _a.sent(); - return [3 /*break*/, 4]; - case 3: - err_2 = _a.sent(); - core.setFailed("Error: " + err_2.message); - throw err_2; // Re-throw the error - case 4: return [2 /*return*/]; - } - }); - }); -}; diff --git a/src/Utility.js b/src/Utility.js deleted file mode 100644 index 95edc17f..00000000 --- a/src/Utility.js +++ /dev/null @@ -1,117 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -exports.__esModule = true; -exports.Utility = void 0; -var core = require("@actions/core"); -var exec = require("@actions/exec"); -var util = require("util"); -var cpExec = util.promisify(require('child_process').exec); -var Utility = /** @class */ (function () { - function Utility() { - } - /** - * @param commandLine - the command to execute - * @param args - the arguments to pass to the command - * @param continueOnError - whether or not to continue execution if the command fails - */ - Utility.prototype.executeAndthrowIfError = function (commandLine, args, continueOnError) { - if (continueOnError === void 0) { continueOnError = false; } - return __awaiter(this, void 0, void 0, function () { - var stdout_1, stderr_1, options, exitCode, error_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - _a.trys.push([0, 2, , 3]); - stdout_1 = ''; - stderr_1 = ''; - options = { - listeners: { - stdout: function (data) { - stdout_1 += data.toString(); - core.info(data.toString()); - }, - stderr: function (data) { - stderr_1 += data.toString(); - core.error(data.toString()); - } - } - }; - return [4 /*yield*/, exec.exec(commandLine, args, options)]; - case 1: - exitCode = _a.sent(); - if (!continueOnError && exitCode !== 0) { - core.error("Command failed with exit code " + exitCode + ". Error stream: " + stderr_1); - throw new Error("Command failed with exit code " + exitCode + ". Error stream: " + stderr_1); - } - return [3 /*break*/, 3]; - case 2: - error_1 = _a.sent(); - core.setFailed("Error: " + error_1.message); - throw error_1; // Re-throw the error - case 3: return [2 /*return*/]; - } - }); - }); - }; - /** - * Sets the Azure CLI to dynamically install extensions that are missing. In this case, we care about the - * Azure Container Apps module being dynamically installed while it's still in preview. - */ - Utility.prototype.setAzureCliDynamicInstall = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, cpExec("az config set extension.use_dynamic_install=yes_without_prompt")]; - case 1: - _a.sent(); - return [2 /*return*/]; - } - }); - }); - }; - /** - * Checks whether or not the provided string is null, undefined or empty. - * @param str - the string to validate - * @returns true if the string is null, undefined or empty, false otherwise - */ - Utility.prototype.isNullOrEmpty = function (str) { - return str === null || str === undefined || str === ""; - }; - return Utility; -}()); -exports.Utility = Utility;