diff --git a/__tests__/ActionInputValidator/ValidatorFactory.test.ts b/__tests__/ActionInputValidator/ValidatorFactory.test.ts index ffd293c99..9009f6342 100644 --- a/__tests__/ActionInputValidator/ValidatorFactory.test.ts +++ b/__tests__/ActionInputValidator/ValidatorFactory.test.ts @@ -26,8 +26,8 @@ describe('Test Validator Factory', () => { jest.spyOn(PublishProfile, 'getPublishProfile').mockImplementation(() => PublishProfile.prototype); jest.spyOn(PublishProfile.prototype, 'getAppOS').mockImplementation(async() => 'unix'); - let validators = await ValidatorFactory.getValidator(type); - expect(validators[0]).toBeInstanceOf(PublishProfileWebAppValidator); + let validator = await ValidatorFactory.getValidator(type); + expect(validator).toBeInstanceOf(PublishProfileWebAppValidator); }); it("Get Container Validator for Publish Profile auth flow", async() => { @@ -42,8 +42,8 @@ describe('Test Validator Factory', () => { jest.spyOn(PublishProfile, 'getPublishProfile').mockImplementation(() => PublishProfile.prototype); jest.spyOn(PublishProfile.prototype, 'getAppOS').mockImplementation(async() => 'unix'); - let validators = await ValidatorFactory.getValidator(type); - expect(validators[0]).toBeInstanceOf(PublishProfileContainerWebAppValidator); + let validator = await ValidatorFactory.getValidator(type); + expect(validator).toBeInstanceOf(PublishProfileContainerWebAppValidator); }); }); @@ -70,8 +70,8 @@ describe('Test Validator Factory', () => { }; }); - let validators = await ValidatorFactory.getValidator(type); - expect(validators[0]).toBeInstanceOf(SpnLinuxContainerWebAppValidator); + let validator = await ValidatorFactory.getValidator(type); + expect(validator).toBeInstanceOf(SpnLinuxContainerWebAppValidator); }); it("Get Linux/Kube Code Validator for SPN auth flow", async() => { @@ -90,8 +90,8 @@ describe('Test Validator Factory', () => { }; }); - let validators = await ValidatorFactory.getValidator(type); - expect(validators[0]).toBeInstanceOf(SpnLinuxWebAppValidator); + let validator = await ValidatorFactory.getValidator(type); + expect(validator).toBeInstanceOf(SpnLinuxWebAppValidator); }); it("Get Windows Container Validator for SPN auth flow", async() => { @@ -111,8 +111,8 @@ describe('Test Validator Factory', () => { }; }); - let validators = await ValidatorFactory.getValidator(type); - expect(validators[0]).toBeInstanceOf(SpnWindowsContainerWebAppValidator); + let validator = await ValidatorFactory.getValidator(type); + expect(validator).toBeInstanceOf(SpnWindowsContainerWebAppValidator); }); it("Get Windows Code Validator for SPN auth flow", async() => { @@ -131,8 +131,8 @@ describe('Test Validator Factory', () => { }; }); - let validators = await ValidatorFactory.getValidator(type); - expect(validators[0]).toBeInstanceOf(SpnWindowsWebAppValidator); + let validator = await ValidatorFactory.getValidator(type); + expect(validator).toBeInstanceOf(SpnWindowsWebAppValidator); }); }); diff --git a/__tests__/DeploymentProvider/DeploymentProviderFactory.test.ts b/__tests__/DeploymentProvider/DeploymentProviderFactory.test.ts index 8309e752b..d2c3584db 100644 --- a/__tests__/DeploymentProvider/DeploymentProviderFactory.test.ts +++ b/__tests__/DeploymentProvider/DeploymentProviderFactory.test.ts @@ -19,8 +19,8 @@ describe('Test Deployment Provider Factory', () => { it("Get Code Deployment Provider for Publish Profile auth flow", async() => { let type: DEPLOYMENT_PROVIDER_TYPES = DEPLOYMENT_PROVIDER_TYPES.PUBLISHPROFILE; - let providers = await DeploymentProviderFactory.getDeploymentProvider(type); - expect(providers[0]).toBeInstanceOf(WebAppDeploymentProvider); + let provider = await DeploymentProviderFactory.getDeploymentProvider(type); + expect(provider).toBeInstanceOf(WebAppDeploymentProvider); }); it("Get Container Deployment Provider for Publish Profile auth flow", async() => { @@ -32,8 +32,8 @@ describe('Test Deployment Provider Factory', () => { let type: DEPLOYMENT_PROVIDER_TYPES = DEPLOYMENT_PROVIDER_TYPES.PUBLISHPROFILE; - let providers = await DeploymentProviderFactory.getDeploymentProvider(type); - expect(providers[0]).toBeInstanceOf(PublishProfileWebAppContainerDeploymentProvider); + let provider = await DeploymentProviderFactory.getDeploymentProvider(type); + expect(provider).toBeInstanceOf(PublishProfileWebAppContainerDeploymentProvider); }); }); @@ -48,8 +48,8 @@ describe('Test Deployment Provider Factory', () => { let type: DEPLOYMENT_PROVIDER_TYPES = DEPLOYMENT_PROVIDER_TYPES.SPN; - let providers = await DeploymentProviderFactory.getDeploymentProvider(type); - expect(providers[0]).toBeInstanceOf(WebAppDeploymentProvider); + let provider = await DeploymentProviderFactory.getDeploymentProvider(type); + expect(provider).toBeInstanceOf(WebAppDeploymentProvider); }); it("Get Container Deployment Provider for SPN auth flow", async() => { @@ -61,8 +61,8 @@ describe('Test Deployment Provider Factory', () => { let type: DEPLOYMENT_PROVIDER_TYPES = DEPLOYMENT_PROVIDER_TYPES.SPN; - let providers = await DeploymentProviderFactory.getDeploymentProvider(type); - expect(providers[0]).toBeInstanceOf(WebAppContainerDeploymentProvider); + let provider = await DeploymentProviderFactory.getDeploymentProvider(type); + expect(provider).toBeInstanceOf(WebAppContainerDeploymentProvider); }); }); diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 33d2dacca..d2caff0c3 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -35,9 +35,9 @@ describe('Test azure-webapps-deploy', () => { } return ''; }); - let getValidatorFactorySpy = jest.spyOn(ValidatorFactory, 'getValidator').mockImplementation(async _type => [new PublishProfileWebAppValidator()]); + let getValidatorFactorySpy = jest.spyOn(ValidatorFactory, 'getValidator').mockImplementation(async _type => new PublishProfileWebAppValidator()); let ValidatorFactoryValidateSpy = jest.spyOn(PublishProfileWebAppValidator.prototype, 'validate'); - let getDeploymentProviderSpy = jest.spyOn(DeploymentProviderFactory, 'getDeploymentProvider').mockImplementation(type => [new WebAppDeploymentProvider(type)]); + let getDeploymentProviderSpy = jest.spyOn(DeploymentProviderFactory, 'getDeploymentProvider').mockImplementation(type => new WebAppDeploymentProvider(type)); let deployWebAppStepSpy = jest.spyOn(WebAppDeploymentProvider.prototype, 'DeployWebAppStep'); let updateDeploymentStatusSpy = jest.spyOn(WebAppDeploymentProvider.prototype, 'UpdateDeploymentStatus'); diff --git a/lib/ActionInputValidator/ActionValidators/SpnWebAppSiteContainersValidator.js b/lib/ActionInputValidator/ActionValidators/SpnWebAppSiteContainersValidator.js index 46f54d856..639e16254 100644 --- a/lib/ActionInputValidator/ActionValidators/SpnWebAppSiteContainersValidator.js +++ b/lib/ActionInputValidator/ActionValidators/SpnWebAppSiteContainersValidator.js @@ -11,9 +11,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", { value: true }); exports.SpnWebAppSiteContainersValidator = void 0; const Validations_1 = require("../Validations"); -class SpnWebAppSiteContainersValidator { +const SpnLinuxWebAppValidator_1 = require("./SpnLinuxWebAppValidator"); +const actionparameters_1 = require("../../actionparameters"); +class SpnWebAppSiteContainersValidator extends SpnLinuxWebAppValidator_1.SpnLinuxWebAppValidator { validate() { + const _super = Object.create(null, { + validate: { get: () => super.validate } + }); return __awaiter(this, void 0, void 0, function* () { + let actionParams = actionparameters_1.ActionParameters.getActionParams(); + if (!!actionParams.blessedAppSitecontainers) { + yield _super.validate.call(this); + } (0, Validations_1.validateSiteContainersInputs)(); }); } diff --git a/lib/ActionInputValidator/ValidatorFactory.js b/lib/ActionInputValidator/ValidatorFactory.js index 14e4ec4dd..593b1d6d1 100644 --- a/lib/ActionInputValidator/ValidatorFactory.js +++ b/lib/ActionInputValidator/ValidatorFactory.js @@ -68,11 +68,11 @@ class ValidatorFactory { let actionParams = actionparameters_1.ActionParameters.getActionParams(); if (type === BaseWebAppDeploymentProvider_1.DEPLOYMENT_PROVIDER_TYPES.PUBLISHPROFILE) { if (!!actionParams.blessedAppSitecontainers || !!actionParams.siteContainers) { - return [new PublishProfileWebAppSiteContainersValidator_1.PublishProfileWebAppSiteContainersValidator()]; + return new PublishProfileWebAppSiteContainersValidator_1.PublishProfileWebAppSiteContainersValidator(); } else if (!!actionParams.images) { yield this.setResourceDetails(actionParams); - return [new PublishProfileContainerWebAppValidator_1.PublishProfileContainerWebAppValidator()]; + return new PublishProfileContainerWebAppValidator_1.PublishProfileContainerWebAppValidator(); } else { try { @@ -81,7 +81,7 @@ class ValidatorFactory { catch (error) { core.warning(`Failed to set resource details: ${error.message}`); } - return [new PublishProfileWebAppValidator_1.PublishProfileWebAppValidator()]; + return new PublishProfileWebAppValidator_1.PublishProfileWebAppValidator(); } } else if (type == BaseWebAppDeploymentProvider_1.DEPLOYMENT_PROVIDER_TYPES.SPN) { @@ -90,24 +90,22 @@ class ValidatorFactory { yield this.getResourceDetails(actionParams); if (!!actionParams.isLinux) { if (!!actionParams.siteContainers) { - if (yield this.isBlessedSitecontainerApp(actionParams)) { - return [new SpnLinuxWebAppValidator_1.SpnLinuxWebAppValidator(), new SpnWebAppSiteContainersValidator_1.SpnWebAppSiteContainersValidator()]; - } - return [new SpnWebAppSiteContainersValidator_1.SpnWebAppSiteContainersValidator()]; + yield this.setBlessedSitecontainerApp(actionParams); + return new SpnWebAppSiteContainersValidator_1.SpnWebAppSiteContainersValidator(); } else if (!!actionParams.images || !!actionParams.multiContainerConfigFile) { - return [new SpnLinuxContainerWebAppValidator_1.SpnLinuxContainerWebAppValidator()]; + return new SpnLinuxContainerWebAppValidator_1.SpnLinuxContainerWebAppValidator(); } else { - return [new SpnLinuxWebAppValidator_1.SpnLinuxWebAppValidator()]; + return new SpnLinuxWebAppValidator_1.SpnLinuxWebAppValidator(); } } else { if (!!actionParams.images) { - return [new SpnWindowsContainerWebAppValidator_1.SpnWindowsContainerWebAppValidator()]; + return new SpnWindowsContainerWebAppValidator_1.SpnWindowsContainerWebAppValidator(); } else { - return [new SpnWindowsWebAppValidator_1.SpnWindowsWebAppValidator()]; + return new SpnWindowsWebAppValidator_1.SpnWindowsWebAppValidator(); } } } @@ -133,16 +131,17 @@ class ValidatorFactory { actionParams.isLinux = appOS.includes(RuntimeConstants_1.default.Unix) || appOS.includes(RuntimeConstants_1.default.Unix.toLowerCase()); }); } - static isBlessedSitecontainerApp(actionParams) { + static setBlessedSitecontainerApp(actionParams) { return __awaiter(this, void 0, void 0, function* () { - var _a, _b; + var _a; const appService = new azure_app_service_1.AzureAppService(actionParams.endpoint, actionParams.resourceGroupName, actionParams.appName, actionParams.slotName); let config = yield appService.getConfiguration(); core.debug(`LinuxFxVersion of app is: ${config.properties.linuxFxVersion}`); - actionParams.blessedAppSitecontainers = (((_a = config.properties.linuxFxVersion) === null || _a === void 0 ? void 0 : _a.startsWith("DOCKER|")) !== true - && ((_b = config.properties.linuxFxVersion) === null || _b === void 0 ? void 0 : _b.startsWith("COMPOSE|")) !== true - && config.properties.linuxFxVersion !== "SITECONTAINERS"); - return actionParams.blessedAppSitecontainers; + const linuxFxVersion = ((_a = config.properties.linuxFxVersion) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || ""; + actionParams.blessedAppSitecontainers = (!linuxFxVersion.startsWith("DOCKER|") + && !linuxFxVersion.startsWith("COMPOSE|") + && linuxFxVersion !== "SITECONTAINERS"); + core.debug(`Is blessed app sitecontainers: ${actionParams.blessedAppSitecontainers}`); }); } } diff --git a/lib/DeploymentProvider/DeploymentProviderFactory.js b/lib/DeploymentProvider/DeploymentProviderFactory.js index fc3f117c0..a0684a0f9 100644 --- a/lib/DeploymentProvider/DeploymentProviderFactory.js +++ b/lib/DeploymentProvider/DeploymentProviderFactory.js @@ -11,24 +11,21 @@ class DeploymentProviderFactory { static getDeploymentProvider(type) { if (type === BaseWebAppDeploymentProvider_1.DEPLOYMENT_PROVIDER_TYPES.PUBLISHPROFILE) { if (!!actionparameters_1.ActionParameters.getActionParams().images) { - return [new PublishProfileWebAppContainerDeploymentProvider_1.PublishProfileWebAppContainerDeploymentProvider(type)]; + return new PublishProfileWebAppContainerDeploymentProvider_1.PublishProfileWebAppContainerDeploymentProvider(type); } else { - return [new WebAppDeploymentProvider_1.WebAppDeploymentProvider(type)]; + return new WebAppDeploymentProvider_1.WebAppDeploymentProvider(type); } } else if (type == BaseWebAppDeploymentProvider_1.DEPLOYMENT_PROVIDER_TYPES.SPN) { - if (!!actionparameters_1.ActionParameters.getActionParams().blessedAppSitecontainers) { - return [new WebAppDeploymentProvider_1.WebAppDeploymentProvider(type), new WebAppSiteContainersDeploymentProvider_1.WebAppSiteContainersDeploymentProvider(type)]; - } - else if (!!actionparameters_1.ActionParameters.getActionParams().siteContainers) { - return [new WebAppSiteContainersDeploymentProvider_1.WebAppSiteContainersDeploymentProvider(type)]; + if (!!actionparameters_1.ActionParameters.getActionParams().blessedAppSitecontainers || !!actionparameters_1.ActionParameters.getActionParams().siteContainers) { + return new WebAppSiteContainersDeploymentProvider_1.WebAppSiteContainersDeploymentProvider(type); } else if (!!actionparameters_1.ActionParameters.getActionParams().images || (!!actionparameters_1.ActionParameters.getActionParams().isLinux && !!actionparameters_1.ActionParameters.getActionParams().multiContainerConfigFile)) { - return [new WebAppContainerDeployment_1.WebAppContainerDeploymentProvider(type)]; + return new WebAppContainerDeployment_1.WebAppContainerDeploymentProvider(type); } else { - return [new WebAppDeploymentProvider_1.WebAppDeploymentProvider(type)]; + return new WebAppDeploymentProvider_1.WebAppDeploymentProvider(type); } } else { diff --git a/lib/DeploymentProvider/Providers/WebAppSiteContainersDeploymentProvider.js b/lib/DeploymentProvider/Providers/WebAppSiteContainersDeploymentProvider.js index 2cb7df776..cf41c4cae 100644 --- a/lib/DeploymentProvider/Providers/WebAppSiteContainersDeploymentProvider.js +++ b/lib/DeploymentProvider/Providers/WebAppSiteContainersDeploymentProvider.js @@ -43,18 +43,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", { value: true }); exports.WebAppSiteContainersDeploymentProvider = void 0; -const BaseWebAppDeploymentProvider_1 = require("./BaseWebAppDeploymentProvider"); const SiteContainerDeploymentUtility_1 = require("azure-actions-appservice-rest/Utilities/SiteContainerDeploymentUtility"); const core = __importStar(require("@actions/core")); -class WebAppSiteContainersDeploymentProvider extends BaseWebAppDeploymentProvider_1.BaseWebAppDeploymentProvider { +const WebAppDeploymentProvider_1 = require("./WebAppDeploymentProvider"); +class WebAppSiteContainersDeploymentProvider extends WebAppDeploymentProvider_1.WebAppDeploymentProvider { DeployWebAppStep() { + const _super = Object.create(null, { + DeployWebAppStep: { get: () => super.DeployWebAppStep } + }); return __awaiter(this, void 0, void 0, function* () { + if (!!this.actionParams.blessedAppSitecontainers) { + core.info("Blessed site containers detected, using WebAppDeploymentProvider for deployment."); + yield _super.DeployWebAppStep.call(this); + } let siteContainerDeploymentUtility = new SiteContainerDeploymentUtility_1.SiteContainerDeploymentUtility(this.appService); let siteContainers = this.actionParams.siteContainers; core.info("Updating site containers"); for (let i = 0; i < siteContainers.length; i++) { let siteContainer = siteContainers[i]; - core.info("updating site container: " + siteContainer.getName); + core.info("updating site container: " + siteContainer.getName()); yield siteContainerDeploymentUtility.updateSiteContainer(siteContainer); } }); diff --git a/lib/main.js b/lib/main.js index 438e54438..5a68a7d35 100644 --- a/lib/main.js +++ b/lib/main.js @@ -71,17 +71,13 @@ function main() { type = BaseWebAppDeploymentProvider_1.DEPLOYMENT_PROVIDER_TYPES.PUBLISHPROFILE; } // Validate action inputs - let validators = yield ValidatorFactory_1.ValidatorFactory.getValidator(type); - for (const validator of validators) { - yield validator.validate(); - } - var deploymentProviders = DeploymentProviderFactory_1.DeploymentProviderFactory.getDeploymentProvider(type); - for (const provider of deploymentProviders) { - core.info("Predeployment Step Started"); - yield provider.PreDeploymentStep(); - core.info("Deployment Step Started"); - yield provider.DeployWebAppStep(); - } + let validator = yield ValidatorFactory_1.ValidatorFactory.getValidator(type); + yield validator.validate(); + var deploymentProvider = DeploymentProviderFactory_1.DeploymentProviderFactory.getDeploymentProvider(type); + core.info("Predeployment Step Started"); + yield deploymentProvider.PreDeploymentStep(); + core.info("Deployment Step Started"); + yield deploymentProvider.DeployWebAppStep(); } catch (error) { isDeploymentSuccess = false; @@ -95,8 +91,8 @@ function main() { } } finally { - if (deploymentProviders != null) { - yield deploymentProviders[0].UpdateDeploymentStatus(isDeploymentSuccess); + if (deploymentProvider != null) { + yield deploymentProvider.UpdateDeploymentStatus(isDeploymentSuccess); } // Reset AZURE_HTTP_USER_AGENT core.exportVariable('AZURE_HTTP_USER_AGENT', prefix); diff --git a/package-lock.json b/package-lock.json index 29d9cb5ef..3321f5857 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@actions/core": "^1.10.0", "@actions/github": "^4.0.0", "actions-secret-parser": "^1.0.4", - "azure-actions-appservice-rest": "^1.3.32", + "azure-actions-appservice-rest": "^1.3.34", "azure-actions-utility": "^1.0.3", "azure-actions-webclient": "^1.1.1" }, @@ -1514,9 +1514,9 @@ } }, "node_modules/azure-actions-appservice-rest": { - "version": "1.3.32", - "resolved": "https://registry.npmjs.org/azure-actions-appservice-rest/-/azure-actions-appservice-rest-1.3.32.tgz", - "integrity": "sha512-GFj/HuhJCOePbP2YZcouqrt7i2Set2yyJ3mquM7fTnZzJu8uv3eNYNYMS7kEoyRTxSv9EePvEmLPKZOWRgGE+A==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/azure-actions-appservice-rest/-/azure-actions-appservice-rest-1.3.34.tgz", + "integrity": "sha512-Wy48/F+gPvM6UiRuJkUxfL7aPbb7vXwAoDPrI18cKS1XVWYoQOHm5cJu8gPWc8WVgO7FFs4Jd0ZqfzGv440fzw==", "license": "MIT", "dependencies": { "@actions/core": "^1.1.10", @@ -1642,9 +1642,9 @@ } }, "node_modules/babel-preset-current-node-syntax": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.1.0.tgz", - "integrity": "sha512-ldYss8SbBlWva1bs28q78Ju5Zq1F+8BrqBZZ0VFhLBvhh6lCpC2o3gDJi/5DRLs9FgYZCnmPYIVFU4lRXCkyUw==", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.1.1.tgz", + "integrity": "sha512-23fWKohMTvS5s0wwJKycOe0dBdCwQ6+iiLaNR9zy8P13mtFRFM9qLLX6HJX5DL2pi/FNDf3fCQHM4FIMoHH/7w==", "dev": true, "license": "MIT", "dependencies": { @@ -1665,7 +1665,7 @@ "@babel/plugin-syntax-top-level-await": "^7.14.5" }, "peerDependencies": { - "@babel/core": "^7.0.0" + "@babel/core": "^7.0.0 || ^8.0.0-0" } }, "node_modules/babel-preset-jest": { @@ -1963,9 +1963,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001727", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001727.tgz", - "integrity": "sha512-pB68nIHmbN6L/4C6MH1DokyR3bYqFwjaSs/sWDHGj4CTcFtQUQMuJftVwWkXq7mNWOybD3KhUv3oWHoGxgP14Q==", + "version": "1.0.30001731", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001731.tgz", + "integrity": "sha512-lDdp2/wrOmTRWuoB5DpfNkC0rJDU8DqRa6nYL6HK6sytw70QMopt/NIc/9SM7ylItlBWfACXk0tEn37UWM/+mg==", "dev": true, "funding": [ { @@ -2416,9 +2416,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.191", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.191.tgz", - "integrity": "sha512-xcwe9ELcuxYLUFqZZxL19Z6HVKcvNkIwhbHUz7L3us6u12yR+7uY89dSl570f/IqNthx8dAw3tojG7i4Ni4tDA==", + "version": "1.5.192", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.192.tgz", + "integrity": "sha512-rP8Ez0w7UNw/9j5eSXCe10o1g/8B1P5SM90PCCMVkIRQn2R0LEHWz4Eh9RnxkniuDe1W0cTSOB3MLlkTGDcuCg==", "dev": true, "license": "ISC" }, @@ -2768,6 +2768,21 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "license": "ISC" }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", diff --git a/package.json b/package.json index 47bed6549..cc266d5c7 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "@actions/core": "^1.10.0", "@actions/github": "^4.0.0", "actions-secret-parser": "^1.0.4", - "azure-actions-appservice-rest": "^1.3.32", + "azure-actions-appservice-rest": "^1.3.34", "azure-actions-utility": "^1.0.3", "azure-actions-webclient": "^1.1.1" } diff --git a/src/ActionInputValidator/ActionValidators/SpnWebAppSiteContainersValidator.ts b/src/ActionInputValidator/ActionValidators/SpnWebAppSiteContainersValidator.ts index 71f049fea..90e4fc186 100644 --- a/src/ActionInputValidator/ActionValidators/SpnWebAppSiteContainersValidator.ts +++ b/src/ActionInputValidator/ActionValidators/SpnWebAppSiteContainersValidator.ts @@ -1,10 +1,17 @@ import { validateSiteContainersInputs } from "../Validations"; + import { IValidator } from "./IValidator"; +import { SpnLinuxWebAppValidator } from "./SpnLinuxWebAppValidator"; +import { ActionParameters } from "../../actionparameters"; -export class SpnWebAppSiteContainersValidator implements IValidator { +export class SpnWebAppSiteContainersValidator extends SpnLinuxWebAppValidator { async validate(): Promise { + + let actionParams: ActionParameters = ActionParameters.getActionParams(); + if (!!actionParams.blessedAppSitecontainers) { + await super.validate(); + } validateSiteContainersInputs(); - } } \ No newline at end of file diff --git a/src/ActionInputValidator/ValidatorFactory.ts b/src/ActionInputValidator/ValidatorFactory.ts index 3352c0dec..535eb80e8 100644 --- a/src/ActionInputValidator/ValidatorFactory.ts +++ b/src/ActionInputValidator/ValidatorFactory.ts @@ -18,15 +18,15 @@ import { PublishProfileWebAppSiteContainersValidator } from "./ActionValidators/ import { AzureAppService } from "azure-actions-appservice-rest/Arm/azure-app-service"; export class ValidatorFactory { - public static async getValidator(type: DEPLOYMENT_PROVIDER_TYPES) : Promise { + public static async getValidator(type: DEPLOYMENT_PROVIDER_TYPES) : Promise { let actionParams: ActionParameters = ActionParameters.getActionParams(); if(type === DEPLOYMENT_PROVIDER_TYPES.PUBLISHPROFILE) { if (!!actionParams.blessedAppSitecontainers || !!actionParams.siteContainers) { - return [new PublishProfileWebAppSiteContainersValidator()]; + return new PublishProfileWebAppSiteContainersValidator(); } else if (!!actionParams.images) { await this.setResourceDetails(actionParams); - return [new PublishProfileContainerWebAppValidator()]; + return new PublishProfileContainerWebAppValidator(); } else { try { @@ -35,7 +35,7 @@ export class ValidatorFactory { catch (error) { core.warning(`Failed to set resource details: ${error.message}`); } - return [new PublishProfileWebAppValidator()]; + return new PublishProfileWebAppValidator(); } } else if(type == DEPLOYMENT_PROVIDER_TYPES.SPN) { @@ -44,25 +44,22 @@ export class ValidatorFactory { await this.getResourceDetails(actionParams); if (!!actionParams.isLinux) { if (!!actionParams.siteContainers) { - if (await this.isBlessedSitecontainerApp(actionParams)) { - return [new SpnLinuxWebAppValidator(), new SpnWebAppSiteContainersValidator()]; - } - - return [new SpnWebAppSiteContainersValidator()]; + await this.setBlessedSitecontainerApp(actionParams); + return new SpnWebAppSiteContainersValidator(); } else if (!!actionParams.images || !!actionParams.multiContainerConfigFile) { - return [new SpnLinuxContainerWebAppValidator()]; + return new SpnLinuxContainerWebAppValidator(); } else { - return [new SpnLinuxWebAppValidator()]; + return new SpnLinuxWebAppValidator(); } } else { if (!!actionParams.images) { - return [new SpnWindowsContainerWebAppValidator()]; + return new SpnWindowsContainerWebAppValidator(); } else { - return [new SpnWindowsWebAppValidator()]; + return new SpnWindowsWebAppValidator(); } } } @@ -86,17 +83,18 @@ export class ValidatorFactory { actionParams.isLinux = appOS.includes(RuntimeConstants.Unix) || appOS.includes(RuntimeConstants.Unix.toLowerCase()); } - private static async isBlessedSitecontainerApp(actionParams: ActionParameters): Promise { + private static async setBlessedSitecontainerApp(actionParams: ActionParameters): Promise { const appService = new AzureAppService(actionParams.endpoint, actionParams.resourceGroupName, actionParams.appName, actionParams.slotName); let config = await appService.getConfiguration(); core.debug(`LinuxFxVersion of app is: ${config.properties.linuxFxVersion}`); - actionParams.blessedAppSitecontainers = (config.properties.linuxFxVersion?.startsWith("DOCKER|") !== true - && config.properties.linuxFxVersion?.startsWith("COMPOSE|") !== true - && config.properties.linuxFxVersion !== "SITECONTAINERS"); + const linuxFxVersion = config.properties.linuxFxVersion?.toUpperCase() || ""; + actionParams.blessedAppSitecontainers = (!linuxFxVersion.startsWith("DOCKER|") + && !linuxFxVersion.startsWith("COMPOSE|") + && linuxFxVersion !== "SITECONTAINERS"); - return actionParams.blessedAppSitecontainers; + core.debug(`Is blessed app sitecontainers: ${actionParams.blessedAppSitecontainers}`); } } diff --git a/src/DeploymentProvider/DeploymentProviderFactory.ts b/src/DeploymentProvider/DeploymentProviderFactory.ts index 20adc724f..36b42d19d 100644 --- a/src/DeploymentProvider/DeploymentProviderFactory.ts +++ b/src/DeploymentProvider/DeploymentProviderFactory.ts @@ -9,27 +9,24 @@ import { WebAppSiteContainersDeploymentProvider } from "./Providers/WebAppSiteCo export class DeploymentProviderFactory { - public static getDeploymentProvider(type: DEPLOYMENT_PROVIDER_TYPES) : IWebAppDeploymentProvider[] { + public static getDeploymentProvider(type: DEPLOYMENT_PROVIDER_TYPES) : IWebAppDeploymentProvider { if(type === DEPLOYMENT_PROVIDER_TYPES.PUBLISHPROFILE) { if (!!ActionParameters.getActionParams().images) { - return [new PublishProfileWebAppContainerDeploymentProvider(type)]; + return new PublishProfileWebAppContainerDeploymentProvider(type); } else { - return [new WebAppDeploymentProvider(type)]; + return new WebAppDeploymentProvider(type); } } else if(type == DEPLOYMENT_PROVIDER_TYPES.SPN) { - if (!!ActionParameters.getActionParams().blessedAppSitecontainers) { - return [new WebAppDeploymentProvider(type), new WebAppSiteContainersDeploymentProvider(type)]; - } - else if (!!ActionParameters.getActionParams().siteContainers) { - return [new WebAppSiteContainersDeploymentProvider(type)]; + if (!!ActionParameters.getActionParams().blessedAppSitecontainers || !!ActionParameters.getActionParams().siteContainers) { + return new WebAppSiteContainersDeploymentProvider(type); } else if(!!ActionParameters.getActionParams().images || (!!ActionParameters.getActionParams().isLinux && !!ActionParameters.getActionParams().multiContainerConfigFile)) { - return [new WebAppContainerDeploymentProvider(type)]; + return new WebAppContainerDeploymentProvider(type); } else { - return [new WebAppDeploymentProvider(type)]; + return new WebAppDeploymentProvider(type); } } else { diff --git a/src/DeploymentProvider/Providers/WebAppSiteContainersDeploymentProvider.ts b/src/DeploymentProvider/Providers/WebAppSiteContainersDeploymentProvider.ts index a280ace73..b3b9509fc 100644 --- a/src/DeploymentProvider/Providers/WebAppSiteContainersDeploymentProvider.ts +++ b/src/DeploymentProvider/Providers/WebAppSiteContainersDeploymentProvider.ts @@ -1,9 +1,16 @@ import { BaseWebAppDeploymentProvider } from './BaseWebAppDeploymentProvider'; import { SiteContainerDeploymentUtility } from 'azure-actions-appservice-rest/Utilities/SiteContainerDeploymentUtility'; import * as core from '@actions/core'; +import { WebAppDeploymentProvider } from './WebAppDeploymentProvider'; -export class WebAppSiteContainersDeploymentProvider extends BaseWebAppDeploymentProvider { +export class WebAppSiteContainersDeploymentProvider extends WebAppDeploymentProvider { public async DeployWebAppStep() { + + if(!!this.actionParams.blessedAppSitecontainers){ + core.info("Blessed site containers detected, using WebAppDeploymentProvider for deployment."); + await super.DeployWebAppStep(); + } + let siteContainerDeploymentUtility = new SiteContainerDeploymentUtility(this.appService); let siteContainers = this.actionParams.siteContainers; @@ -11,7 +18,7 @@ export class WebAppSiteContainersDeploymentProvider extends BaseWebAppDeployment for (let i = 0; i < siteContainers.length; i++) { let siteContainer = siteContainers[i]; - core.info("updating site container: " + siteContainer.getName); + core.info("updating site container: " + siteContainer.getName()); await siteContainerDeploymentUtility.updateSiteContainer(siteContainer); } } diff --git a/src/main.ts b/src/main.ts index e8927cadc..752c79395 100644 --- a/src/main.ts +++ b/src/main.ts @@ -34,19 +34,15 @@ export async function main() { } // Validate action inputs - let validators = await ValidatorFactory.getValidator(type); - for (const validator of validators) { - await validator.validate(); - } + let validator = await ValidatorFactory.getValidator(type); + await validator.validate(); - var deploymentProviders = DeploymentProviderFactory.getDeploymentProvider(type); + var deploymentProvider = DeploymentProviderFactory.getDeploymentProvider(type); - for (const provider of deploymentProviders) { - core.info("Predeployment Step Started"); - await provider.PreDeploymentStep(); - core.info("Deployment Step Started"); - await provider.DeployWebAppStep(); - } + core.info("Predeployment Step Started"); + await deploymentProvider.PreDeploymentStep(); + core.info("Deployment Step Started"); + await deploymentProvider.DeployWebAppStep(); } catch(error) { isDeploymentSuccess = false; @@ -60,8 +56,8 @@ export async function main() { } } finally { - if(deploymentProviders != null) { - await deploymentProviders[0].UpdateDeploymentStatus(isDeploymentSuccess); + if(deploymentProvider != null) { + await deploymentProvider.UpdateDeploymentStatus(isDeploymentSuccess); } // Reset AZURE_HTTP_USER_AGENT