cloudmason 0.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/CODEOWNERS +1 -0
- package/.github/workflows/main.yml +27 -27
- package/README.md +373 -25
- package/build.js +20 -20
- package/commands/delete.js +67 -28
- package/commands/helpers/cf.js +181 -117
- package/commands/helpers/common.js +82 -0
- package/commands/helpers/ec2.js +154 -40
- package/commands/helpers/params.js +231 -178
- package/commands/helpers/s3.js +186 -67
- package/commands/helpers/stacks/asg.yaml +420 -224
- package/commands/helpers/stacks/infra.yaml +102 -106
- package/commands/helpers/stacks.js +25 -25
- package/commands/index.html +22 -0
- package/commands/init_org.js +54 -61
- package/commands/inspect.js +40 -0
- package/commands/launch_app.js +80 -57
- package/commands/list_apps.js +21 -21
- package/commands/new_app.js +44 -50
- package/commands/new_instance.js +133 -186
- package/commands/reset_stack.js +27 -27
- package/commands/starter.js +21 -0
- package/commands/starters/asg_node/index.js +62 -0
- package/commands/starters/asg_node/mason.txt +1 -0
- package/commands/starters/asg_node/modules/appConfig.js +131 -0
- package/commands/starters/asg_node/package-lock.json +5877 -0
- package/commands/starters/asg_node/package.json +23 -0
- package/commands/starters/asg_node/public/css/favicon-16x16.png +0 -0
- package/commands/starters/asg_node/public/css/fonts/Lato-Bold.ttf +0 -0
- package/commands/starters/asg_node/public/css/fonts/Lato-Regular.ttf +0 -0
- package/commands/starters/asg_node/public/css/fonts/Montserrat-Var.ttf +0 -0
- package/commands/starters/asg_node/public/css/fonts/OpenSans.ttf +0 -0
- package/commands/starters/asg_node/public/css/fonts/bpmn.woff2 +0 -0
- package/commands/starters/asg_node/public/css/fonts/fonts.css +17 -0
- package/commands/starters/asg_node/public/css/index.css +9 -0
- package/commands/starters/asg_node/public/index.html +15 -0
- package/commands/starters/asg_node/public/js/index.js +5 -0
- package/commands/starters/asg_node/start.sh +4 -0
- package/commands/update_app.js +235 -272
- package/commands/update_stack.js +27 -0
- package/commands/utils.js +32 -32
- package/main.js +262 -220
- package/package.json +1 -28
- package/test.bat +16 -9
- package/commands/delete_app.js +0 -28
- package/commands/helpers/stacks/asg_draft.json +0 -321
package/commands/new_app.js
CHANGED
|
@@ -1,50 +1,44 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
console.log(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (!fs.existsSync(stackPath)){ throw new Error('Invalid stack ' + args.type); }
|
|
46
|
-
|
|
47
|
-
const b64Script = Buffer.from(bootScript, 'utf8').toString('base64');
|
|
48
|
-
const stackTxt = fs.readFileSync(stackPath, 'utf-8').replace(/{{user_data}}/, b64Script)
|
|
49
|
-
return stackTxt;
|
|
50
|
-
}
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const Params = require('./helpers/params');
|
|
4
|
+
const S3 = require('./helpers/s3');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
exports.main = async function(args){
|
|
8
|
+
// Check for existing app
|
|
9
|
+
const existingApp = await Params.getApp(args.name);
|
|
10
|
+
if (existingApp){
|
|
11
|
+
console.log('Err: App already exists ' + args.name);
|
|
12
|
+
throw new Error('App exists')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Check Lang Selection
|
|
16
|
+
if (args.node && !/[0-9]{1,2}/.test(args.node)){
|
|
17
|
+
throw new Error('Invalid nodejs version. Use major version only (14,15,16)')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Prep Stack
|
|
21
|
+
const stackPath = path.resolve(__dirname, 'helpers', 'stacks', `${args.type}.yaml`);
|
|
22
|
+
if (!fs.existsSync(stackPath)){ throw new Error('Invalid stack ' + args.type); }
|
|
23
|
+
|
|
24
|
+
const stackText = fs.readFileSync(stackPath, 'utf-8')
|
|
25
|
+
|
|
26
|
+
// Upload Stack
|
|
27
|
+
console.log(`Uploading ${args.type} stack to ${process.env.orgBucket}`)
|
|
28
|
+
const stackKey = `apps/${args.name.toLowerCase()}/default_stack.yaml`
|
|
29
|
+
await S3.uploadInfraText(stackKey,stackText);
|
|
30
|
+
|
|
31
|
+
// Update app config
|
|
32
|
+
console.log('Adding app params');
|
|
33
|
+
const nodev = args.node || '';
|
|
34
|
+
const pyv = args.py || '';
|
|
35
|
+
await Params.addApp(args.name,args.type,stackKey,nodev,pyv);
|
|
36
|
+
console.log(`Added ${args.name} with ${args.type} stack`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
// #!/bin/bash -x
|
|
41
|
+
// echo "Running user data"
|
|
42
|
+
// cd /home/ec2-user/app
|
|
43
|
+
// chmod +x start.sh
|
|
44
|
+
// source start.sh
|
package/commands/new_instance.js
CHANGED
|
@@ -1,186 +1,133 @@
|
|
|
1
|
-
const { EC2Client, DescribeVpcsCommand, DescribeSubnetsCommand } = require("@aws-sdk/client-ec2");
|
|
2
|
-
const {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (
|
|
12
|
-
console.log('
|
|
13
|
-
throw new Error('
|
|
14
|
-
}
|
|
15
|
-
// Get
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
18
|
-
console.log('Err:
|
|
19
|
-
throw new Error('
|
|
20
|
-
}
|
|
21
|
-
// Get
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
console.log(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
async function
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
SubjectAlternativeNames: [ `*.${rootDomain}` ],
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const data = await acmClient.send(new RequestCertificateCommand(params));
|
|
138
|
-
return data.CertificateArn;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
async function getVPC(region){
|
|
142
|
-
console.log('Getting default VPC ID')
|
|
143
|
-
// Initialize an Amazon EC2 client object.
|
|
144
|
-
const ec2Client = new EC2Client({ region }); // replace with your desired region
|
|
145
|
-
const data = await ec2Client.send(new DescribeVpcsCommand({}));
|
|
146
|
-
|
|
147
|
-
// Find the default VPC from the list of VPCs.
|
|
148
|
-
const defaultVpc = data.Vpcs.find(vpc => vpc.IsDefault);
|
|
149
|
-
|
|
150
|
-
// Return the VPC ID if the default VPC is found.
|
|
151
|
-
return defaultVpc.VpcId;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
async function getSubnets(region){
|
|
155
|
-
console.log('Retrieving Subnets')
|
|
156
|
-
const ec2Client = new EC2Client({ region });
|
|
157
|
-
const subnetsData = await ec2Client.send(new DescribeSubnetsCommand({}));
|
|
158
|
-
const subNets = subnetsData.Subnets.filter(s=>{ return s.DefaultForAz === true });
|
|
159
|
-
const subnetList = subNets.map(subnet => subnet.SubnetId );
|
|
160
|
-
return subnetList;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
async function getHostedZoneId(hostedZoneName){
|
|
164
|
-
hostedZoneName += '.';
|
|
165
|
-
const client = new Route53Client({ region: "us-east-1" });
|
|
166
|
-
const command = new ListHostedZonesByNameCommand({ DNSName: hostedZoneName });
|
|
167
|
-
let response;
|
|
168
|
-
try {
|
|
169
|
-
response = await client.send(command);
|
|
170
|
-
} catch(e){
|
|
171
|
-
console.log(e);
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
// Check if we have the desired hosted zone in the response
|
|
177
|
-
if (response.HostedZones && response.HostedZones.length > 0) {
|
|
178
|
-
for (let zone of response.HostedZones) {
|
|
179
|
-
if (zone.Name === hostedZoneName) {
|
|
180
|
-
return zone.Id.split("/").pop(); // Extracting the ID part from the full ARN
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
} else {
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
1
|
+
const { EC2Client, DescribeVpcsCommand, DescribeSubnetsCommand } = require("@aws-sdk/client-ec2");
|
|
2
|
+
const { Route53Client, ListHostedZonesByNameCommand } = require("@aws-sdk/client-route-53");
|
|
3
|
+
|
|
4
|
+
const Params = require('./helpers/params');
|
|
5
|
+
|
|
6
|
+
exports.main = async function(args){
|
|
7
|
+
console.log(`Adding ${args.app} instance ${args.domain} in ${args.region}`)
|
|
8
|
+
if (!args.max){
|
|
9
|
+
console.log('Using default max instance count of 2. Specify -max to override')
|
|
10
|
+
args.max = 2;
|
|
11
|
+
} else if (args.max < 2){
|
|
12
|
+
console.log('-max must be at least 2 to allow proper rolling updates');
|
|
13
|
+
throw new Error('Invalid max instance count');
|
|
14
|
+
}
|
|
15
|
+
// Get App
|
|
16
|
+
const existingApp = await Params.getApp(args.app);
|
|
17
|
+
if (!existingApp){
|
|
18
|
+
console.log('Err: No app named ' + args.app);
|
|
19
|
+
throw new Error('Err: No app named ' + args.app)
|
|
20
|
+
}
|
|
21
|
+
// Get Instance
|
|
22
|
+
const existingInstance = existingApp.instances.find(ins=>{ return ins.domain.toLowerCase() === args.domain.toLowerCase() })
|
|
23
|
+
if (existingInstance){
|
|
24
|
+
console.log('Err: Existing Intance with name ' + args.domain);
|
|
25
|
+
throw new Error('Existing Instance')
|
|
26
|
+
}
|
|
27
|
+
// Get Hosted Zone
|
|
28
|
+
const rootDomain = parseDomain(args.domain);
|
|
29
|
+
const hostedZoneId = await getHostedZoneId(rootDomain);
|
|
30
|
+
if (!hostedZoneId){
|
|
31
|
+
console.log('Err: Hosted zone/domain not found ' + rootDomain);
|
|
32
|
+
throw new Error('Domain not found')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const instanceParams = {
|
|
36
|
+
domain: args.domain,
|
|
37
|
+
region: args.region,
|
|
38
|
+
version: null,
|
|
39
|
+
build: null,
|
|
40
|
+
amiName: null,
|
|
41
|
+
stackName: `${args.app.toUpperCase()}-i-${args.domain.replaceAll(/[^A-Za-z0-9]/ig,'-').toUpperCase()}`,
|
|
42
|
+
cfParams: {
|
|
43
|
+
AmiId: null,
|
|
44
|
+
VpcId: null,
|
|
45
|
+
InstanceSubnets: [],
|
|
46
|
+
InstanceRootDomain: hostedZoneId,
|
|
47
|
+
InstanceDomain: args.domain,
|
|
48
|
+
MaxEc2Instances: args.max || 2,
|
|
49
|
+
AdminEmail: args.admin,
|
|
50
|
+
EC2InstanceType: args.ins || 't3.small',
|
|
51
|
+
InstanceEnvironment: args.env || 'dev'
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Get VPC & Subnets
|
|
56
|
+
instanceParams.cfParams.VpcId = await getVPC(args.region);
|
|
57
|
+
instanceParams.cfParams.InstanceSubnets = await getSubnets(args.region)
|
|
58
|
+
|
|
59
|
+
// Update SSM
|
|
60
|
+
console.log('Updating instance params')
|
|
61
|
+
await Params.addInstance(args.app,args.domain,instanceParams);
|
|
62
|
+
|
|
63
|
+
console.log(`Added instance ${args.domain}`);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//////////////////////////////////////////////////
|
|
68
|
+
//////////////////////////////////////////////////
|
|
69
|
+
/////////////////////////////////////////////////
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
function parseDomain(domain){
|
|
73
|
+
const domainArray = domain.split('.');
|
|
74
|
+
const rootDomainName = domainArray.length === 2 ? domainArray[0] : domainArray[domainArray.length-2]
|
|
75
|
+
const rootDomain = rootDomainName + '.'+ domainArray[domainArray.length-1];
|
|
76
|
+
return rootDomain;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function getVPC(region){
|
|
80
|
+
console.log('Getting default VPC ID')
|
|
81
|
+
// Initialize an Amazon EC2 client object.
|
|
82
|
+
const ec2Client = new EC2Client({ region }); // replace with your desired region
|
|
83
|
+
const data = await ec2Client.send(new DescribeVpcsCommand({}));
|
|
84
|
+
|
|
85
|
+
// Find the default VPC from the list of VPCs.
|
|
86
|
+
const defaultVpc = data.Vpcs.find(vpc => vpc.IsDefault);
|
|
87
|
+
|
|
88
|
+
// Return the VPC ID if the default VPC is found.
|
|
89
|
+
return defaultVpc.VpcId;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function getSubnets(region){
|
|
93
|
+
console.log('Retrieving Subnets')
|
|
94
|
+
const ec2Client = new EC2Client({ region });
|
|
95
|
+
const subnetsData = await ec2Client.send(new DescribeSubnetsCommand({}));
|
|
96
|
+
const subNets = subnetsData.Subnets.filter(s=>{ return s.DefaultForAz === true });
|
|
97
|
+
const subnetList = subNets.map(subnet => subnet.SubnetId );
|
|
98
|
+
return subnetList;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function getHostedZoneId(hostedZoneName){
|
|
102
|
+
hostedZoneName += '.';
|
|
103
|
+
const client = new Route53Client({ region: "us-east-1" });
|
|
104
|
+
const command = new ListHostedZonesByNameCommand({ DNSName: hostedZoneName });
|
|
105
|
+
let response;
|
|
106
|
+
try {
|
|
107
|
+
response = await client.send(command);
|
|
108
|
+
} catch(e){
|
|
109
|
+
console.log(e);
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
// Check if we have the desired hosted zone in the response
|
|
115
|
+
if (response.HostedZones && response.HostedZones.length > 0) {
|
|
116
|
+
for (let zone of response.HostedZones) {
|
|
117
|
+
if (zone.Name === hostedZoneName) {
|
|
118
|
+
return zone.Id.split("/").pop(); // Extracting the ID part from the full ARN
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
async function sleep(time){
|
|
128
|
+
return new Promise(function (resolve, reject) {
|
|
129
|
+
setTimeout(function () { resolve(true);
|
|
130
|
+
}, time);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
package/commands/reset_stack.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
const S3 = require('./helpers/s3')
|
|
2
|
-
const Params= require('./helpers/params');
|
|
3
|
-
const Stacks = require('./helpers/stacks')
|
|
4
|
-
|
|
5
|
-
exports.main = async function(args){
|
|
6
|
-
// Get App
|
|
7
|
-
const app = await Params.getApp(args.app);
|
|
8
|
-
if (!app){
|
|
9
|
-
console.log('Err: No app named ' + args.app);
|
|
10
|
-
throw new Error('Err: No app named ' + args.app)
|
|
11
|
-
}
|
|
12
|
-
// Get Stack
|
|
13
|
-
const stackText = Stacks.get('asg', {lang: 'node'});
|
|
14
|
-
const stackKey = `apps/${args.app.toLowerCase()}/default_stack.yaml`
|
|
15
|
-
|
|
16
|
-
// Reset Default
|
|
17
|
-
console.log('Resetting default stack @ ', stackKey)
|
|
18
|
-
await S3.uploadInfraText(stackKey,stackText);
|
|
19
|
-
|
|
20
|
-
if (!app.versions){ return }
|
|
21
|
-
const versions = Object.keys(app.versions);
|
|
22
|
-
for (let i=0; i<versions.length; i++){
|
|
23
|
-
let k = versions[i]
|
|
24
|
-
let vStackPath = `apps/${args.app.toLowerCase()}/${k}/stack.yaml`
|
|
25
|
-
console.log('Resetting v',k, '@', vStackPath);
|
|
26
|
-
await S3.uploadInfraText(vStackPath,stackText);
|
|
27
|
-
}
|
|
1
|
+
const S3 = require('./helpers/s3')
|
|
2
|
+
const Params= require('./helpers/params');
|
|
3
|
+
const Stacks = require('./helpers/stacks')
|
|
4
|
+
|
|
5
|
+
exports.main = async function(args){
|
|
6
|
+
// Get App
|
|
7
|
+
const app = await Params.getApp(args.app);
|
|
8
|
+
if (!app){
|
|
9
|
+
console.log('Err: No app named ' + args.app);
|
|
10
|
+
throw new Error('Err: No app named ' + args.app)
|
|
11
|
+
}
|
|
12
|
+
// Get Stack
|
|
13
|
+
const stackText = Stacks.get('asg', {lang: 'node'});
|
|
14
|
+
const stackKey = `apps/${args.app.toLowerCase()}/default_stack.yaml`
|
|
15
|
+
|
|
16
|
+
// Reset Default
|
|
17
|
+
console.log('Resetting default stack @ ', stackKey)
|
|
18
|
+
await S3.uploadInfraText(stackKey,stackText);
|
|
19
|
+
|
|
20
|
+
if (!app.versions){ return }
|
|
21
|
+
const versions = Object.keys(app.versions);
|
|
22
|
+
for (let i=0; i<versions.length; i++){
|
|
23
|
+
let k = versions[i]
|
|
24
|
+
let vStackPath = `apps/${args.app.toLowerCase()}/${k}/stack.yaml`
|
|
25
|
+
console.log('Resetting v',k, '@', vStackPath);
|
|
26
|
+
await S3.uploadInfraText(vStackPath,stackText);
|
|
27
|
+
}
|
|
28
28
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const cp = require('child_process');
|
|
4
|
+
|
|
5
|
+
exports.main = function(args){
|
|
6
|
+
// Check Args Valid
|
|
7
|
+
if (!args.type){ throw new Error('Missing type: asg or static') }
|
|
8
|
+
if (args.type === 'asg' && !args.l){ throw new Error('Missing -l language. Specify py or node') }
|
|
9
|
+
|
|
10
|
+
// Resolve Output Path
|
|
11
|
+
const outputPath = path.resolve(args.p);
|
|
12
|
+
const starterPath = `./commands/starters/${args.type}${args.l ? `_${args.l}` : ''}`;
|
|
13
|
+
|
|
14
|
+
// Copy Directory
|
|
15
|
+
console.log(`Creating dir ${outputPath}`);
|
|
16
|
+
fs.mkdirSync(outputPath, { recursive: true });
|
|
17
|
+
console.log(`Adding starter files`);
|
|
18
|
+
fs.cpSync(starterPath, outputPath, {recursive: true,});
|
|
19
|
+
console.log('Running NPM Install');
|
|
20
|
+
cp.execSync(`npm install`, { cwd: outputPath, stdio: 'inherit' });
|
|
21
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const express = require('express');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const Infra = require('./modules/appConfig.js');
|
|
5
|
+
|
|
6
|
+
// Port must be 8080
|
|
7
|
+
const app = express();
|
|
8
|
+
const PORT = 8080;
|
|
9
|
+
|
|
10
|
+
// Use JSON
|
|
11
|
+
app.use(express.json());
|
|
12
|
+
|
|
13
|
+
// Protect Routes
|
|
14
|
+
// User info and cognito groups available in the res.local.user object
|
|
15
|
+
app.use(Infra.verifyUser);
|
|
16
|
+
|
|
17
|
+
// Serve static files from the 'public' directory
|
|
18
|
+
app.use(express.static(path.join(__dirname, 'public')));
|
|
19
|
+
|
|
20
|
+
app.get('/api/health', async (req, res) => {
|
|
21
|
+
let results = ''
|
|
22
|
+
const ddB = Infra.checkDDBConnection().then((res)=>{results += `DDB Connection OK: ${res.ok} [${res.msg}]\n` });
|
|
23
|
+
const s3 = Infra.checkS3Connection().then((res)=>{results += `S3 Connection OK: ${res.ok} [${res.msg}]\n` });
|
|
24
|
+
Promise.all([ddB,s3]).then(()=>{
|
|
25
|
+
res.send(results);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
app.get('/config', async (req, res) => {
|
|
30
|
+
const cnf = {
|
|
31
|
+
app: process.env.$APP_ID,
|
|
32
|
+
region: process.env.$APP_REGION,
|
|
33
|
+
user: res.locals.user,
|
|
34
|
+
version: process.env.$APP_VERSION,
|
|
35
|
+
env: process.env.$APP_ENV
|
|
36
|
+
};
|
|
37
|
+
res.json(cnf);
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
app.get('/whoami', async (req, res) => {
|
|
41
|
+
const logs = [
|
|
42
|
+
`access:${req.headers['x-amzn-oidc-accesstoken']}`,
|
|
43
|
+
`oidc:${req.headers['x-amzn-oidc-data']}`,
|
|
44
|
+
`user:${req.headers['x-amzn-oidc-identity']}`
|
|
45
|
+
];
|
|
46
|
+
console.log(logs.join('\n'));
|
|
47
|
+
res.json(res.locals.user);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
app.get('/log', async (req, res) => {
|
|
51
|
+
console.log('log>>',req.query);
|
|
52
|
+
res.send('OK');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Start Server
|
|
56
|
+
Infra.setParams(__dirname).then(()=>{
|
|
57
|
+
console.log(`Starting Server for ${process.env.$APP_ID} in ${process.env.$APP_REGION}`,true);
|
|
58
|
+
app.listen(PORT, async () => {
|
|
59
|
+
console.log(`${process.env.$APP_ID} running on http://localhost:${PORT} in ${process.env.$APP_REGION}`);
|
|
60
|
+
console.log(`Boot Complete ${process.env.$APP_ID}@${process.env.$APP_REGION}:${process.env.$APP_ENV}`,true);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
us-west-2,MEANTTO-i-TEST-ELMNTS-XYZ,local
|