Fixing aws base stack setup error handling

pull/289/head
mdugdale 2021-08-22 01:15:02 +01:00
parent a0593807c4
commit f5e6599266
3 changed files with 69 additions and 59 deletions

60
dist/index.js vendored
View File

@ -580,38 +580,44 @@ class AWSBuildEnvironment {
const describeStack = () => __awaiter(this, void 0, void 0, function* () { const describeStack = () => __awaiter(this, void 0, void 0, function* () {
return yield CF.describeStacks(describeStackInput).promise(); return yield CF.describeStacks(describeStackInput).promise();
}); });
if (!stackExists) { try {
core.info(`${baseStackName} stack does not exist (${JSON.stringify(stacks)})`); if (!stackExists) {
yield CF.createStack(createStackInput).promise(); core.info(`${baseStackName} stack does not exist (${JSON.stringify(stacks)})`);
core.info(`created stack (version: ${hash})`); yield CF.createStack(createStackInput).promise();
} core.info(`created stack (version: ${hash})`);
const CFState = yield describeStack();
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}`);
}
const stackVersion = (_d = (_c = stack.Parameters) === null || _c === void 0 ? void 0 : _c.find((x) => x.ParameterKey === 'Version')) === null || _d === void 0 ? void 0 : _d.ParameterValue;
if (stack.StackStatus === 'CREATE_IN_PROGRESS') {
yield CF.waitFor('stackCreateComplete', describeStackInput).promise();
}
if (stackExists) {
core.info(`Base stack exists (version: ${stackVersion}, local version: ${hash})`);
if (hash !== stackVersion) {
core.info(`Updating`);
yield CF.updateStack(updateInput).promise();
} }
else { const CFState = yield describeStack();
core.info(`No update required`); let stack = (_b = CFState.Stacks) === null || _b === void 0 ? void 0 : _b[0];
}
stack = (_e = (yield describeStack()).Stacks) === null || _e === void 0 ? void 0 : _e[0];
if (!stack) { if (!stack) {
throw new Error(`Base stack doesn't exist, even after updating and creation, stackExists check: ${stackExists}`); throw new Error(`Base stack doesn't exist, even after creation, stackExists check: ${stackExists}`);
} }
if (stack.StackStatus === 'UPDATE_IN_PROGRESS') { const stackVersion = (_d = (_c = stack.Parameters) === null || _c === void 0 ? void 0 : _c.find((x) => x.ParameterKey === 'Version')) === null || _d === void 0 ? void 0 : _d.ParameterValue;
yield CF.waitFor('stackUpdateComplete', describeStackInput).promise(); if (stack.StackStatus === 'CREATE_IN_PROGRESS') {
yield CF.waitFor('stackCreateComplete', describeStackInput).promise();
} }
if (stackExists) {
core.info(`Base stack exists (version: ${stackVersion}, local version: ${hash})`);
if (hash !== stackVersion) {
core.info(`Updating`);
yield CF.updateStack(updateInput).promise();
}
else {
core.info(`No update required`);
}
stack = (_e = (yield describeStack()).Stacks) === null || _e === void 0 ? void 0 : _e[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();
}
}
core.info('base stack is ready');
}
catch (error) {
core.error(JSON.stringify(yield describeStack(), undefined, 4));
throw error;
} }
core.info('base stack is ready');
}); });
} }
handleStackCreationFailure(error, CF, taskDefStackName, taskDefCloudFormation, secrets) { 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

@ -290,42 +290,46 @@ class AWSBuildEnvironment implements CloudRunnerProviderInterface {
const describeStack = async () => { const describeStack = async () => {
return await CF.describeStacks(describeStackInput).promise(); return await CF.describeStacks(describeStackInput).promise();
}; };
try {
if (!stackExists) { if (!stackExists) {
core.info(`${baseStackName} stack does not exist (${JSON.stringify(stacks)})`); core.info(`${baseStackName} stack does not exist (${JSON.stringify(stacks)})`);
await CF.createStack(createStackInput).promise(); await CF.createStack(createStackInput).promise();
core.info(`created stack (version: ${hash})`); core.info(`created stack (version: ${hash})`);
}
const CFState = await describeStack();
let stack = CFState.Stacks?.[0];
if (!stack) {
throw new Error(`Base stack doesn't exist, even after creation, stackExists check: ${stackExists}`);
}
const stackVersion = stack.Parameters?.find((x) => x.ParameterKey === 'Version')?.ParameterValue;
if (stack.StackStatus === 'CREATE_IN_PROGRESS') {
await CF.waitFor('stackCreateComplete', describeStackInput).promise();
}
if (stackExists) {
core.info(`Base stack exists (version: ${stackVersion}, local version: ${hash})`);
if (hash !== stackVersion) {
core.info(`Updating`);
await CF.updateStack(updateInput).promise();
} else {
core.info(`No update required`);
} }
stack = (await describeStack()).Stacks?.[0]; const CFState = await describeStack();
let stack = CFState.Stacks?.[0];
if (!stack) { if (!stack) {
throw new Error( throw new Error(`Base stack doesn't exist, even after creation, stackExists check: ${stackExists}`);
`Base stack doesn't exist, even after updating and creation, stackExists check: ${stackExists}`,
);
} }
if (stack.StackStatus === 'UPDATE_IN_PROGRESS') { const stackVersion = stack.Parameters?.find((x) => x.ParameterKey === 'Version')?.ParameterValue;
await CF.waitFor('stackUpdateComplete', describeStackInput).promise();
if (stack.StackStatus === 'CREATE_IN_PROGRESS') {
await CF.waitFor('stackCreateComplete', describeStackInput).promise();
} }
if (stackExists) {
core.info(`Base stack exists (version: ${stackVersion}, local version: ${hash})`);
if (hash !== stackVersion) {
core.info(`Updating`);
await CF.updateStack(updateInput).promise();
} else {
core.info(`No update required`);
}
stack = (await describeStack()).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();
}
}
core.info('base stack is ready');
} catch (error) {
core.error(JSON.stringify(await describeStack(), undefined, 4));
throw error;
} }
core.info('base stack is ready');
} }
async handleStackCreationFailure( async handleStackCreationFailure(