Skip to content

Commit 66eae17

Browse files
authored
Add changes for Sitecontainers deployment (#461)
* Add changes for Sitecontainers deployment * Adding changes using single comit * resolved conflicts * Fixed test cases * resolving comments * resolving comments * resolve comments
1 parent 9ef6108 commit 66eae17

26 files changed

+824
-886
lines changed

__tests__/ActionInputValidator/ValidatorFactory.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ describe('Test Validator Factory', () => {
2626
jest.spyOn(PublishProfile, 'getPublishProfile').mockImplementation(() => PublishProfile.prototype);
2727
jest.spyOn(PublishProfile.prototype, 'getAppOS').mockImplementation(async() => 'unix');
2828

29-
let validator = await ValidatorFactory.getValidator(type);
30-
expect(validator).toBeInstanceOf(PublishProfileWebAppValidator);
29+
let validators = await ValidatorFactory.getValidator(type);
30+
expect(validators[0]).toBeInstanceOf(PublishProfileWebAppValidator);
3131
});
3232

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

45-
let validator = await ValidatorFactory.getValidator(type);
46-
expect(validator).toBeInstanceOf(PublishProfileContainerWebAppValidator);
45+
let validators = await ValidatorFactory.getValidator(type);
46+
expect(validators[0]).toBeInstanceOf(PublishProfileContainerWebAppValidator);
4747
});
4848

4949
});
@@ -70,8 +70,8 @@ describe('Test Validator Factory', () => {
7070
};
7171
});
7272

73-
let validator = await ValidatorFactory.getValidator(type);
74-
expect(validator).toBeInstanceOf(SpnLinuxContainerWebAppValidator);
73+
let validators = await ValidatorFactory.getValidator(type);
74+
expect(validators[0]).toBeInstanceOf(SpnLinuxContainerWebAppValidator);
7575
});
7676

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

93-
let validator = await ValidatorFactory.getValidator(type);
94-
expect(validator).toBeInstanceOf(SpnLinuxWebAppValidator);
93+
let validators = await ValidatorFactory.getValidator(type);
94+
expect(validators[0]).toBeInstanceOf(SpnLinuxWebAppValidator);
9595
});
9696

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

114-
let validator = await ValidatorFactory.getValidator(type);
115-
expect(validator).toBeInstanceOf(SpnWindowsContainerWebAppValidator);
114+
let validators = await ValidatorFactory.getValidator(type);
115+
expect(validators[0]).toBeInstanceOf(SpnWindowsContainerWebAppValidator);
116116
});
117117

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

134-
let validator = await ValidatorFactory.getValidator(type);
135-
expect(validator).toBeInstanceOf(SpnWindowsWebAppValidator);
134+
let validators = await ValidatorFactory.getValidator(type);
135+
expect(validators[0]).toBeInstanceOf(SpnWindowsWebAppValidator);
136136
});
137137

138138
});

__tests__/DeploymentProvider/DeploymentProviderFactory.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ describe('Test Deployment Provider Factory', () => {
1919
it("Get Code Deployment Provider for Publish Profile auth flow", async() => {
2020
let type: DEPLOYMENT_PROVIDER_TYPES = DEPLOYMENT_PROVIDER_TYPES.PUBLISHPROFILE;
2121

22-
let provider = await DeploymentProviderFactory.getDeploymentProvider(type);
23-
expect(provider).toBeInstanceOf(WebAppDeploymentProvider);
22+
let providers = await DeploymentProviderFactory.getDeploymentProvider(type);
23+
expect(providers[0]).toBeInstanceOf(WebAppDeploymentProvider);
2424
});
2525

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

3333
let type: DEPLOYMENT_PROVIDER_TYPES = DEPLOYMENT_PROVIDER_TYPES.PUBLISHPROFILE;
3434

35-
let provider = await DeploymentProviderFactory.getDeploymentProvider(type);
36-
expect(provider).toBeInstanceOf(PublishProfileWebAppContainerDeploymentProvider);
35+
let providers = await DeploymentProviderFactory.getDeploymentProvider(type);
36+
expect(providers[0]).toBeInstanceOf(PublishProfileWebAppContainerDeploymentProvider);
3737
});
3838

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

4949
let type: DEPLOYMENT_PROVIDER_TYPES = DEPLOYMENT_PROVIDER_TYPES.SPN;
5050

51-
let provider = await DeploymentProviderFactory.getDeploymentProvider(type);
52-
expect(provider).toBeInstanceOf(WebAppDeploymentProvider);
51+
let providers = await DeploymentProviderFactory.getDeploymentProvider(type);
52+
expect(providers[0]).toBeInstanceOf(WebAppDeploymentProvider);
5353
});
5454

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

6262
let type: DEPLOYMENT_PROVIDER_TYPES = DEPLOYMENT_PROVIDER_TYPES.SPN;
6363

64-
let provider = await DeploymentProviderFactory.getDeploymentProvider(type);
65-
expect(provider).toBeInstanceOf(WebAppContainerDeploymentProvider);
64+
let providers = await DeploymentProviderFactory.getDeploymentProvider(type);
65+
expect(providers[0]).toBeInstanceOf(WebAppContainerDeploymentProvider);
6666
});
6767

6868
});

__tests__/main.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ describe('Test azure-webapps-deploy', () => {
3535
}
3636
return '';
3737
});
38-
let getValidatorFactorySpy = jest.spyOn(ValidatorFactory, 'getValidator').mockImplementation(async _type => new PublishProfileWebAppValidator());
38+
let getValidatorFactorySpy = jest.spyOn(ValidatorFactory, 'getValidator').mockImplementation(async _type => [new PublishProfileWebAppValidator()]);
3939
let ValidatorFactoryValidateSpy = jest.spyOn(PublishProfileWebAppValidator.prototype, 'validate');
40-
let getDeploymentProviderSpy = jest.spyOn(DeploymentProviderFactory, 'getDeploymentProvider').mockImplementation(type => new WebAppDeploymentProvider(type));
40+
let getDeploymentProviderSpy = jest.spyOn(DeploymentProviderFactory, 'getDeploymentProvider').mockImplementation(type => [new WebAppDeploymentProvider(type)]);
4141
let deployWebAppStepSpy = jest.spyOn(WebAppDeploymentProvider.prototype, 'DeployWebAppStep');
4242
let updateDeploymentStatusSpy = jest.spyOn(WebAppDeploymentProvider.prototype, 'UpdateDeploymentStatus');
4343

action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ inputs:
4040
restart:
4141
description: 'Restart the app service after deployment'
4242
required: false
43-
43+
sitecontainers-config:
44+
description: 'Applies to Sitecontainers, containes a list of siteContainer specs'
45+
required: false
46+
4447
outputs:
4548
webapp-url:
4649
description: 'URL to work with your webapp'

lib/ActionInputValidator/ActionValidators/PublishProfileContainerWebAppValidator.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class PublishProfileContainerWebAppValidator {
1919
(0, Validations_1.packageNotAllowed)(actionParams.packageInput);
2020
(0, Validations_1.multiContainerNotAllowed)(actionParams.multiContainerConfigFile);
2121
(0, Validations_1.startupCommandNotAllowed)(actionParams.startupCommand);
22+
(0, Validations_1.siteContainersConfigNotAllowed)(actionParams.siteContainers);
2223
(0, Validations_1.validateAppDetails)();
2324
(0, Validations_1.validateSingleContainerInputs)();
2425
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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.PublishProfileWebAppSiteContainersValidator = void 0;
13+
class PublishProfileWebAppSiteContainersValidator {
14+
validate() {
15+
return __awaiter(this, void 0, void 0, function* () {
16+
throw new Error("publish-profile is not supported for Site Containers scenario");
17+
});
18+
}
19+
}
20+
exports.PublishProfileWebAppSiteContainersValidator = PublishProfileWebAppSiteContainersValidator;

lib/ActionInputValidator/ActionValidators/PublishProfileWebAppValidator.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class PublishProfileWebAppValidator {
1919
(0, Validations_1.containerInputsNotAllowed)(actionParams.images, actionParams.multiContainerConfigFile, true);
2020
(0, Validations_1.validateAppDetails)();
2121
(0, Validations_1.startupCommandNotAllowed)(actionParams.startupCommand);
22+
(0, Validations_1.siteContainersConfigNotAllowed)(actionParams.siteContainers);
2223
yield (0, Validations_1.validatePackageInput)();
2324
});
2425
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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.SpnWebAppSiteContainersValidator = void 0;
13+
const Validations_1 = require("../Validations");
14+
class SpnWebAppSiteContainersValidator {
15+
validate() {
16+
return __awaiter(this, void 0, void 0, function* () {
17+
(0, Validations_1.validateSiteContainersInputs)();
18+
});
19+
}
20+
}
21+
exports.SpnWebAppSiteContainersValidator = SpnWebAppSiteContainersValidator;

lib/ActionInputValidator/Validations.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ exports.multiContainerNotAllowed = multiContainerNotAllowed;
5151
exports.validateSingleContainerInputs = validateSingleContainerInputs;
5252
exports.validateContainerInputs = validateContainerInputs;
5353
exports.validatePackageInput = validatePackageInput;
54+
exports.siteContainersConfigNotAllowed = siteContainersConfigNotAllowed;
55+
exports.validateSiteContainersInputs = validateSiteContainersInputs;
5456
const core = __importStar(require("@actions/core"));
5557
const packageUtility_1 = require("azure-actions-utility/packageUtility");
5658
const PublishProfile_1 = require("../Utilities/PublishProfile");
@@ -146,3 +148,16 @@ function validatePackageInput() {
146148
}
147149
});
148150
}
151+
// Error if Sitecontainers configuration is provided
152+
function siteContainersConfigNotAllowed(siteContainers) {
153+
if (!!siteContainers) {
154+
throw new Error("SiteContainers not valid input for this web app.");
155+
}
156+
}
157+
// validate Sitecontainers inputs
158+
function validateSiteContainersInputs() {
159+
const actionParams = actionparameters_1.ActionParameters.getActionParams();
160+
if (!actionParams.siteContainers || actionParams.siteContainers.length === 0) {
161+
throw new Error("Site containers not provided.");
162+
}
163+
}

lib/ActionInputValidator/ValidatorFactory.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,20 @@ const SpnWindowsWebAppValidator_1 = require("./ActionValidators/SpnWindowsWebApp
5959
const Validations_1 = require("./Validations");
6060
const PublishProfile_1 = require("../Utilities/PublishProfile");
6161
const RuntimeConstants_1 = __importDefault(require("../RuntimeConstants"));
62+
const SpnWebAppSiteContainersValidator_1 = require("./ActionValidators/SpnWebAppSiteContainersValidator");
63+
const PublishProfileWebAppSiteContainersValidator_1 = require("./ActionValidators/PublishProfileWebAppSiteContainersValidator");
64+
const azure_app_service_1 = require("azure-actions-appservice-rest/Arm/azure-app-service");
6265
class ValidatorFactory {
6366
static getValidator(type) {
6467
return __awaiter(this, void 0, void 0, function* () {
6568
let actionParams = actionparameters_1.ActionParameters.getActionParams();
6669
if (type === BaseWebAppDeploymentProvider_1.DEPLOYMENT_PROVIDER_TYPES.PUBLISHPROFILE) {
67-
if (!!actionParams.images) {
70+
if (!!actionParams.blessedAppSitecontainers || !!actionParams.siteContainers) {
71+
return [new PublishProfileWebAppSiteContainersValidator_1.PublishProfileWebAppSiteContainersValidator()];
72+
}
73+
else if (!!actionParams.images) {
6874
yield this.setResourceDetails(actionParams);
69-
return new PublishProfileContainerWebAppValidator_1.PublishProfileContainerWebAppValidator();
75+
return [new PublishProfileContainerWebAppValidator_1.PublishProfileContainerWebAppValidator()];
7076
}
7177
else {
7278
try {
@@ -75,27 +81,33 @@ class ValidatorFactory {
7581
catch (error) {
7682
core.warning(`Failed to set resource details: ${error.message}`);
7783
}
78-
return new PublishProfileWebAppValidator_1.PublishProfileWebAppValidator();
84+
return [new PublishProfileWebAppValidator_1.PublishProfileWebAppValidator()];
7985
}
8086
}
8187
else if (type == BaseWebAppDeploymentProvider_1.DEPLOYMENT_PROVIDER_TYPES.SPN) {
8288
// app-name is required to get resource details
8389
(0, Validations_1.appNameIsRequired)(actionParams.appName);
8490
yield this.getResourceDetails(actionParams);
8591
if (!!actionParams.isLinux) {
86-
if (!!actionParams.images || !!actionParams.multiContainerConfigFile) {
87-
return new SpnLinuxContainerWebAppValidator_1.SpnLinuxContainerWebAppValidator();
92+
if (!!actionParams.siteContainers) {
93+
if (yield this.isBlessedSitecontainerApp(actionParams)) {
94+
return [new SpnLinuxWebAppValidator_1.SpnLinuxWebAppValidator(), new SpnWebAppSiteContainersValidator_1.SpnWebAppSiteContainersValidator()];
95+
}
96+
return [new SpnWebAppSiteContainersValidator_1.SpnWebAppSiteContainersValidator()];
97+
}
98+
else if (!!actionParams.images || !!actionParams.multiContainerConfigFile) {
99+
return [new SpnLinuxContainerWebAppValidator_1.SpnLinuxContainerWebAppValidator()];
88100
}
89101
else {
90-
return new SpnLinuxWebAppValidator_1.SpnLinuxWebAppValidator();
102+
return [new SpnLinuxWebAppValidator_1.SpnLinuxWebAppValidator()];
91103
}
92104
}
93105
else {
94106
if (!!actionParams.images) {
95-
return new SpnWindowsContainerWebAppValidator_1.SpnWindowsContainerWebAppValidator();
107+
return [new SpnWindowsContainerWebAppValidator_1.SpnWindowsContainerWebAppValidator()];
96108
}
97109
else {
98-
return new SpnWindowsWebAppValidator_1.SpnWindowsWebAppValidator();
110+
return [new SpnWindowsWebAppValidator_1.SpnWindowsWebAppValidator()];
99111
}
100112
}
101113
}
@@ -121,5 +133,17 @@ class ValidatorFactory {
121133
actionParams.isLinux = appOS.includes(RuntimeConstants_1.default.Unix) || appOS.includes(RuntimeConstants_1.default.Unix.toLowerCase());
122134
});
123135
}
136+
static isBlessedSitecontainerApp(actionParams) {
137+
return __awaiter(this, void 0, void 0, function* () {
138+
var _a, _b;
139+
const appService = new azure_app_service_1.AzureAppService(actionParams.endpoint, actionParams.resourceGroupName, actionParams.appName, actionParams.slotName);
140+
let config = yield appService.getConfiguration();
141+
core.debug(`LinuxFxVersion of app is: ${config.properties.linuxFxVersion}`);
142+
actionParams.blessedAppSitecontainers = (((_a = config.properties.linuxFxVersion) === null || _a === void 0 ? void 0 : _a.startsWith("DOCKER|")) !== true
143+
&& ((_b = config.properties.linuxFxVersion) === null || _b === void 0 ? void 0 : _b.startsWith("COMPOSE|")) !== true
144+
&& config.properties.linuxFxVersion !== "SITECONTAINERS");
145+
return actionParams.blessedAppSitecontainers;
146+
});
147+
}
124148
}
125149
exports.ValidatorFactory = ValidatorFactory;

0 commit comments

Comments
 (0)