setup base stack automatically

pull/289/head
Frostebite 2021-08-08 10:20:52 +01:00
parent ba2931a765
commit 7d7846249a
4 changed files with 30 additions and 8 deletions

View File

@ -9,8 +9,11 @@ Parameters:
Description: "Your deployment environment: DEV, QA , PROD" Description: "Your deployment environment: DEV, QA , PROD"
Storage: Storage:
Type: String Type: String
Default: development Default: game-ci-storage
Description: "Your deployment environment: DEV, QA , PROD" Description: "Your s3 storage bucket"
Version:
Type: String
Description: "hash of template"
# ContainerPort: # ContainerPort:
# Type: Number # Type: Number

15
dist/index.js vendored
View File

@ -856,6 +856,7 @@ const fs = __importStar(__webpack_require__(35747));
const core = __importStar(__webpack_require__(42186)); const core = __importStar(__webpack_require__(42186));
const remote_builder_constants_1 = __importDefault(__webpack_require__(92560)); const remote_builder_constants_1 = __importDefault(__webpack_require__(92560));
const aws_build_runner_1 = __importDefault(__webpack_require__(11201)); const aws_build_runner_1 = __importDefault(__webpack_require__(11201));
const crypto = __webpack_require__(33373);
class AWSBuildEnvironment { class AWSBuildEnvironment {
constructor(buildParameters) { constructor(buildParameters) {
this.stackName = buildParameters.awsStackName; this.stackName = buildParameters.awsStackName;
@ -1022,10 +1023,11 @@ class AWSBuildEnvironment {
}); });
} }
setupBaseStack(CF) { setupBaseStack(CF) {
var _a, _b, _c; var _a, _b, _c, _d, _e, _f;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const baseStackName = process.env.baseStackName || 'game-ci-base-stack-01'; const baseStackName = process.env.baseStackName || 'game-ci-base-stack-01';
const baseStack = fs.readFileSync(`${__dirname}/cloud-formations/base-setup.yml`, 'utf8'); const baseStack = fs.readFileSync(`${__dirname}/cloud-formations/base-setup.yml`, 'utf8');
const hash = crypto.createHash('md5').update(baseStack).digest('hex');
const describeStackInput = { const describeStackInput = {
StackName: baseStackName, StackName: baseStackName,
}; };
@ -1038,6 +1040,7 @@ class AWSBuildEnvironment {
Parameters: [ Parameters: [
{ ParameterKey: 'EnvironmentName', ParameterValue: 'development' }, { ParameterKey: 'EnvironmentName', ParameterValue: 'development' },
{ ParameterKey: 'Storage', ParameterValue: `${baseStackName}-storage` }, { ParameterKey: 'Storage', ParameterValue: `${baseStackName}-storage` },
{ ParameterKey: 'Version', ParameterValue: `hash` },
], ],
}); });
CFState = yield CF.describeStacks(describeStackInput).promise(); CFState = yield CF.describeStacks(describeStackInput).promise();
@ -1047,18 +1050,22 @@ class AWSBuildEnvironment {
if (!stack) { if (!stack) {
throw new Error('expected base stack to exist'); throw new Error('expected base stack to exist');
} }
if (stack.StackName === baseStackName) { if (stack.StackName === baseStackName &&
hash !== ((_c = (_b = stack.Parameters) === null || _b === void 0 ? void 0 : _b.find((x) => x.ParameterKey === 'Version')) === null || _c === void 0 ? void 0 : _c.ParameterValue)) {
const updateInput = { const updateInput = {
StackName: baseStackName, StackName: baseStackName,
TemplateBody: baseStack, TemplateBody: baseStack,
}; };
yield CF.updateStack(updateInput).promise(); yield CF.updateStack(updateInput).promise();
} }
else {
core.info(`Skipping any update for base stack ${stack.StackName} ${(_d = stack.Parameters) === null || _d === void 0 ? void 0 : _d.find((x) => x.ParameterKey === 'Version')}`);
}
} }
if (((_b = CFState.Stacks) === null || _b === void 0 ? void 0 : _b[0].StackStatus) === 'CREATE_IN_PROGRESS') { if (((_e = CFState.Stacks) === null || _e === void 0 ? void 0 : _e[0].StackStatus) === 'CREATE_IN_PROGRESS') {
yield CF.waitFor('stackCreateComplete', describeStackInput).promise(); yield CF.waitFor('stackCreateComplete', describeStackInput).promise();
} }
else if (((_c = CFState.Stacks) === null || _c === void 0 ? void 0 : _c[0].StackStatus) === 'UPDATE_IN_PROGRESS') { else if (((_f = CFState.Stacks) === null || _f === void 0 ? void 0 : _f[0].StackStatus) === 'UPDATE_IN_PROGRESS') {
yield CF.waitFor('stackUpdateComplete', describeStackInput).promise(); yield CF.waitFor('stackUpdateComplete', describeStackInput).promise();
} }
}); });

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -9,6 +9,7 @@ import RemoteBuilderConstants from './remote-builder-constants';
import AWSBuildRunner from './aws-build-runner'; import AWSBuildRunner from './aws-build-runner';
import { RemoteBuilderProviderInterface } from './remote-builder-provider-interface'; import { RemoteBuilderProviderInterface } from './remote-builder-provider-interface';
import BuildParameters from '../build-parameters'; import BuildParameters from '../build-parameters';
const crypto = require('crypto');
class AWSBuildEnvironment implements RemoteBuilderProviderInterface { class AWSBuildEnvironment implements RemoteBuilderProviderInterface {
private stackName: string; private stackName: string;
@ -232,6 +233,7 @@ class AWSBuildEnvironment implements RemoteBuilderProviderInterface {
async setupBaseStack(CF: SDK.CloudFormation) { async setupBaseStack(CF: SDK.CloudFormation) {
const baseStackName = process.env.baseStackName || 'game-ci-base-stack-01'; const baseStackName = process.env.baseStackName || 'game-ci-base-stack-01';
const baseStack = fs.readFileSync(`${__dirname}/cloud-formations/base-setup.yml`, 'utf8'); const baseStack = fs.readFileSync(`${__dirname}/cloud-formations/base-setup.yml`, 'utf8');
const hash = crypto.createHash('md5').update(baseStack).digest('hex');
const describeStackInput: SDK.CloudFormation.DescribeStacksInput = { const describeStackInput: SDK.CloudFormation.DescribeStacksInput = {
StackName: baseStackName, StackName: baseStackName,
}; };
@ -244,6 +246,7 @@ class AWSBuildEnvironment implements RemoteBuilderProviderInterface {
Parameters: [ Parameters: [
{ ParameterKey: 'EnvironmentName', ParameterValue: 'development' }, { ParameterKey: 'EnvironmentName', ParameterValue: 'development' },
{ ParameterKey: 'Storage', ParameterValue: `${baseStackName}-storage` }, { ParameterKey: 'Storage', ParameterValue: `${baseStackName}-storage` },
{ ParameterKey: 'Version', ParameterValue: `hash` },
], ],
}); });
CFState = await CF.describeStacks(describeStackInput).promise(); CFState = await CF.describeStacks(describeStackInput).promise();
@ -252,12 +255,21 @@ class AWSBuildEnvironment implements RemoteBuilderProviderInterface {
if (!stack) { if (!stack) {
throw new Error('expected base stack to exist'); throw new Error('expected base stack to exist');
} }
if (stack.StackName === baseStackName) { if (
stack.StackName === baseStackName &&
hash !== stack.Parameters?.find((x) => x.ParameterKey === 'Version')?.ParameterValue
) {
const updateInput: SDK.CloudFormation.UpdateStackInput = { const updateInput: SDK.CloudFormation.UpdateStackInput = {
StackName: baseStackName, StackName: baseStackName,
TemplateBody: baseStack, TemplateBody: baseStack,
}; };
await CF.updateStack(updateInput).promise(); await CF.updateStack(updateInput).promise();
} else {
core.info(
`Skipping any update for base stack ${stack.StackName} ${stack.Parameters?.find(
(x) => x.ParameterKey === 'Version',
)}`,
);
} }
} }
if (CFState.Stacks?.[0].StackStatus === 'CREATE_IN_PROGRESS') { if (CFState.Stacks?.[0].StackStatus === 'CREATE_IN_PROGRESS') {