diff --git a/src/commands/aws/parameterstore/parameterstore.ts b/src/commands/aws/parameterstore/parameterstore.ts index 7a16602..484b51c 100644 --- a/src/commands/aws/parameterstore/parameterstore.ts +++ b/src/commands/aws/parameterstore/parameterstore.ts @@ -1,12 +1,8 @@ import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu' import chalk = require('chalk'); -import { defaultMenuSettings } from '../../../globals'; +import { defaultMenuSettings, sleep } from '../../../globals'; const { AutoComplete } = require('enquirer'); -const sleep = (milliseconds) => { - return new Promise(resolve => setTimeout(resolve, milliseconds)) -} - module.exports = { name: 'parameterstore', alias: ['ps'], diff --git a/src/commands/deployment/testservers/update/update.ts b/src/commands/deployment/testservers/update/update.ts index 5c4dd56..75a5093 100644 --- a/src/commands/deployment/testservers/update/update.ts +++ b/src/commands/deployment/testservers/update/update.ts @@ -2,7 +2,8 @@ import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu' const chalk = require('chalk'); const { AutoComplete, Input, Confirm } = require('enquirer'); import { Octokit } from "@octokit/core"; -import { defaultMenuSettings, getCurrentBranch, getSettings } from '../../../../globals'; +import { exit } from 'process'; +import { defaultMenuSettings, getCurrentBranch, getSettings, sleep } from '../../../../globals'; type Stack = { name: string @@ -143,6 +144,35 @@ module.exports = { print.fancy(`Running [${chalk.yellow(cmd)}] in folder [${`${config.photowall_repo}/cloudformation/`}]`); const output = await system.run(cmd, {cwd: `${config.photowall_repo}/cloudformation/`, trim: true}); print.fancy(output); + + // Check the status + const spinner = print.spin(`Waiting for stack to update`); + let currentStackStatus = ""; + while (currentStackStatus !== "UPDATE_COMPLETE") { + const stackCmd = `aws cloudformation describe-stacks --stack-name photowall-${stacksuffix}`; + const response = await system.run(stackCmd, {trim: true}); + const stackData = JSON.parse(response); + currentStackStatus = stackData.Stacks[0].StackStatus; + switch (currentStackStatus) { + case "UPDATE_IN_PROGRESS": + spinner.text = `[${chalk.red(currentStackStatus)}]: Updating the stack`; + case "UPDATE_COMPLETE_CLEANUP_IN_PROGRESS": + spinner.text = `[${chalk.yellow(currentStackStatus)}]: Almost done, cleanup in progress`; + case "UPDATE_COMPLETE": + spinner.text = `[${chalk.green(currentStackStatus)}]: Update complete`; + break; + } + if (currentStackStatus !== 'UPDATE_COMPLETE') { + await sleep(1000); + } + } + + spinner.text = `Will start the pipeline now [${chalk.yellow(`photowall-${stacksuffix}Pipeline`)}]`; + const runPipelineCmd = `aws codepipeline start-pipeline-execution --name photowall-${stacksuffix}Pipeline`; + await system.run(runPipelineCmd); + await sleep(2000); + spinner.stop(); + print.fancy('Pipeline started, bye! 🚀'); } } catch (e) { @@ -151,6 +181,8 @@ module.exports = { if (toolbox.fromMenu()) { await toolbox.menu.showMenu('deployment testservers', defaultMenuSettings) + } else { + exit(); } } } diff --git a/src/globals.ts b/src/globals.ts index 7670f9f..429b41a 100644 --- a/src/globals.ts +++ b/src/globals.ts @@ -65,3 +65,7 @@ export const confirmMessage = async (message: string) => { return false; } }; + +export const sleep = (milliseconds) => { + return new Promise(resolve => setTimeout(resolve, milliseconds)) +}