setup base stack automatically

pull/289/head
Frostebite 2021-08-08 10:05:16 +01:00
parent a35c029939
commit ba2931a765
3 changed files with 52 additions and 28 deletions

40
dist/index.js vendored
View File

@ -1022,22 +1022,16 @@ class AWSBuildEnvironment {
});
}
setupBaseStack(CF) {
var _a;
var _a, _b, _c;
return __awaiter(this, void 0, void 0, function* () {
let createBaseStack = true;
const baseStackName = process.env.baseStackName || 'game-ci-base-stack-01';
const baseStack = fs.readFileSync(`${__dirname}/cloud-formations/base-setup.yml`, 'utf8');
for (const stack of ((_a = (yield CF.listStacks().promise())) === null || _a === void 0 ? void 0 : _a.StackSummaries) || []) {
if (stack.StackName === baseStackName) {
const updateInput = {
StackName: baseStackName,
TemplateBody: baseStack,
};
yield CF.updateStack(updateInput).promise();
createBaseStack = false;
}
}
if (createBaseStack) {
const describeStackInput = {
StackName: baseStackName,
};
let CFState = yield CF.describeStacks(describeStackInput).promise();
const stackExists = CFState.Stacks === null || CFState.Stacks === [];
if (stackExists) {
yield CF.createStack({
StackName: baseStackName,
TemplateBody: baseStack,
@ -1046,6 +1040,26 @@ class AWSBuildEnvironment {
{ ParameterKey: 'Storage', ParameterValue: `${baseStackName}-storage` },
],
});
CFState = yield CF.describeStacks(describeStackInput).promise();
}
else {
const stack = (_a = CFState.Stacks) === null || _a === void 0 ? void 0 : _a[0];
if (!stack) {
throw new Error('expected base stack to exist');
}
if (stack.StackName === baseStackName) {
const updateInput = {
StackName: baseStackName,
TemplateBody: baseStack,
};
yield CF.updateStack(updateInput).promise();
}
}
if (((_b = CFState.Stacks) === null || _b === void 0 ? void 0 : _b[0].StackStatus) === 'CREATE_IN_PROGRESS') {
yield CF.waitFor('stackCreateComplete', describeStackInput).promise();
}
else if (((_c = CFState.Stacks) === null || _c === void 0 ? void 0 : _c[0].StackStatus) === 'UPDATE_IN_PROGRESS') {
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

@ -230,20 +230,14 @@ class AWSBuildEnvironment implements RemoteBuilderProviderInterface {
}
async setupBaseStack(CF: SDK.CloudFormation) {
let createBaseStack: Boolean = true;
const baseStackName = process.env.baseStackName || 'game-ci-base-stack-01';
const baseStack = fs.readFileSync(`${__dirname}/cloud-formations/base-setup.yml`, 'utf8');
for (const stack of (await CF.listStacks().promise())?.StackSummaries || []) {
if (stack.StackName === baseStackName) {
const updateInput: SDK.CloudFormation.UpdateStackInput = {
StackName: baseStackName,
TemplateBody: baseStack,
};
await CF.updateStack(updateInput).promise();
createBaseStack = false;
}
}
if (createBaseStack) {
const describeStackInput: SDK.CloudFormation.DescribeStacksInput = {
StackName: baseStackName,
};
let CFState = await CF.describeStacks(describeStackInput).promise();
const stackExists: Boolean = CFState.Stacks === null || CFState.Stacks === [];
if (stackExists) {
await CF.createStack({
StackName: baseStackName,
TemplateBody: baseStack,
@ -252,9 +246,25 @@ class AWSBuildEnvironment implements RemoteBuilderProviderInterface {
{ ParameterKey: 'Storage', ParameterValue: `${baseStackName}-storage` },
],
});
CFState = await CF.describeStacks(describeStackInput).promise();
} else {
const stack = CFState.Stacks?.[0];
if (!stack) {
throw new Error('expected base stack to exist');
}
if (stack.StackName === baseStackName) {
const updateInput: SDK.CloudFormation.UpdateStackInput = {
StackName: baseStackName,
TemplateBody: baseStack,
};
await CF.updateStack(updateInput).promise();
}
}
if (CFState.Stacks?.[0].StackStatus === 'CREATE_IN_PROGRESS') {
await CF.waitFor('stackCreateComplete', describeStackInput).promise();
} else if (CFState.Stacks?.[0].StackStatus === 'UPDATE_IN_PROGRESS') {
await CF.waitFor('stackUpdateComplete', describeStackInput).promise();
}
// wait for base stack to be finished...
}
async handleStackCreationFailure(