Skip to content

Commit

Permalink
Merge branch 'snehapar/container-apps-deploy-action-javascript' into …
Browse files Browse the repository at this point in the history
…snehapar/container-apps-deploy-action-typescript
  • Loading branch information
snehapar9 committed Sep 21, 2023
2 parents b7705b3 + a0e5eff commit c7ffa17
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 149 deletions.
45 changes: 21 additions & 24 deletions azurecontainerapps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ export class azurecontainerapps {
core.setFailed(err.message);
this.telemetryHelper.setFailedResult(err.message);
} finally {
// Logout of Azure if logged in during this task session
// this.authHelper.logoutAzure();

// If telemetry is enabled, will log metadata for this task run
await this.telemetryHelper.sendLogs();
}
Expand Down Expand Up @@ -108,7 +105,7 @@ export class azurecontainerapps {
this.telemetryHelper = new TelemetryHelper(disableTelemetry);

// Set up AzureAuthenticationHelper for managing logging in and out of Azure CLI using provided service connection
// this.authHelper = new AzureAuthenticationHelper();
// this.authHelper = new AzureAuthenticationHelper();

// Set up ContainerAppHelper for managing calls around the Container App
this.appHelper = new ContainerAppHelper(disableTelemetry);
Expand All @@ -124,16 +121,16 @@ export class azurecontainerapps {
private static validateSupportedScenarioArguments() {

// Get the path to the application source to build and run, if provided
this.appSourcePath = core.getInput('appSourcePath', {required: false});
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});
this.acrName = core.getInput('acrName', { required: false });

// Get the previously built image to deploy, if provided
this.imageToDeploy = core.getInput('imageToDeploy', {required: false});
this.imageToDeploy = core.getInput('imageToDeploy', { required: false });

// Get the YAML configuration file, if provided
this.yamlConfigPath = core.getInput('yamlConfigPath', {required: false});
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)) {
Expand Down Expand Up @@ -188,7 +185,7 @@ export class azurecontainerapps {
* @returns The name of the Container App to use for the task.
*/
private static getContainerAppName(): string {
let containerAppName: string = core.getInput('containerAppName', {required: false});
let containerAppName: string = core.getInput('containerAppName', { required: false });
if (util.isNullOrEmpty(containerAppName)) {
containerAppName = `app-${this.buildId}-${this.buildNumber}`;

Expand All @@ -207,7 +204,7 @@ export class azurecontainerapps {
*/
private static async getLocation(): Promise<string> {
// Set deployment location, if provided
let location: string = core.getInput('location', {required: false});
let location: string = core.getInput('location', { required: false });

// If no location was provided, use the default location for the Container App service
if (util.isNullOrEmpty(location)) {
Expand All @@ -227,7 +224,7 @@ export class azurecontainerapps {
*/
private static async getOrCreateResourceGroup(containerAppName: string, location: string): Promise<string> {
// Get the resource group to deploy to if it was provided, or generate it from the Container App name
let resourceGroup: string = core.getInput('resourceGroup', {required: false});
let resourceGroup: string = core.getInput('resourceGroup', { required: false });
if (util.isNullOrEmpty(resourceGroup)) {
resourceGroup = `${containerAppName}-rg`;
core.info(`Default resource group name: ${resourceGroup}`);
Expand Down Expand Up @@ -257,7 +254,7 @@ export class azurecontainerapps {
resourceGroup: string,
location: string): Promise<string> {
// Get the Container App environment if it was provided
let containerAppEnvironment: string = core.getInput('containerAppEnvironment', {required: false});
let containerAppEnvironment: string = core.getInput('containerAppEnvironment', { required: false });

// See if we can reuse an existing Container App environment found in the resource group
if (util.isNullOrEmpty(containerAppEnvironment)) {
Expand Down Expand Up @@ -287,8 +284,8 @@ export class azurecontainerapps {
* Authenticates calls to the provided Azure Container Registry.
*/
private static async authenticateAzureContainerRegistryAsync() {
this.acrUsername = core.getInput('acrUsername', {required: false});
this.acrPassword = core.getInput('acrPassword', {required: false});
this.acrUsername = core.getInput('acrUsername', { required: false });
this.acrPassword = core.getInput('acrPassword', { required: false });

// Login to ACR if credentials were provided
if (!util.isNullOrEmpty(this.acrUsername) && !util.isNullOrEmpty(this.acrPassword)) {
Expand All @@ -313,9 +310,9 @@ export class azurecontainerapps {
*/
private static async buildAndPushImageAsync() {
// 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});
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}`;
this.imageToBuild = `${this.acrName}.azurecr.io/gh-action/container-app:${this.buildId}.${this.buildNumber}`;
core.info(`Default image to build: ${this.imageToBuild}`);
}

Expand All @@ -326,7 +323,7 @@ export class azurecontainerapps {
}

// Get Dockerfile to build, if provided, or check if one exists at the root of the provided application
let dockerfilePath: string = core.getInput('dockerfilePath', {required: false});
let dockerfilePath: string = core.getInput('dockerfilePath', { required: false });
if (util.isNullOrEmpty(dockerfilePath)) {
core.info(`No Dockerfile path provided; checking for Dockerfile at root of application source.`);
const rootDockerfilePath = path.join(this.appSourcePath, 'Dockerfile');
Expand Down Expand Up @@ -361,7 +358,7 @@ export class azurecontainerapps {
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});
this.runtimeStack = core.getInput('runtimeStack', { required: false });
if (util.isNullOrEmpty(this.runtimeStack)) {
this.runtimeStack = await this.appHelper.determineRuntimeStackAsync(appSourcePath);
core.info(`Runtime stack determined to be: ${this.runtimeStack}`);
Expand Down Expand Up @@ -401,14 +398,14 @@ export class azurecontainerapps {
this.commandLineArgs = [];

// Get the ingress inputs
this.ingress = core.getInput('ingress', {required: false});
this.targetPort = core.getInput('targetPort', {required: false});
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');
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) &&
Expand Down Expand Up @@ -438,7 +435,7 @@ export class azurecontainerapps {
// 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});
this.targetPort = core.getInput('targetPort', { required: false });
if (util.isNullOrEmpty(this.targetPort)) {
if (!util.isNullOrEmpty(this.runtimeStack) && this.runtimeStack.startsWith('python:')) {
this.targetPort = '80';
Expand All @@ -462,7 +459,7 @@ export class azurecontainerapps {
}
}

const environmentVariables: string = core.getInput('environmentVariables', {required: false});
const environmentVariables: string = core.getInput('environmentVariables', { required: false });

// Add user-specified environment variables
if (!util.isNullOrEmpty(environmentVariables)) {
Expand Down
44 changes: 19 additions & 25 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,10 @@ var azurecontainerapps = /** @class */ (function () {
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();
case 9:
// 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*/];
Expand Down Expand Up @@ -169,7 +165,7 @@ var azurecontainerapps = /** @class */ (function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
case 0:
// Set the Azure CLI to dynamically install missing extensions
return [4 /*yield*/, util.setAzureCliDynamicInstall()];
case 1:
Expand Down Expand Up @@ -383,7 +379,7 @@ var azurecontainerapps = /** @class */ (function () {
// 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;
this.imageToBuild = this.acrName + ".azurecr.io/gh-action/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'
Expand All @@ -399,7 +395,7 @@ var azurecontainerapps = /** @class */ (function () {
core.info("Dockerfile found at root of application source.");
dockerfilePath = rootDockerfilePath;
return [3 /*break*/, 3];
case 1:
case 1:
// No Dockerfile found or provided, build the image using the builder
return [4 /*yield*/, this.buildImageFromBuilderAsync(this.appSourcePath, this.imageToBuild)];
case 2:
Expand All @@ -418,7 +414,7 @@ var azurecontainerapps = /** @class */ (function () {
// Build the image from the provided/discovered Dockerfile
_a.sent();
_a.label = 7;
case 7:
case 7:
// Push the image to ACR
return [4 /*yield*/, this.registryHelper.pushImageToAcr(this.imageToBuild)];
case 8:
Expand All @@ -439,7 +435,7 @@ var azurecontainerapps = /** @class */ (function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
case 0:
// Install the pack CLI
return [4 /*yield*/, this.appHelper.installPackCliAsync()];
case 1:
Expand Down Expand Up @@ -581,7 +577,7 @@ var azurecontainerapps = /** @class */ (function () {
// Create the Container App from the YAML configuration file
_a.sent();
return [3 /*break*/, 4];
case 2:
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:
Expand All @@ -604,14 +600,14 @@ var azurecontainerapps = /** @class */ (function () {
case 8:
_a.sent();
_a.label = 9;
case 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:
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:
Expand Down Expand Up @@ -1195,8 +1191,8 @@ class OidcClient {
const res = yield httpclient
.getJson(id_token_url)
.catch(error => {
throw new Error(`Failed to get ID Token. \n
Error Code : ${error.statusCode}\n
throw new Error(`Failed to get ID Token. \n
Error Code : ${error.statusCode}\n
Error Message: ${error.message}`);
});
const id_token = (_a = res.result) === null || _a === void 0 ? void 0 : _a.value;
Expand Down Expand Up @@ -5729,10 +5725,8 @@ var TelemetryHelper = /** @class */ (function () {
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:
Expand Down Expand Up @@ -6016,7 +6010,7 @@ module.exports = require("util");
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/
/******/ // The require function
/******/ function __nccwpck_require__(moduleId) {
/******/ // Check if module is in cache
Expand All @@ -6030,7 +6024,7 @@ module.exports = require("util");
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/
/******/ // Execute the module function
/******/ var threw = true;
/******/ try {
Expand All @@ -6039,23 +6033,23 @@ module.exports = require("util");
/******/ } finally {
/******/ if(threw) delete __webpack_module_cache__[moduleId];
/******/ }
/******/
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat */
/******/
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
/******/
/******/
/************************************************************************/
/******/
/******/
/******/ // 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__(3238);
/******/ module.exports = __webpack_exports__;
/******/
/******/
/******/ })()
;
Loading

0 comments on commit c7ffa17

Please sign in to comment.