first commit
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu'
|
||||
const tto = require('terminal-table-output').create();
|
||||
|
||||
type Stack = {
|
||||
name: string,
|
||||
status: string,
|
||||
drift_status: string,
|
||||
branch: string,
|
||||
updated: string,
|
||||
};
|
||||
|
||||
/**
|
||||
* Subsection1 menu
|
||||
*/
|
||||
module.exports = {
|
||||
name: 'status',
|
||||
alias: ['s'],
|
||||
description: 'Show status for available testservers (s)',
|
||||
hidden: true,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
|
||||
const { system, strings } = toolbox
|
||||
|
||||
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 curratedStacks: Stack[] = teststacks.filter(Boolean);
|
||||
|
||||
const status = (status: string) => {
|
||||
switch(status) {
|
||||
case 'UPDATE_FAILED':
|
||||
case 'CREATE_FAILED':
|
||||
return ` (💔) `;
|
||||
case 'UPDATE_IN_PROGRESS':
|
||||
case 'CREATE_IN_PROGRESS':
|
||||
return ` (🟡) `;
|
||||
case 'UPDATE_COMPLETE':
|
||||
case 'CREATE_COMPLETE':
|
||||
return ` (🟢) `;
|
||||
}
|
||||
}
|
||||
|
||||
tto.line('-');
|
||||
tto.pushrow(['| status', 'stack', 'branch', 'updated'])
|
||||
.line('-');
|
||||
for (const stack of curratedStacks) {
|
||||
tto.pushrow([status(stack.status), stack.name, stack.branch, stack.updated]);
|
||||
}
|
||||
tto.print(true);
|
||||
|
||||
if (toolbox.fromMenu()) {
|
||||
await toolbox.menu.showMenu('deployment testservers');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user