Add maxmind license key (#12)
* Add MaxMindLicenseKey * fix lint errors * fix update
This commit is contained in:
@@ -39,7 +39,7 @@ const getDownloadFileFromRepoCommand = (token: string, org: string, repo: string
|
|||||||
return `curl -o /tmp/${file} -H 'Authorization: token ${token} ' -H 'Accept: application/vnd.github.v3.raw' -O -L https://api.github.com/repos/${org}/${repo}/contents/${path}`;
|
return `curl -o /tmp/${file} -H 'Authorization: token ${token} ' -H 'Accept: application/vnd.github.v3.raw' -O -L https://api.github.com/repos/${org}/${repo}/contents/${path}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getCreateStackCommand = (stackName: string, branch: string, templateFile: string, dockerImage: string, githubToken: string, composerAuth: string) => {
|
const getCreateStackCommand = (stackName: string, branch: string, templateFile: string, dockerImage: string, githubToken: string, composerAuth: string, maxmindLicenseKey: string) => {
|
||||||
const stackDomain = stackName.replace('photowall-', '');
|
const stackDomain = stackName.replace('photowall-', '');
|
||||||
const cmd = [
|
const cmd = [
|
||||||
`aws cloudformation create-stack --stack-name ${stackName}`,
|
`aws cloudformation create-stack --stack-name ${stackName}`,
|
||||||
@@ -65,6 +65,7 @@ const getCreateStackCommand = (stackName: string, branch: string, templateFile:
|
|||||||
`ParameterKey=StaticCdnCertificateArn,ParameterValue=${STACK_DEFAULTS.STATIC_CDN_CERTIFICATE_ARN}`,
|
`ParameterKey=StaticCdnCertificateArn,ParameterValue=${STACK_DEFAULTS.STATIC_CDN_CERTIFICATE_ARN}`,
|
||||||
`ParameterKey=AwsAccessKeyParamNameEnvironment,ParameterValue=${STACK_DEFAULTS.AWS_KEY_ENVIRONMENT}`,
|
`ParameterKey=AwsAccessKeyParamNameEnvironment,ParameterValue=${STACK_DEFAULTS.AWS_KEY_ENVIRONMENT}`,
|
||||||
`ParameterKey=DatabaseSecurityGroup,ParameterValue=${STACK_DEFAULTS.DB_SECURITY_GROUP_ID}`,
|
`ParameterKey=DatabaseSecurityGroup,ParameterValue=${STACK_DEFAULTS.DB_SECURITY_GROUP_ID}`,
|
||||||
|
`ParameterKey=MaxMindLicenseKey,ParameterValue=${maxmindLicenseKey}`,
|
||||||
];
|
];
|
||||||
|
|
||||||
return cmd.join(' ');
|
return cmd.join(' ');
|
||||||
@@ -92,17 +93,17 @@ module.exports = {
|
|||||||
hidden: false,
|
hidden: false,
|
||||||
run: async (toolbox: GluegunMenuToolbox) => {
|
run: async (toolbox: GluegunMenuToolbox) => {
|
||||||
const { system, strings, print, filesystem } = toolbox;
|
const { system, strings, print, filesystem } = toolbox;
|
||||||
|
|
||||||
// Load settings
|
// Load settings
|
||||||
const config = await getSettings(toolbox);
|
const config = await getSettings(toolbox);
|
||||||
if (!config) {
|
if (!config) {
|
||||||
await toolbox.menu.showMenu('setup', defaultMenuSettings);
|
await toolbox.menu.showMenu('setup', defaultMenuSettings);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const branches = await getRepoBranches(toolbox, config.gh_token, 'Photowall', 'photowall');
|
const branches = await getRepoBranches(toolbox, config.gh_token, 'Photowall', 'photowall');
|
||||||
const branchOptions = branches.map(item => item.name);
|
const branchOptions = branches.map(item => item.name);
|
||||||
|
|
||||||
const promptBranch = new AutoComplete({
|
const promptBranch = new AutoComplete({
|
||||||
name: 'branchName',
|
name: 'branchName',
|
||||||
message: 'Select a branch',
|
message: 'Select a branch',
|
||||||
@@ -155,7 +156,7 @@ module.exports = {
|
|||||||
const options = curratedStacks.map(item => {
|
const options = curratedStacks.map(item => {
|
||||||
return item.name;
|
return item.name;
|
||||||
});
|
});
|
||||||
|
|
||||||
const input = new Input({
|
const input = new Input({
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'stack',
|
name: 'stack',
|
||||||
@@ -165,25 +166,25 @@ module.exports = {
|
|||||||
|
|
||||||
if (options.includes(stackName)) {
|
if (options.includes(stackName)) {
|
||||||
print.error(`
|
print.error(`
|
||||||
|
|
||||||
The stack ${chalk.yellow(stackName)} is already taken, try the update command instead.
|
The stack ${chalk.yellow(stackName)} is already taken, try the update command instead.
|
||||||
|
|
||||||
`);
|
`);
|
||||||
if (toolbox.fromMenu()) {
|
if (toolbox.fromMenu()) {
|
||||||
await toolbox.menu.showMenu('deployment testservers');
|
await toolbox.menu.showMenu('deployment testservers');
|
||||||
}
|
}
|
||||||
} else if (stackName.indexOf('photowall-test-') !== 0) {
|
} else if (stackName.indexOf('photowall-test-') !== 0) {
|
||||||
print.error(`
|
print.error(`
|
||||||
|
|
||||||
The stack must begin with ${chalk.yellow('photowall-test-')}.
|
The stack must begin with ${chalk.yellow('photowall-test-')}.
|
||||||
|
|
||||||
`);
|
`);
|
||||||
if (toolbox.fromMenu()) {
|
if (toolbox.fromMenu()) {
|
||||||
await toolbox.menu.showMenu('deployment testservers', defaultMenuSettings);
|
await toolbox.menu.showMenu('deployment testservers', defaultMenuSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const shouldRun = await getConfirmation(branchName, stackName);
|
const shouldRun = await getConfirmation(branchName, stackName);
|
||||||
@@ -196,6 +197,7 @@ module.exports = {
|
|||||||
const awsAccountId = strings.trim(await system.run(`aws sts get-caller-identity --query Account --output text`));
|
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 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`));
|
const githubToken = strings.trim(await system.run(`aws ssm get-parameter --with-decryption --name /github/CODE_PIPELINE_TOKEN --output text --query Parameter.Value`));
|
||||||
|
const maxmindLicenseKey = strings.trim(await system.run(`aws ssm get-parameter --with-decryption --name /maxmind/MAXMIND_LICENSE_KEY --output text --query Parameter.Value`));
|
||||||
|
|
||||||
print.fancy(await system.run(`aws ecr create-repository --repository ${stackName}`));
|
print.fancy(await system.run(`aws ecr create-repository --repository ${stackName}`));
|
||||||
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(`aws ecr get-login-password --region ${awsRegion} | docker login --username AWS --password-stdin ${awsAccountId}.dkr.ecr.${awsRegion}.amazonaws.com`));
|
||||||
@@ -208,7 +210,7 @@ module.exports = {
|
|||||||
composerAuthToken = composerAuthToken.replace('\n', '');
|
composerAuthToken = composerAuthToken.replace('\n', '');
|
||||||
const composerAuth = `'{\\\"github-oauth\\\":{\\\"github.com\\\":\\\"${composerAuthToken}\\\"}}'`;
|
const composerAuth = `'{\\\"github-oauth\\\":{\\\"github.com\\\":\\\"${composerAuthToken}\\\"}}'`;
|
||||||
|
|
||||||
const createCommand = getCreateStackCommand(stackName, branchName, 'file://ecs-service.yaml', dockerImage, githubToken, composerAuth);
|
const createCommand = getCreateStackCommand(stackName, branchName, 'file://ecs-service.yaml', dockerImage, githubToken, composerAuth, maxmindLicenseKey);
|
||||||
print.fancy(await system.run(createCommand, {cwd: '/tmp/', trim: true}));
|
print.fancy(await system.run(createCommand, {cwd: '/tmp/', trim: true}));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ module.exports = {
|
|||||||
description: 'Show status for available testservers (s)',
|
description: 'Show status for available testservers (s)',
|
||||||
hidden: false,
|
hidden: false,
|
||||||
run: async (toolbox: GluegunMenuToolbox) => {
|
run: async (toolbox: GluegunMenuToolbox) => {
|
||||||
|
|
||||||
const { system, strings } = toolbox
|
const { system, strings } = toolbox
|
||||||
|
|
||||||
const stacks = JSON.parse(strings.trim(await system.run(`aws cloudformation list-stacks`)));
|
const stacks = JSON.parse(strings.trim(await system.run(`aws cloudformation list-stacks`)));
|
||||||
@@ -45,14 +45,14 @@ module.exports = {
|
|||||||
updated: '',
|
updated: '',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const curratedStacks: Stack[] = teststacks.filter(Boolean);
|
const curratedStacks: Stack[] = teststacks.filter(Boolean);
|
||||||
|
|
||||||
const status = (status: string) => {
|
const status = (status: string) => {
|
||||||
switch(status) {
|
switch(status) {
|
||||||
case 'NO_STATUS':
|
case 'NO_STATUS':
|
||||||
return `(${chalk.red.bold('?')})`;
|
return `(${chalk.red.bold('?')})`;
|
||||||
@@ -78,10 +78,10 @@ module.exports = {
|
|||||||
|
|
||||||
const timeSince = (date: number) => {
|
const timeSince = (date: number) => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
var seconds = Math.floor((now - date) / 1000);
|
let seconds = Math.floor((now - date) / 1000);
|
||||||
|
|
||||||
var interval = seconds / 31536000;
|
let interval = seconds / 31536000;
|
||||||
|
|
||||||
if (interval > 1) {
|
if (interval > 1) {
|
||||||
return Math.floor(interval) + " years";
|
return Math.floor(interval) + " years";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ const getLifeCyclePolicyCommand = (stackName: string, policyFile: string) => {
|
|||||||
return `aws ecr put-lifecycle-policy --repository-name ${stackName} --lifecycle-policy-text "${policyFile}"`;
|
return `aws ecr put-lifecycle-policy --repository-name ${stackName} --lifecycle-policy-text "${policyFile}"`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getUpdateStackCommand = (stackName: string, branch: string, templateFile: string) => {
|
const getUpdateStackCommand = (stackName: string, branch: string, templateFile: string, maxmindLicenseKey: string) => {
|
||||||
const cmd = [
|
const cmd = [
|
||||||
`aws cloudformation update-stack --stack-name ${stackName}`,
|
`aws cloudformation update-stack --stack-name ${stackName}`,
|
||||||
`--template-body ${templateFile}`,
|
`--template-body ${templateFile}`,
|
||||||
@@ -63,7 +63,8 @@ const getUpdateStackCommand = (stackName: string, branch: string, templateFile:
|
|||||||
`ParameterKey=StaticCdnHostName,ParameterValue=${STACK_DEFAULTS.STATIC_CDN_HOSTNAME}`,
|
`ParameterKey=StaticCdnHostName,ParameterValue=${STACK_DEFAULTS.STATIC_CDN_HOSTNAME}`,
|
||||||
`ParameterKey=StaticCdnCertificateArn,ParameterValue=${STACK_DEFAULTS.STATIC_CDN_CERTIFICATE_ARN}`,
|
`ParameterKey=StaticCdnCertificateArn,ParameterValue=${STACK_DEFAULTS.STATIC_CDN_CERTIFICATE_ARN}`,
|
||||||
`ParameterKey=AwsAccessKeyParamNameEnvironment,ParameterValue=${STACK_DEFAULTS.AWS_KEY_ENVIRONMENT}`,
|
`ParameterKey=AwsAccessKeyParamNameEnvironment,ParameterValue=${STACK_DEFAULTS.AWS_KEY_ENVIRONMENT}`,
|
||||||
`ParameterKey=DatabaseSecurityGroup,ParameterValue=${STACK_DEFAULTS.DB_SECURITY_GROUP_ID}`
|
`ParameterKey=DatabaseSecurityGroup,ParameterValue=${STACK_DEFAULTS.DB_SECURITY_GROUP_ID}`,
|
||||||
|
`ParameterKey=MaxMindLicenseKey,ParameterValue=${maxmindLicenseKey}`,
|
||||||
];
|
];
|
||||||
return cmd.join(' ');
|
return cmd.join(' ');
|
||||||
}
|
}
|
||||||
@@ -118,7 +119,7 @@ module.exports = {
|
|||||||
hidden: false,
|
hidden: false,
|
||||||
run: async (toolbox: GluegunMenuToolbox) => {
|
run: async (toolbox: GluegunMenuToolbox) => {
|
||||||
const { system, strings, print } = toolbox;
|
const { system, strings, print } = toolbox;
|
||||||
|
|
||||||
// Load settings
|
// Load settings
|
||||||
const config = await getSettings(toolbox);
|
const config = await getSettings(toolbox);
|
||||||
if (!config) {
|
if (!config) {
|
||||||
@@ -174,7 +175,7 @@ module.exports = {
|
|||||||
const options = curratedStacks.map(item => {
|
const options = curratedStacks.map(item => {
|
||||||
return item.name;
|
return item.name;
|
||||||
});
|
});
|
||||||
|
|
||||||
const prompt = new AutoComplete({
|
const prompt = new AutoComplete({
|
||||||
name: 'testserver',
|
name: 'testserver',
|
||||||
message: 'Choose a server',
|
message: 'Choose a server',
|
||||||
@@ -190,16 +191,18 @@ module.exports = {
|
|||||||
await system.run(getDownloadFileFromRepoCommand(config.gh_token, 'Photowall', 'photowall', 'cloudformation/ecs-service.yaml'));
|
await system.run(getDownloadFileFromRepoCommand(config.gh_token, 'Photowall', 'photowall', 'cloudformation/ecs-service.yaml'));
|
||||||
|
|
||||||
const stackName = await prompt.run();
|
const stackName = await prompt.run();
|
||||||
|
|
||||||
|
const maxmindLicenseKey = strings.trim(await system.run(`aws ssm get-parameter --with-decryption --name /maxmind/MAXMIND_LICENSE_KEY --output text --query Parameter.Value`));
|
||||||
|
|
||||||
const lifeCycleCommand = getLifeCyclePolicyCommand(stackName, `file://ecr-lifecycle-policy.json`);
|
const lifeCycleCommand = getLifeCyclePolicyCommand(stackName, `file://ecr-lifecycle-policy.json`);
|
||||||
const updateStackCommand = getUpdateStackCommand(stackName, branchName, `file://ecs-service.yaml`);
|
const updateStackCommand = getUpdateStackCommand(stackName, branchName, `file://ecs-service.yaml`, maxmindLicenseKey);
|
||||||
|
|
||||||
const shouldRun = await getConfirmation(branchName, stackName);
|
const shouldRun = await getConfirmation(branchName, stackName);
|
||||||
|
|
||||||
if (shouldRun) {
|
if (shouldRun) {
|
||||||
let output = await system.run(lifeCycleCommand, {cwd: '/tmp/', trim: true});
|
let output = await system.run(lifeCycleCommand, {cwd: '/tmp/', trim: true});
|
||||||
print.fancy(output);
|
print.fancy(output);
|
||||||
output = await system.run(updateStackCommand, {cwd: '/tmp/', trim: true});
|
output = await system.run(updateStackCommand, {cwd: '/tmp/', trim: true});
|
||||||
print.fancy(output);
|
print.fancy(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user