|
|
|
@@ -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) {
|
|
|
|
|