fix create/delete when there exists broken stacks
This commit is contained in:
@@ -1,18 +1,11 @@
|
||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||
import { exit } from 'process';
|
||||
import { getTestStacksInfo } from '../../../../common/testservers';
|
||||
const chalk = require('chalk');
|
||||
const { AutoComplete, Input, Confirm } = require('enquirer');
|
||||
import { defaultMenuSettings, getSettings } from '../../../../globals';
|
||||
import { getRepoBranches } from '../../../../services/github_rest';
|
||||
|
||||
type Stack = {
|
||||
name: string;
|
||||
status: string;
|
||||
drift_status: string;
|
||||
branch: string;
|
||||
updated: string;
|
||||
};
|
||||
|
||||
const getConfirmation = async (branchName: string, stackName: string) => {
|
||||
const url = stackName.replace('photowall-', '');
|
||||
const confirm = new Confirm({
|
||||
@@ -36,7 +29,7 @@ module.exports = {
|
||||
description: 'Create new testserver on aws (c)',
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
const { system, strings, print, filesystem } = toolbox;
|
||||
const { system, strings, print } = toolbox;
|
||||
|
||||
// Load settings
|
||||
const config = await getSettings(toolbox);
|
||||
@@ -67,47 +60,9 @@ module.exports = {
|
||||
});
|
||||
const branchName = await promptBranch.run();
|
||||
|
||||
const stacks = JSON.parse(
|
||||
strings.trim(await system.run(`aws cloudformation list-stacks`))
|
||||
);
|
||||
const teststacks: Stack[] = await Promise.all(
|
||||
stacks.StackSummaries.map(async item => {
|
||||
if (
|
||||
item.StackName.indexOf('photowall-test-') > -1 &&
|
||||
[
|
||||
'CREATE_COMPLETE',
|
||||
'UPDATE_COMPLETE',
|
||||
'UPDATE_IN_PROGRESS',
|
||||
'UPDATE_FAILED',
|
||||
'CREATE_FAILED',
|
||||
'CREATE_IN_PROGRESS'
|
||||
].includes(item.StackStatus)
|
||||
) {
|
||||
const pipeline = JSON.parse(
|
||||
strings.trim(
|
||||
await system.run(
|
||||
`aws codepipeline get-pipeline --name ${item.StackName}Pipeline`
|
||||
)
|
||||
)
|
||||
);
|
||||
const branch = pipeline.pipeline.stages.filter(stage => {
|
||||
return stage.name === 'Source';
|
||||
})[0].actions[0].configuration.Branch;
|
||||
const lastUpdated = pipeline.metadata.updated;
|
||||
return {
|
||||
name: item.StackName,
|
||||
status: item.StackStatus,
|
||||
drift_status: item.DriftInformation.StackDriftStatus,
|
||||
branch: branch,
|
||||
updated: lastUpdated
|
||||
};
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
})
|
||||
);
|
||||
const testStacks = await getTestStacksInfo(toolbox);
|
||||
|
||||
const curratedStacks: Stack[] = teststacks.filter(Boolean);
|
||||
const options = curratedStacks.map(item => {
|
||||
const options = testStacks.map(item => {
|
||||
return item.name;
|
||||
});
|
||||
|
||||
@@ -121,11 +76,11 @@ module.exports = {
|
||||
|
||||
if (options.includes(stackName)) {
|
||||
print.error(`
|
||||
|
||||
|
||||
The stack ${chalk.yellow(
|
||||
stackName
|
||||
)} is already taken, try the update command instead.
|
||||
|
||||
|
||||
`);
|
||||
if (toolbox.fromMenu()) {
|
||||
await toolbox.menu.showMenu('deployment testservers');
|
||||
|
||||
Reference in New Issue
Block a user