Skip to content

Commit 8307c5d

Browse files
committed
Use AWS Lambda instead of Docker to compile Java
1 parent c3c3205 commit 8307c5d

File tree

8 files changed

+138
-13
lines changed

8 files changed

+138
-13
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ Are you a first-timer in contributing to open source? [These guidelines](https:/
2020

2121
4. Create `.env.local` in the project root:
2222
```bash
23+
# By putting dummy values, GitHub sign in will not work locally
2324
GITHUB_CLIENT_ID = dummy
2425
GITHUB_CLIENT_SECRET = dummy
26+
27+
# By putting dummy values, extracting visualizing commands will not work locally (except for JavaScript).
28+
AWS_ACCESS_KEY_ID = dummy
29+
AWS_SECRET_ACCESS_KEY = dummy
2530
```
26-
It's safe to put any dummy value to them unless you need the GitHub sign in functionality locally.
2731

2832
5. Install dependencies, and run the server.
2933

package-lock.json

Lines changed: 89 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"tslint": "^5.16.0"
2727
},
2828
"dependencies": {
29+
"aws-sdk": "^2.480.0",
2930
"axios": "^0.19.0",
3031
"body-parser": "^1.18.2",
3132
"compression": "^1.7.3",

src/config/environments.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ const {
2727

2828
GITHUB_CLIENT_ID,
2929
GITHUB_CLIENT_SECRET,
30+
31+
AWS_ACCESS_KEY_ID,
32+
AWS_SECRET_ACCESS_KEY,
3033
} = process.env;
3134

3235
const isEnabled = (v: string) => v === '1';
@@ -48,6 +51,8 @@ const missingVars = [
4851
] : []),
4952
'GITHUB_CLIENT_ID',
5053
'GITHUB_CLIENT_SECRET',
54+
'AWS_ACCESS_KEY_ID',
55+
'AWS_SECRET_ACCESS_KEY',
5156
].filter(variable => process.env[variable] === undefined);
5257
if (missingVars.length) throw new Error(`The following environment variables are missing: ${missingVars.join(', ')}`);
5358

@@ -71,3 +76,6 @@ export const credentials: ServerOptions | undefined = isEnabled(CREDENTIALS_ENAB
7176

7277
export const githubClientId = GITHUB_CLIENT_ID;
7378
export const githubClientSecret = GITHUB_CLIENT_SECRET;
79+
80+
export const awsAccessKeyId = AWS_ACCESS_KEY_ID;
81+
export const awsSecretAccessKey = AWS_SECRET_ACCESS_KEY;

src/tracers/DockerTracer.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ export class DockerTracer extends Tracer {
1515
super(lang);
1616
this.directory = path.resolve(__dirname, lang);
1717
this.imageName = `tracer-${this.lang}`;
18-
19-
this.build = this.build.bind(this);
2018
}
2119

2220
build(release: Release) {

src/tracers/LambdaTracer.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import AWS from 'aws-sdk';
2+
import express from 'express';
3+
import { Release, Tracer } from 'tracers/Tracer';
4+
import { awsAccessKeyId, awsSecretAccessKey } from 'config/environments';
5+
import { BadRequest } from 'ts-httpexceptions';
6+
7+
export class LambdaTracer extends Tracer {
8+
static lambda = new AWS.Lambda({
9+
region: 'us-east-2',
10+
accessKeyId: awsAccessKeyId,
11+
secretAccessKey: awsSecretAccessKey,
12+
});
13+
14+
async build(release: Release) {
15+
}
16+
17+
route(router: express.Router) {
18+
router.post(`/${this.lang}`, (req, res, next) => {
19+
const {code} = req.body;
20+
LambdaTracer.lambda.invoke({
21+
FunctionName: `extractor-${this.lang}`,
22+
InvocationType: 'RequestResponse',
23+
Payload: JSON.stringify(code),
24+
}, function (err, data) {
25+
if (err) return next(err);
26+
if (typeof data.Payload !== 'string') return next(new Error('Unexpected Payload Type'));
27+
const payload = JSON.parse(data.Payload);
28+
if (!payload.success) return next(new BadRequest(payload.errorMessage));
29+
res.send(payload.commands);
30+
});
31+
});
32+
}
33+
}

src/tracers/java/Dockerfile

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/tracers/java/JavaTracer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { DockerTracer } from 'tracers/DockerTracer';
1+
import { LambdaTracer } from 'tracers/LambdaTracer';
22

3-
export class JavaTracer extends DockerTracer {
3+
export class JavaTracer extends LambdaTracer {
44
constructor() {
55
super('java');
66
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy