fix aws check for base stack

pull/289/head
Frostebite 2021-08-13 19:16:17 +01:00
parent 54cdb38171
commit a9d25bcd6d
3 changed files with 51 additions and 43 deletions

46
dist/index.js vendored
View File

@ -1031,16 +1031,10 @@ class AWSBuildEnvironment {
const describeStackInput = {
StackName: baseStackName,
};
let CFState;
try {
CFState = yield CF.describeStacks(describeStackInput).promise();
}
catch (_g) {
CFState = { Stacks: [] };
}
const stackExists = CFState.Stacks !== null && CFState.Stacks !== [];
const stacks = (_a = (yield CF.listStacks().promise()).StackSummaries) === null || _a === void 0 ? void 0 : _a.map((x) => x.StackName);
const stackExists = (stacks === null || stacks === void 0 ? void 0 : stacks.includes(baseStackName)) || false;
if (!stackExists) {
core.info('stack exists');
core.info('stack does not exist');
yield CF.createStack({
StackName: baseStackName,
TemplateBody: baseStack,
@ -1050,15 +1044,19 @@ class AWSBuildEnvironment {
{ ParameterKey: 'Version', ParameterValue: `hash` },
],
});
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');
}
const CFState = yield CF.describeStacks(describeStackInput).promise();
let stack = (_b = CFState.Stacks) === null || _b === void 0 ? void 0 : _b[0];
if (!stack) {
throw new Error(`Base stack doesn't exist, even after creation, stackExists check: ${stackExists}`);
}
if (stack.StackStatus === 'CREATE_IN_PROGRESS') {
yield CF.waitFor('stackCreateComplete', describeStackInput).promise();
}
if (stackExists) {
core.info('stack exists');
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)) {
hash !== ((_d = (_c = stack.Parameters) === null || _c === void 0 ? void 0 : _c.find((x) => x.ParameterKey === 'Version')) === null || _d === void 0 ? void 0 : _d.ParameterValue)) {
const updateInput = {
StackName: baseStackName,
TemplateBody: baseStack,
@ -1066,15 +1064,17 @@ class AWSBuildEnvironment {
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')}`);
core.info(`Skipping any update for base stack ${stack.StackName} ${(_e = stack.Parameters) === null || _e === void 0 ? void 0 : _e.find((x) => x.ParameterKey === 'Version')}`);
}
stack = (_f = (yield CF.describeStacks(describeStackInput).promise()).Stacks) === null || _f === void 0 ? void 0 : _f[0];
if (!stack) {
throw new Error(`Base stack doesn't exist, even after updating and creation, stackExists check: ${stackExists}`);
}
if (stack.StackStatus === 'UPDATE_IN_PROGRESS') {
yield CF.waitFor('stackUpdateComplete', describeStackInput).promise();
}
}
if (((_e = CFState.Stacks) === null || _e === void 0 ? void 0 : _e[0].StackStatus) === 'CREATE_IN_PROGRESS') {
yield CF.waitFor('stackCreateComplete', describeStackInput).promise();
}
else if (((_f = CFState.Stacks) === null || _f === void 0 ? void 0 : _f[0].StackStatus) === 'UPDATE_IN_PROGRESS') {
yield CF.waitFor('stackUpdateComplete', describeStackInput).promise();
}
core.info('base stack exists and is ready');
});
}
handleStackCreationFailure(error, CF, taskDefStackName, taskDefCloudFormation, secrets) {

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -237,15 +237,11 @@ class AWSBuildEnvironment implements RemoteBuilderProviderInterface {
const describeStackInput: SDK.CloudFormation.DescribeStacksInput = {
StackName: baseStackName,
};
let CFState;
try {
CFState = await CF.describeStacks(describeStackInput).promise();
} catch {
CFState = { Stacks: [] };
}
const stackExists: Boolean = CFState.Stacks !== null && CFState.Stacks !== [];
const stacks = (await CF.listStacks().promise()).StackSummaries?.map((x) => x.StackName);
const stackExists: Boolean = stacks?.includes(baseStackName) || false;
if (!stackExists) {
core.info('stack exists');
core.info('stack does not exist');
await CF.createStack({
StackName: baseStackName,
TemplateBody: baseStack,
@ -255,12 +251,19 @@ class AWSBuildEnvironment implements RemoteBuilderProviderInterface {
{ ParameterKey: 'Version', ParameterValue: `hash` },
],
});
CFState = await CF.describeStacks(describeStackInput).promise();
} else {
const stack = CFState.Stacks?.[0];
if (!stack) {
throw new Error('expected base stack to exist');
}
}
const CFState = await CF.describeStacks(describeStackInput).promise();
let stack = CFState.Stacks?.[0];
if (!stack) {
throw new Error(`Base stack doesn't exist, even after creation, stackExists check: ${stackExists}`);
}
if (stack.StackStatus === 'CREATE_IN_PROGRESS') {
await CF.waitFor('stackCreateComplete', describeStackInput).promise();
}
if (stackExists) {
core.info('stack exists');
if (
stack.StackName === baseStackName &&
hash !== stack.Parameters?.find((x) => x.ParameterKey === 'Version')?.ParameterValue
@ -277,12 +280,17 @@ class AWSBuildEnvironment implements RemoteBuilderProviderInterface {
)}`,
);
}
stack = (await CF.describeStacks(describeStackInput).promise()).Stacks?.[0];
if (!stack) {
throw new Error(
`Base stack doesn't exist, even after updating and creation, stackExists check: ${stackExists}`,
);
}
if (stack.StackStatus === 'UPDATE_IN_PROGRESS') {
await CF.waitFor('stackUpdateComplete', describeStackInput).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();
}
core.info('base stack exists and is ready');
}
async handleStackCreationFailure(