Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
24 changes: 12 additions & 12 deletions __tests__/ActionInputValidator/ValidatorFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ describe('Test Validator Factory', () => {
jest.spyOn(PublishProfile, 'getPublishProfile').mockImplementation(() => PublishProfile.prototype);
jest.spyOn(PublishProfile.prototype, 'getAppOS').mockImplementation(async() => 'unix');

let validator = await ValidatorFactory.getValidator(type);
expect(validator).toBeInstanceOf(PublishProfileWebAppValidator);
let validators = await ValidatorFactory.getValidator(type);
expect(validators[0]).toBeInstanceOf(PublishProfileWebAppValidator);
});

it("Get Container Validator for Publish Profile auth flow", async() => {
Expand All @@ -42,8 +42,8 @@ describe('Test Validator Factory', () => {
jest.spyOn(PublishProfile, 'getPublishProfile').mockImplementation(() => PublishProfile.prototype);
jest.spyOn(PublishProfile.prototype, 'getAppOS').mockImplementation(async() => 'unix');

let validator = await ValidatorFactory.getValidator(type);
expect(validator).toBeInstanceOf(PublishProfileContainerWebAppValidator);
let validators = await ValidatorFactory.getValidator(type);
expect(validators[0]).toBeInstanceOf(PublishProfileContainerWebAppValidator);
});

});
Expand All @@ -70,8 +70,8 @@ describe('Test Validator Factory', () => {
};
});

let validator = await ValidatorFactory.getValidator(type);
expect(validator).toBeInstanceOf(SpnLinuxContainerWebAppValidator);
let validators = await ValidatorFactory.getValidator(type);
expect(validators[0]).toBeInstanceOf(SpnLinuxContainerWebAppValidator);
});

it("Get Linux/Kube Code Validator for SPN auth flow", async() => {
Expand All @@ -90,8 +90,8 @@ describe('Test Validator Factory', () => {
};
});

let validator = await ValidatorFactory.getValidator(type);
expect(validator).toBeInstanceOf(SpnLinuxWebAppValidator);
let validators = await ValidatorFactory.getValidator(type);
expect(validators[0]).toBeInstanceOf(SpnLinuxWebAppValidator);
});

it("Get Windows Container Validator for SPN auth flow", async() => {
Expand All @@ -111,8 +111,8 @@ describe('Test Validator Factory', () => {
};
});

let validator = await ValidatorFactory.getValidator(type);
expect(validator).toBeInstanceOf(SpnWindowsContainerWebAppValidator);
let validators = await ValidatorFactory.getValidator(type);
expect(validators[0]).toBeInstanceOf(SpnWindowsContainerWebAppValidator);
});

it("Get Windows Code Validator for SPN auth flow", async() => {
Expand All @@ -131,8 +131,8 @@ describe('Test Validator Factory', () => {
};
});

let validator = await ValidatorFactory.getValidator(type);
expect(validator).toBeInstanceOf(SpnWindowsWebAppValidator);
let validators = await ValidatorFactory.getValidator(type);
expect(validators[0]).toBeInstanceOf(SpnWindowsWebAppValidator);
});

});
Expand Down
16 changes: 8 additions & 8 deletions __tests__/DeploymentProvider/DeploymentProviderFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 provider = await DeploymentProviderFactory.getDeploymentProvider(type);
expect(provider).toBeInstanceOf(WebAppDeploymentProvider);
let providers = await DeploymentProviderFactory.getDeploymentProvider(type);
expect(providers[0]).toBeInstanceOf(WebAppDeploymentProvider);
});

it("Get Container Deployment Provider for Publish Profile auth flow", async() => {
Expand All @@ -32,8 +32,8 @@ describe('Test Deployment Provider Factory', () => {

let type: DEPLOYMENT_PROVIDER_TYPES = DEPLOYMENT_PROVIDER_TYPES.PUBLISHPROFILE;

let provider = await DeploymentProviderFactory.getDeploymentProvider(type);
expect(provider).toBeInstanceOf(PublishProfileWebAppContainerDeploymentProvider);
let providers = await DeploymentProviderFactory.getDeploymentProvider(type);
expect(providers[0]).toBeInstanceOf(PublishProfileWebAppContainerDeploymentProvider);
});

});
Expand All @@ -48,8 +48,8 @@ describe('Test Deployment Provider Factory', () => {

let type: DEPLOYMENT_PROVIDER_TYPES = DEPLOYMENT_PROVIDER_TYPES.SPN;

let provider = await DeploymentProviderFactory.getDeploymentProvider(type);
expect(provider).toBeInstanceOf(WebAppDeploymentProvider);
let providers = await DeploymentProviderFactory.getDeploymentProvider(type);
expect(providers[0]).toBeInstanceOf(WebAppDeploymentProvider);
});

it("Get Container Deployment Provider for SPN auth flow", async() => {
Expand All @@ -61,8 +61,8 @@ describe('Test Deployment Provider Factory', () => {

let type: DEPLOYMENT_PROVIDER_TYPES = DEPLOYMENT_PROVIDER_TYPES.SPN;

let provider = await DeploymentProviderFactory.getDeploymentProvider(type);
expect(provider).toBeInstanceOf(WebAppContainerDeploymentProvider);
let providers = await DeploymentProviderFactory.getDeploymentProvider(type);
expect(providers[0]).toBeInstanceOf(WebAppContainerDeploymentProvider);
});

});
Expand Down
4 changes: 2 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ inputs:
restart:
description: 'Restart the app service after deployment'
required: false

sitecontainers-config:
description: 'Applies to Sitecontainers, containes a list of siteContainer specs'
required: false

outputs:
webapp-url:
description: 'URL to work with your webapp'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class PublishProfileContainerWebAppValidator {
(0, Validations_1.packageNotAllowed)(actionParams.packageInput);
(0, Validations_1.multiContainerNotAllowed)(actionParams.multiContainerConfigFile);
(0, Validations_1.startupCommandNotAllowed)(actionParams.startupCommand);
(0, Validations_1.siteContainersConfigNotAllowed)(actionParams.siteContainers);
(0, Validations_1.validateAppDetails)();
(0, Validations_1.validateSingleContainerInputs)();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PublishProfileWebAppSiteContainersValidator = void 0;
class PublishProfileWebAppSiteContainersValidator {
validate() {
return __awaiter(this, void 0, void 0, function* () {
throw new Error("publish-profile is not supported for Site Containers scenario");
});
}
}
exports.PublishProfileWebAppSiteContainersValidator = PublishProfileWebAppSiteContainersValidator;
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class PublishProfileWebAppValidator {
(0, Validations_1.containerInputsNotAllowed)(actionParams.images, actionParams.multiContainerConfigFile, true);
(0, Validations_1.validateAppDetails)();
(0, Validations_1.startupCommandNotAllowed)(actionParams.startupCommand);
(0, Validations_1.siteContainersConfigNotAllowed)(actionParams.siteContainers);
yield (0, Validations_1.validatePackageInput)();
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SpnWebAppSiteContainersValidator = void 0;
const Validations_1 = require("../Validations");
class SpnWebAppSiteContainersValidator {
validate() {
return __awaiter(this, void 0, void 0, function* () {
(0, Validations_1.validateSiteContainersInputs)();
});
}
}
exports.SpnWebAppSiteContainersValidator = SpnWebAppSiteContainersValidator;
15 changes: 15 additions & 0 deletions lib/ActionInputValidator/Validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ exports.multiContainerNotAllowed = multiContainerNotAllowed;
exports.validateSingleContainerInputs = validateSingleContainerInputs;
exports.validateContainerInputs = validateContainerInputs;
exports.validatePackageInput = validatePackageInput;
exports.siteContainersConfigNotAllowed = siteContainersConfigNotAllowed;
exports.validateSiteContainersInputs = validateSiteContainersInputs;
const core = __importStar(require("@actions/core"));
const packageUtility_1 = require("azure-actions-utility/packageUtility");
const PublishProfile_1 = require("../Utilities/PublishProfile");
Expand Down Expand Up @@ -146,3 +148,16 @@ function validatePackageInput() {
}
});
}
// Error if Sitecontainers configuration is provided
function siteContainersConfigNotAllowed(siteContainers) {
if (!!siteContainers) {
throw new Error("SiteContainers not valid input for this web app.");
}
}
// validate Sitecontainers inputs
function validateSiteContainersInputs() {
const actionParams = actionparameters_1.ActionParameters.getActionParams();
if (!actionParams.siteContainers || actionParams.siteContainers.length === 0) {
throw new Error("Site containers not provided.");
}
}
41 changes: 33 additions & 8 deletions lib/ActionInputValidator/ValidatorFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,20 @@ const SpnWindowsWebAppValidator_1 = require("./ActionValidators/SpnWindowsWebApp
const Validations_1 = require("./Validations");
const PublishProfile_1 = require("../Utilities/PublishProfile");
const RuntimeConstants_1 = __importDefault(require("../RuntimeConstants"));
const SpnWebAppSiteContainersValidator_1 = require("./ActionValidators/SpnWebAppSiteContainersValidator");
const PublishProfileWebAppSiteContainersValidator_1 = require("./ActionValidators/PublishProfileWebAppSiteContainersValidator");
const azure_app_service_1 = require("azure-actions-appservice-rest/Arm/azure-app-service");
class ValidatorFactory {
static getValidator(type) {
return __awaiter(this, void 0, void 0, function* () {
let actionParams = actionparameters_1.ActionParameters.getActionParams();
if (type === BaseWebAppDeploymentProvider_1.DEPLOYMENT_PROVIDER_TYPES.PUBLISHPROFILE) {
if (!!actionParams.images) {
if (!!actionParams.blessedAppSitecontainers || !!actionParams.siteContainers) {
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 {
Expand All @@ -75,27 +81,33 @@ 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) {
// app-name is required to get resource details
(0, Validations_1.appNameIsRequired)(actionParams.appName);
yield this.getResourceDetails(actionParams);
if (!!actionParams.isLinux) {
if (!!actionParams.images || !!actionParams.multiContainerConfigFile) {
return new SpnLinuxContainerWebAppValidator_1.SpnLinuxContainerWebAppValidator();
if (!!actionParams.siteContainers) {
if (yield this.isBlessedSitecontainerApp(actionParams)) {
return [new SpnLinuxWebAppValidator_1.SpnLinuxWebAppValidator(), new SpnWebAppSiteContainersValidator_1.SpnWebAppSiteContainersValidator()];
}
return [new SpnWebAppSiteContainersValidator_1.SpnWebAppSiteContainersValidator()];
}
else if (!!actionParams.images || !!actionParams.multiContainerConfigFile) {
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()];
}
}
}
Expand All @@ -121,5 +133,18 @@ class ValidatorFactory {
actionParams.isLinux = appOS.includes(RuntimeConstants_1.default.Unix) || appOS.includes(RuntimeConstants_1.default.Unix.toLowerCase());
});
}
static isBlessedSitecontainerApp(actionParams) {
return __awaiter(this, void 0, void 0, function* () {
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}`);
const linuxFxVersion = ((_a = config.properties.linuxFxVersion) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || "";
actionParams.blessedAppSitecontainers = (!linuxFxVersion.startsWith("DOCKER|")
&& !linuxFxVersion.startsWith("COMPOSE|")
&& linuxFxVersion !== "SITECONTAINERS");
return actionParams.blessedAppSitecontainers;
});
}
}
exports.ValidatorFactory = ValidatorFactory;
Loading
Loading