Skip to content

Commit 18493a0

Browse files
authored
Merge pull request #3 from philips-labs/feature/runners-lambdas
Base setup for scaling and cleanup lambdas
2 parents 1b9a245 + afe136f commit 18493a0

39 files changed

+5777
-43
lines changed

.ci/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node:12
2+
3+
WORKDIR /lambda
4+
5+
COPY . /lambda
6+
7+
RUN apt-get update \
8+
&& apt-get install -y zip \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
RUN yarn install \
12+
&& yarn run dist
13+

.ci/build.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
lambaSrcDirs=("modules/runner-binaries-syncer/lambdas/runner-binaries-syncer" "modules/runners/lambdas/scale-runners" "modules/webhook/lambdas/webhook")
4+
repoRoot=$(dirname "${BASH_SOURCE[0]}")/..
5+
6+
for lambdaDir in ${lambaSrcDirs[@]}; do
7+
cd $repoRoot/${lambdaDir}
8+
docker build -t lambda -f ../../../../.ci/Dockerfile .
9+
docker create --name lambda lambda
10+
zipName=$(basename "$PWD")
11+
docker cp lambda:/lambda/${zipName}.zip ${zipName}.zip
12+
docker rm lambda
13+
done
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Lambda Scale Runners
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
paths:
8+
- .github/workflows/lambda-scale-runners.yml
9+
- "modules/runners/lambdas/scale-runners/**"
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
container: node:12
15+
defaults:
16+
run:
17+
working-directory: modules/runners/lambdas/scale-runners
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: Install dependencies
22+
run: yarn install
23+
- name: Run tests
24+
run: yarn test
25+
- name: Build distribution
26+
run: yarn build

.github/workflows/terraform.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ jobs:
1919
- name: "Checkout"
2020
uses: actions/checkout@v2
2121
- name: "Fake zip files" # Validate will fail if it cannot find the zip files
22-
run:
23-
touch modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/runner-binaries-syncer.zip
22+
run: |
2423
touch modules/webhook/lambdas/webhook/webhook.zip
24+
touch modules/runners/lambdas/scale-runners/scale-runners.zip
25+
touch modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/runner-binaries-syncer.zip
2526
- name: "Terraform Format"
2627
uses: hashicorp/terraform-github-actions@master
2728
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ example/*.secrets*.tfvars
1616
*.zip
1717
*.gz
1818
*.tgz
19+
*.env

examples/default/main.tf

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,28 @@ resource "random_password" "random" {
88
length = 32
99
}
1010

11-
1211
module "runners" {
1312
source = "../../"
1413

1514
aws_region = local.aws_region
1615
vpc_id = module.vpc.vpc_id
16+
subnet_ids = module.vpc.private_subnets
1717

1818
environment = local.environment
1919
tags = {
2020
Project = "ProjectX"
2121
}
2222

23-
github_app_webhook_secret = random_password.random.result
23+
github_app = {
24+
key_base64 = var.github_app_key_base64
25+
id = var.github_app_id
26+
client_id = var.github_app_client_id
27+
client_secret = var.github_app_client_secret
28+
webhook_secret = random_password.random.result
29+
}
2430

31+
enable_organization_runners = false
32+
runner_extra_labels = "default,example"
2533
}
2634

2735

examples/default/outputs.tf

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
output "action_runners" {
1+
output "runners" {
22
value = {
33
runners = module.runners.runners
44
}
55
}
66

7-
8-
output "lambda_binaries_syncer_name" {
9-
value = module.runners.binaries_syncer.lambda.id
10-
}
11-
12-
13-
output "github_app_webhook_secret" {
14-
value = random_password.random.result
7+
output "webhook" {
8+
value = {
9+
secret = random_password.random.result
10+
gateway = module.runners.webhook.gateway
11+
}
1512
}
16-
17-

examples/default/providers.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
provider "aws" {
22
region = local.aws_region
3-
version = "2.59"
3+
version = "2.61"
44
}
55

examples/default/variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
variable "github_app_key_base64" {}
3+
4+
variable "github_app_id" {}
5+
6+
variable "github_app_client_id" {}
7+
8+
variable "github_app_client_secret" {}
9+

main.tf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ resource "random_string" "random" {
1515
resource "aws_sqs_queue" "queued_builds" {
1616
name = "${var.environment}-queued-builds.fifo"
1717
delay_seconds = 30
18+
visibility_timeout_seconds = 60
1819
fifo_queue = true
1920
receive_wait_time_seconds = 10
2021
content_based_deduplication = true
@@ -30,19 +31,27 @@ module "webhook" {
3031
tags = local.tags
3132

3233
sqs_build_queue = aws_sqs_queue.queued_builds
33-
github_app_webhook_secret = var.github_app_webhook_secret
34+
github_app_webhook_secret = var.github_app.webhook_secret
3435
}
3536

3637
module "runners" {
3738
source = "./modules/runners"
3839

3940
aws_region = var.aws_region
4041
vpc_id = var.vpc_id
42+
subnet_ids = var.subnet_ids
4143
environment = var.environment
4244
tags = local.tags
4345

4446
s3_bucket_runner_binaries = module.runner_binaries.bucket
4547
s3_location_runner_binaries = local.s3_action_runner_url
48+
49+
sqs = aws_sqs_queue.queued_builds
50+
github_app = var.github_app
51+
enable_organization_runners = var.enable_organization_runners
52+
scale_down_schedule_expression = var.scale_down_schedule_expression
53+
minimum_running_time_in_minutes = var.minimum_running_time_in_minutes
54+
runner_extra_labels = var.runner_extra_labels
4655
}
4756

4857
module "runner_binaries" {

0 commit comments

Comments
 (0)