-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from philips-labs/feature/runners-lambdas
Base setup for scaling and cleanup lambdas
- Loading branch information
Showing
39 changed files
with
5,777 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM node:12 | ||
|
||
WORKDIR /lambda | ||
|
||
COPY . /lambda | ||
|
||
RUN apt-get update \ | ||
&& apt-get install -y zip \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN yarn install \ | ||
&& yarn run dist | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
lambaSrcDirs=("modules/runner-binaries-syncer/lambdas/runner-binaries-syncer" "modules/runners/lambdas/scale-runners" "modules/webhook/lambdas/webhook") | ||
repoRoot=$(dirname "${BASH_SOURCE[0]}")/.. | ||
|
||
for lambdaDir in ${lambaSrcDirs[@]}; do | ||
cd $repoRoot/${lambdaDir} | ||
docker build -t lambda -f ../../../../.ci/Dockerfile . | ||
docker create --name lambda lambda | ||
zipName=$(basename "$PWD") | ||
docker cp lambda:/lambda/${zipName}.zip ${zipName}.zip | ||
docker rm lambda | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Lambda Scale Runners | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
paths: | ||
- .github/workflows/lambda-scale-runners.yml | ||
- "modules/runners/lambdas/scale-runners/**" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
container: node:12 | ||
defaults: | ||
run: | ||
working-directory: modules/runners/lambdas/scale-runners | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install dependencies | ||
run: yarn install | ||
- name: Run tests | ||
run: yarn test | ||
- name: Build distribution | ||
run: yarn build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ example/*.secrets*.tfvars | |
*.zip | ||
*.gz | ||
*.tgz | ||
*.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
output "action_runners" { | ||
output "runners" { | ||
value = { | ||
runners = module.runners.runners | ||
} | ||
} | ||
|
||
|
||
output "lambda_binaries_syncer_name" { | ||
value = module.runners.binaries_syncer.lambda.id | ||
} | ||
|
||
|
||
output "github_app_webhook_secret" { | ||
value = random_password.random.result | ||
output "webhook" { | ||
value = { | ||
secret = random_password.random.result | ||
gateway = module.runners.webhook.gateway | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
provider "aws" { | ||
region = local.aws_region | ||
version = "2.59" | ||
version = "2.61" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
variable "github_app_key_base64" {} | ||
|
||
variable "github_app_id" {} | ||
|
||
variable "github_app_client_id" {} | ||
|
||
variable "github_app_client_secret" {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# dependencies | ||
node_modules/ | ||
|
||
# production | ||
dist/ | ||
build/ | ||
|
||
# misc | ||
.DS_Store | ||
.env* | ||
*.zip | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v12.16.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"printWidth": 120, | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "github-runner-lambda-scale-runners", | ||
"version": "1.0.0", | ||
"main": "lambda.ts", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "ts-node-dev src/local.ts", | ||
"test": "NODE_ENV=test jest", | ||
"watch": "ts-node-dev --respawn --exit-child src/local.ts", | ||
"build": "ncc build src/lambda.ts -o dist", | ||
"dist": "yarn build && cd dist && zip ../scale-runners.zip index.js" | ||
}, | ||
"devDependencies": { | ||
"@types/aws-lambda": "^8.10.51", | ||
"@types/express": "^4.17.3", | ||
"@types/jest": "^25.2.1", | ||
"@types/node": "^13.13.4", | ||
"@zeit/ncc": "^0.22.1", | ||
"aws-sdk": "^2.671.0", | ||
"jest": "^25.4.0", | ||
"ts-jest": "^25.4.0", | ||
"ts-node-dev": "^1.0.0-pre.44", | ||
"typescript": "^3.8.3" | ||
}, | ||
"dependencies": { | ||
"@octokit/auth-app": "^2.4.5", | ||
"@octokit/rest": "^17.6.0", | ||
"moment": "^2.25.3", | ||
"yn": "^4.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { scaleUp } from './scale-runners/scale-up'; | ||
import { scaleDown } from './scale-runners/scale-down'; | ||
import { SQSEvent } from 'aws-lambda'; | ||
|
||
module.exports.scaleUp = async (event: SQSEvent, context: any, callback: any) => { | ||
console.log(event); | ||
try { | ||
for (const e of event.Records) { | ||
await scaleUp(e.eventSource, JSON.parse(e.body)); | ||
} | ||
return callback(null); | ||
} catch (e) { | ||
console.error(e); | ||
return callback('Failed handling SQS event'); | ||
} | ||
}; | ||
|
||
module.exports.scaleDown = async (event: any, context: any, callback: any) => { | ||
try { | ||
scaleDown(); | ||
return callback(null); | ||
} catch (e) { | ||
console.error(e); | ||
return callback('Failed'); | ||
} | ||
}; |
Oops, something went wrong.