This commit is contained in:
Arwid Thornström
2022-01-19 09:17:55 +01:00
parent 7f934532e9
commit 19b15a585c
8 changed files with 27 additions and 49 deletions
@@ -1,6 +1,6 @@
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu'
const chalk = require('chalk');
const { AutoComplete, Input, Confirm } = require('enquirer');
const { Input, Confirm } = require('enquirer');
import { Octokit } from "@octokit/core";
import { GluegunPrint } from 'gluegun';
const os = require("os");
@@ -38,7 +38,6 @@ const getDownloadFileFromRepoCommand = (token: string, org: string, repo: string
}
const getCreateStackCommand = (stackName: string, branch: string, templateFile: string, dockerImage: string, githubToken: string, composerAuth: string) => {
const stack = 'photowall';
const stackDomain = stackName.replace('photowall-', '');
const cmd = [
`aws cloudformation create-stack --stack-name ${stackName}`,
@@ -110,9 +109,6 @@ const getConfirmation = async (branchName: string, stackName: string) => {
}
}
/**
* Subsection1 menu
*/
module.exports = {
name: 'create',
alias: ['c'],
@@ -222,22 +218,22 @@ module.exports = {
await system.run(getDownloadFileFromRepoCommand(config.gh_token, 'Photowall', 'photowall', 'cloudformation/ecr-lifecycle-policy.json'));
await system.run(getDownloadFileFromRepoCommand(config.gh_token, 'Photowall', 'photowall', 'cloudformation/ecs-service.yaml'));
const aws_account_id = strings.trim(await system.run(`aws sts get-caller-identity --query Account --output text`));
const aws_region = strings.trim(await system.run(`aws configure get region`));
const github_token = strings.trim(await system.run(`aws ssm get-parameter --with-decryption --name /github/CODE_PIPELINE_TOKEN --output text --query Parameter.Value`));
const awsAccountId = strings.trim(await system.run(`aws sts get-caller-identity --query Account --output text`));
const awsRegion = strings.trim(await system.run(`aws configure get region`));
const githubToken = strings.trim(await system.run(`aws ssm get-parameter --with-decryption --name /github/CODE_PIPELINE_TOKEN --output text --query Parameter.Value`));
print.fancy(await system.run(`aws ecr create-repository --repository ${stackName}`));
print.fancy(await system.run(`aws ecr get-login-password --region ${aws_region} | docker login --username AWS --password-stdin ${aws_account_id}.dkr.ecr.${aws_region}.amazonaws.com`));
print.fancy(await system.run(`aws ecr get-login-password --region ${awsRegion} | docker login --username AWS --password-stdin ${awsAccountId}.dkr.ecr.${awsRegion}.amazonaws.com`));
print.fancy(await system.run(`docker pull nginx`));
print.fancy(await system.run(`docker tag nginx ${aws_account_id}.dkr.ecr.${aws_region}.amazonaws.com/${stackName}:latest`));
print.fancy(await system.run(`docker push ${aws_account_id}.dkr.ecr.${aws_region}.amazonaws.com/${stackName}:latest`));
print.fancy(await system.run(`docker tag nginx ${awsAccountId}.dkr.ecr.${awsRegion}.amazonaws.com/${stackName}:latest`));
print.fancy(await system.run(`docker push ${awsAccountId}.dkr.ecr.${awsRegion}.amazonaws.com/${stackName}:latest`));
const dockerImage = `${aws_account_id}.dkr.ecr.${aws_region}.amazonaws.com/${stackName}`;
const dockerImage = `${awsAccountId}.dkr.ecr.${awsRegion}.amazonaws.com/${stackName}`;
let composerAuthToken = await system.run(`aws ssm get-parameter --with-decryption --name /github/COMPOSER_TOKEN --output text --query Parameter.Value`);
composerAuthToken = composerAuthToken.replace('\n', '');
const composer_auth = `'{\"github-oauth\":{\"github.com\":\"${composerAuthToken}\"}}'`;
const composerAuth = `'{\"github-oauth\":{\"github.com\":\"${composerAuthToken}\"}}'`;
const createCommand = getCreateStackCommand(stackName, branchName, 'file://ecs-service.yaml', dockerImage, github_token, composer_auth);
const createCommand = getCreateStackCommand(stackName, branchName, 'file://ecs-service.yaml', dockerImage, githubToken, composerAuth);
print.fancy(await system.run(createCommand, {cwd: '/tmp/', trim: true}));
}
} catch (e) {
@@ -48,9 +48,6 @@ const runCommand = async (system: GluegunSystem, cmd : string | null) => {
return null;
};
/**
* Subsection1 menu
*/
module.exports = {
name: 'delete',
alias: ['d'],
@@ -9,9 +9,6 @@ type Stack = {
updated: string,
};
/**
* Subsection1 menu
*/
module.exports = {
name: 'status',
alias: ['s'],
@@ -107,9 +107,6 @@ const getConfirmation = async (branchName: string, stackName: string) => {
}
}
/**
* Subsection1 menu
*/
module.exports = {
name: 'update',
alias: ['u'],
+2 -2
View File
@@ -97,7 +97,7 @@ module.exports = {
// }
// }
system.run('touch ~/.pwcli_settings');
await system.run('touch ~/.pwcli_settings');
print.info(`Created configuration file ${chalk.yellow(`~/.pwcli_settings`)}`);
const config = {
gh_token: '',
@@ -120,7 +120,7 @@ module.exports = {
if (await (new Confirm({
message: `Ok to save the these settings to ${chalk.yellow(`~/.pwcli_settings`)}?`
})).run()) {
system.run(`echo '${JSON.stringify(config)}' > ~/.pwcli_settings`);
await system.run(`echo '${JSON.stringify(config)}' > ~/.pwcli_settings`);
} else {
print.info('Ok then.');
if (toolbox.fromMenu()) await toolbox.menu.showMenu();