Skip to content

Commit 8915b5a

Browse files
committed
Add option to download lambd's
1 parent 03c783a commit 8915b5a

File tree

7 files changed

+114
-4
lines changed

7 files changed

+114
-4
lines changed

.github/workflows/lambda-runners.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Lambda Runners
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
paths:
8+
- .github/workflows/lambda-runners.yml
9+
- "modules/runners/lambdas/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/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

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,36 @@ Go to GitHub and create a new app. Beware you can create apps your organization
6262

6363
### Setup terraform module
6464

65-
1. Create a terraform workspace and initiate the module, see the examples for more details.
65+
First you need to download the lambda's releases. THe lambda code is available as a GitHub release asset. Downloading can be done with the provided terraform module for example. Create in an empty workspace a terraform module:
66+
67+
```terraform
68+
module "lambdas" {
69+
source = "../../../modules/download-lambda"
70+
lambdas = [
71+
{
72+
name = "webhook"
73+
tag = "v0.0.0-beta"
74+
},
75+
{
76+
name = "runners"
77+
tag = "v0.0.0-beta"
78+
},
79+
{
80+
name = "runner-binaries-syncer"
81+
tag = "v0.0.0-beta"
82+
}
83+
]
84+
}
85+
86+
output "files" {
87+
value = module.lambdas.files
88+
}
89+
```
90+
91+
Next run `terraform init && terraform apply` as result the lambdas will be download to the same directory.
92+
93+
94+
Next create a second terraform workspace and initiate the module, see the examples for more details.
6695

6796
```terraform
6897
module "runners" {
@@ -82,6 +111,9 @@ module "runners" {
82111
webhook_secret = "secret"
83112
}
84113
114+
webhook_lambda_zip = "lambdas-download/webhook.zip"
115+
runner_binaries_syncer_lambda_zip = "lambdas-download/runner-binaries-syncer.zip.zip"
116+
runners_lambda_zip = "lambdas-download/runners.zip"
85117
enable_organization_runners = true
86118
}
87119
```
@@ -93,7 +125,7 @@ terraform init
93125
terrafrom apply
94126
```
95127

96-
3. Check the terraform output for the API gateway url, which you need in the next step.
128+
Check the terraform output for the API gateway url, which you need in the next step. The lambda for syncing the GitHub distribution will be executed by a trigger via Cloud Watch. To ensure the binary is cached, trigger the `runner-binaries-syncer` manually. The payload does not matter.
97129

98130
### Setup GitHub App (part 2)
99131

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module "lambdas" {
2+
source = "../../../modules/download-lambda"
3+
lambdas = [
4+
{
5+
name = "webhook"
6+
tag = "v0.0.0-beta"
7+
},
8+
{
9+
name = "runners"
10+
tag = "v0.0.0-beta"
11+
},
12+
{
13+
name = "runner-binaries-syncer"
14+
tag = "v0.0.0-beta"
15+
}
16+
]
17+
}
18+
19+
output "files" {
20+
value = module.lambdas.files
21+
}

examples/default/main.tf

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

11+
12+
13+
14+
15+
1116
module "runners" {
1217
source = "../../"
1318

@@ -28,8 +33,11 @@ module "runners" {
2833
webhook_secret = random_password.random.result
2934
}
3035

31-
enable_organization_runners = false
32-
runner_extra_labels = "default,example"
36+
webhook_lambda_zip = "lambdas-download/webhook.zip"
37+
runner_binaries_syncer_lambda_zip = "lambdas-download/syncer.zip"
38+
runners_lambda_zip = "lambdas-download/runners.zip"
39+
enable_organization_runners = false
40+
runner_extra_labels = "default,example"
3341
}
3442

3543

modules/download-lambda/main.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
resource "null_resource" "download" {
2+
count = length(var.lambdas)
3+
4+
triggers = {
5+
name = var.lambdas[count.index].name
6+
file = "${var.lambdas[count.index].name}.zip"
7+
tag = var.lambdas[count.index].tag
8+
}
9+
10+
provisioner "local-exec" {
11+
command = "curl -o ${self.triggers.file} -L https://github.com/philips-labs/terraform-aws-github-runner/releases/download/${self.triggers.tag}/${self.triggers.name}-${self.triggers.tag}.zip"
12+
}
13+
}

modules/download-lambda/outputs.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "files" {
2+
value = null_resource.download.*.triggers.file
3+
}

modules/download-lambda/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
variable "lambdas" {
2+
description = "Name and tag for lambdas to download."
3+
type = list(object({
4+
name = string
5+
tag = string
6+
}))
7+
}

0 commit comments

Comments
 (0)