|
| 1 | +"use strict"; |
| 2 | +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| 3 | + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
| 4 | + return new (P || (P = Promise))(function (resolve, reject) { |
| 5 | + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 6 | + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 7 | + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
| 8 | + step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| 9 | + }); |
| 10 | +}; |
| 11 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 12 | +exports.ContentPreparer = void 0; |
| 13 | +const utility_js_1 = require("azure-actions-utility/utility.js"); |
| 14 | +const ziputility_js_1 = require("azure-actions-utility/ziputility.js"); |
| 15 | +const packageUtility_1 = require("azure-actions-utility/packageUtility"); |
| 16 | +const state_1 = require("../constants/state"); |
| 17 | +const exceptions_1 = require("../exceptions"); |
| 18 | +const publish_method_1 = require("../constants/publish_method"); |
| 19 | +const function_sku_1 = require("../constants/function_sku"); |
| 20 | +const runtime_stack_1 = require("../constants/runtime_stack"); |
| 21 | +const utils_1 = require("../utils"); |
| 22 | +const authentication_type_1 = require("../constants/authentication_type"); |
| 23 | +class ContentPreparer { |
| 24 | + invoke(state, params, context) { |
| 25 | + return __awaiter(this, void 0, void 0, function* () { |
| 26 | + this.validatePackageType(state, context.package); |
| 27 | + this._packageType = context.package.getPackageType(); |
| 28 | + this._publishContentPath = yield this.generatePublishContent(state, params.packagePath, this._packageType); |
| 29 | + this._publishMethod = this.derivePublishMethod(state, this._packageType, context.os, context.sku, context.authenticationType); |
| 30 | + try { |
| 31 | + yield context.kuduServiceUtil.warmpUp(); |
| 32 | + } |
| 33 | + catch (expt) { |
| 34 | + throw new exceptions_1.AzureResourceError(state, "Warmup", `Failed to warmup ${params.appName}`, expt); |
| 35 | + } |
| 36 | + return state_1.StateConstant.PublishContent; |
| 37 | + }); |
| 38 | + } |
| 39 | + changeContext(_0, _1, context) { |
| 40 | + return __awaiter(this, void 0, void 0, function* () { |
| 41 | + context.packageType = this._packageType; |
| 42 | + context.publishContentPath = this._publishContentPath; |
| 43 | + context.publishMethod = this._publishMethod; |
| 44 | + return context; |
| 45 | + }); |
| 46 | + } |
| 47 | + validatePackageType(state, pkg) { |
| 48 | + const packageType = pkg.getPackageType(); |
| 49 | + switch (packageType) { |
| 50 | + case packageUtility_1.PackageType.zip: |
| 51 | + case packageUtility_1.PackageType.folder: |
| 52 | + break; |
| 53 | + default: |
| 54 | + throw new exceptions_1.ValidationError(state, "validatePackageType", "only accepts zip or folder"); |
| 55 | + } |
| 56 | + } |
| 57 | + generatePublishContent(state, packagePath, packageType) { |
| 58 | + return __awaiter(this, void 0, void 0, function* () { |
| 59 | + switch (packageType) { |
| 60 | + case packageUtility_1.PackageType.zip: |
| 61 | + utils_1.Logger.Log(`Will directly deploy ${packagePath} as function app content`); |
| 62 | + return packagePath; |
| 63 | + case packageUtility_1.PackageType.folder: |
| 64 | + const tempoaryFilePath = utility_js_1.generateTemporaryFolderOrZipPath(process.env.RUNNER_TEMP, false); |
| 65 | + utils_1.Logger.Log(`Will archive ${packagePath} into ${tempoaryFilePath} as function app content`); |
| 66 | + try { |
| 67 | + return yield ziputility_js_1.archiveFolder(packagePath, "", tempoaryFilePath); |
| 68 | + } |
| 69 | + catch (expt) { |
| 70 | + throw new exceptions_1.FileIOError(state, "Generate Publish Content", `Failed to archive ${packagePath}`, expt); |
| 71 | + } |
| 72 | + default: |
| 73 | + throw new exceptions_1.ValidationError(state, "Generate Publish Content", "only accepts zip or folder"); |
| 74 | + } |
| 75 | + }); |
| 76 | + } |
| 77 | + derivePublishMethod(state, packageType, osType, sku, authenticationType) { |
| 78 | + // Uses api/zipdeploy endpoint if scm credential is provided |
| 79 | + if (authenticationType == authentication_type_1.AuthenticationType.Scm) { |
| 80 | + utils_1.Logger.Log('Will use api/zipdeploy to deploy (scm credential)'); |
| 81 | + return publish_method_1.PublishMethodConstant.ZipDeploy; |
| 82 | + } |
| 83 | + // Linux Consumption sets WEBSITE_RUN_FROM_PACKAGE app settings when scm credential is not available |
| 84 | + if (osType === runtime_stack_1.RuntimeStackConstant.Linux && sku === function_sku_1.FunctionSkuConstant.Consumption) { |
| 85 | + utils_1.Logger.Log('Will use WEBSITE_RUN_FROM_PACKAGE to deploy'); |
| 86 | + return publish_method_1.PublishMethodConstant.WebsiteRunFromPackageDeploy; |
| 87 | + } |
| 88 | + // Rest Skus which support api/zipdeploy endpoint |
| 89 | + switch (packageType) { |
| 90 | + case packageUtility_1.PackageType.zip: |
| 91 | + case packageUtility_1.PackageType.folder: |
| 92 | + utils_1.Logger.Log('Will use api/zipdeploy to deploy (rbac authentication)'); |
| 93 | + return publish_method_1.PublishMethodConstant.ZipDeploy; |
| 94 | + default: |
| 95 | + throw new exceptions_1.ValidationError(state, "Derive Publish Method", "only accepts zip or folder"); |
| 96 | + } |
| 97 | + } |
| 98 | +} |
| 99 | +exports.ContentPreparer = ContentPreparer; |
0 commit comments