Skip to content

Commit 3905b73

Browse files
committed
Base setup for scaling and cleanup lambdas
1 parent 285c362 commit 3905b73

File tree

19 files changed

+9011
-0
lines changed

19 files changed

+9011
-0
lines changed

modules/runners/lambdas/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# dependencies
2+
node_modules/
3+
4+
# production
5+
dist/
6+
build/
7+
8+
# misc
9+
.DS_Store
10+
.env*
11+
*.zip
12+
13+
npm-debug.log*
14+
yarn-debug.log*
15+
yarn-error.log*
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v12.16.1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"printWidth": 120,
3+
"singleQuote": true,
4+
"trailingComma": "all"
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "github-runner-lambda-cleanup-runners",
3+
"version": "1.0.0",
4+
"main": "lambda.ts",
5+
"license": "MIT",
6+
"scripts": {
7+
"start": "ts-node-dev src/local.ts",
8+
"test": "NODE_ENV=test jest",
9+
"watch": "ts-node-dev --respawn --exit-child src/local.ts",
10+
"build": "ncc build src/lambda.ts -o dist",
11+
"dist": "yarn build && cd dist && zip ../cleanup-runners.zip index.js"
12+
},
13+
"devDependencies": {
14+
"@types/express": "^4.17.3",
15+
"@types/jest": "^25.2.1",
16+
"@types/node": "^13.13.4",
17+
"@zeit/ncc": "^0.22.1",
18+
"aws-sdk": "^2.645.0",
19+
"body-parser": "^1.19.0",
20+
"express": "^4.17.1",
21+
"jest": "^25.4.0",
22+
"ts-jest": "^25.4.0",
23+
"ts-node-dev": "^1.0.0-pre.44",
24+
"typescript": "^3.8.3"
25+
},
26+
"dependencies": {}
27+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const handle = async (headers: IncomingHttpHeaders, payload: any): Promise<number> => {
2+
return 200;
3+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { handle } from './cleanup-runners/handler';
2+
3+
module.exports.handler = async (event: any, context: any, callback: any) => {
4+
const statusCode = await handle(event.headers, event.body);
5+
return callback(null, {
6+
statusCode: statusCode,
7+
});
8+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import express from 'express';
2+
import bodyParser from 'body-parser';
3+
import { handle } from './cleanup-runners/handler';
4+
5+
const app = express();
6+
7+
app.use(bodyParser.json());
8+
9+
app.post('/event_handler', (req, res) => {
10+
handle(req.headers, JSON.stringify(req.body))
11+
.then((c) => res.status(c).end())
12+
.catch((e) => {
13+
console.log(e);
14+
res.status(404);
15+
});
16+
});
17+
18+
app.listen(3000, (): void => {
19+
console.log('webhook app listening on port 3000!');
20+
});
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"compilerOptions": {
3+
/* Basic Options */
4+
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
5+
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
6+
"outDir": "build",
7+
"lib": ["es2020", "DOM"] /* Specify library files to be included in the compilation. */,
8+
"allowJs": true /* Allow javascript files to be compiled. */,
9+
// "checkJs": true, /* Report errors in .js files. */
10+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
11+
// "declaration": true, /* Generates corresponding '.d.ts' file. */
12+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
13+
// "sourceMap": true, /* Generates corresponding '.map' file. */
14+
// "outFile": "./", /* Concatenate and emit output to single file. */
15+
// "outDir": "./", /* Redirect output structure to the directory. */
16+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
17+
// "composite": true, /* Enable project compilation */
18+
// "incremental": true, /* Enable incremental compilation */
19+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
20+
// "removeComments": true, /* Do not emit comments to output. */
21+
// "noEmit": true, /* Do not emit outputs. */
22+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
23+
"downlevelIteration": true /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */,
24+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
25+
/* Strict Type-Checking Options */
26+
"strict": true /* Enable all strict type-checking options. */,
27+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
28+
// "strictNullChecks": true, /* Enable strict null checks. */
29+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
30+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
31+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
32+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
33+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
34+
/* Additional Checks */
35+
// "noUnusedLocals": true, /* Report errors on unused locals. */
36+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
37+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
38+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
39+
/* Module Resolution Options */
40+
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
41+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
42+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
43+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
44+
// "typeRoots": [] /* List of folders to include type definitions from. */,
45+
// "types": [] /* Type declaration files to be included in compilation. */,
46+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
47+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
48+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
49+
/* Source Map Options */
50+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
51+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
52+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
53+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
54+
/* Experimental Options */
55+
"experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
56+
"emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */,
57+
"resolveJsonModule": true
58+
},
59+
"include": ["src/**/*"]
60+
}

0 commit comments

Comments
 (0)