Skip to content

Commit dd05844

Browse files
authored
Merge pull request #1592 from philips-labs/develop
Release
2 parents 14ad11f + 27e974d commit dd05844

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+2791
-1643
lines changed

.ci/build-yarn.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
# Build all the lambda's, output on the default place (inside the lambda module)
4+
5+
lambdaSrcDirs=("modules/runner-binaries-syncer/lambdas/runner-binaries-syncer" "modules/runners/lambdas/runners" "modules/webhook/lambdas/webhook")
6+
repoRoot=$(dirname $(dirname $(realpath ${BASH_SOURCE[0]})))
7+
8+
for lambdaDir in ${lambdaSrcDirs[@]}; do
9+
cd "$repoRoot/${lambdaDir}"
10+
yarn && yarn run dist
11+
done

.github/workflows/packer-build.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@ jobs:
1818
runs-on: ubuntu-latest
1919
container:
2020
image: hashicorp/packer:1.7.8
21+
strategy:
22+
matrix:
23+
image: ["linux-amzn2", "windows-core-2019"]
2124
defaults:
2225
run:
23-
working-directory: images/linux-amzn2
26+
working-directory: images/${{ matrix.image }}
2427
steps:
2528
- name: "Checkout"
2629
uses: actions/checkout@v2
2730

2831
- name: packer init
2932
run: packer init .
3033

31-
- name: check terraform formatting
34+
- name: check packer formatting
3235
run: packer fmt -recursive -check=true .
3336

3437
- name: packer validate

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191

9292
steps:
9393
- name: Generate provenance for release
94-
uses: philips-labs/slsa-provenance-action@v0.4.0
94+
uses: philips-labs/slsa-provenance-action@v0.5.0
9595
with:
9696
artifact_path: release-assets
9797
output_path: 'build.provenance'

README.md

Lines changed: 54 additions & 43 deletions
Large diffs are not rendered by default.

examples/default/main.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ module "runners" {
3030
webhook_secret = random_id.random.hex
3131
}
3232

33+
# Grab zip files via lambda_download
3334
webhook_lambda_zip = "lambdas-download/webhook.zip"
3435
runner_binaries_syncer_lambda_zip = "lambdas-download/runner-binaries-syncer.zip"
3536
runners_lambda_zip = "lambdas-download/runners.zip"
36-
enable_organization_runners = false
37-
runner_extra_labels = "default,example"
37+
38+
enable_organization_runners = false
39+
runner_extra_labels = "default,example"
3840

3941
# enable access to the runners via SSM
4042
enable_ssm_on_runners = true
@@ -61,7 +63,11 @@ module "runners" {
6163
instance_types = ["m5.large", "c5.large"]
6264

6365
# override delay of events in seconds
64-
delay_webhook_event = 5
66+
delay_webhook_event = 5
67+
runners_maximum_count = 1
68+
69+
# set up a fifo queue to remain order
70+
fifo_build_queue = true
6571

6672
# override scaling down
6773
scale_down_schedule_expression = "cron(* * * * ? *)"

examples/ephemeral/.terraform.lock.hcl

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

examples/ephemeral/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Action runners deployment ephemeral example
2+
3+
This example is based on the default setup, but shows how runners can be used with the ephemeral flag enabled. Once enabled, ephemeral runners will be used for one job only. Each job requires a fresh instance. This feature should be used in combination with the `workflow_job` event. See GitHub webhook endpoint configuration(link needed here). It is also suggested to use a pre-build AMI to minimize runner launch times.
4+
## Usages
5+
6+
Steps for the full setup, such as creating a GitHub app can be found in the root module's [README](../../README.md). First download the Lambda releases from GitHub. Alternatively you can build the lambdas locally with Node or Docker, there is a simple build script in `<root>/.ci/build.sh`. In the `main.tf` you can simply remove the location of the lambda zip files, the default location will work in this case.
7+
8+
> Ensure you have set the version in `lambdas-download/main.tf` for running the example. The version needs to be set to a GitHub release version, see https://github.com/philips-labs/terraform-aws-github-runner/releases
9+
10+
```bash
11+
cd lambdas-download
12+
terraform init
13+
terraform apply
14+
cd ..
15+
```
16+
17+
Before running Terraform, ensure the GitHub app is configured. See the [configuration details](../../README.md#usages) for more details.
18+
19+
```bash
20+
terraform init
21+
terraform apply
22+
```
23+
24+
You can receive the webhook details by running:
25+
26+
```bash
27+
terraform output -raw webhook_secret
28+
```
29+
30+
Be-aware some shells will print some end of line character `%`.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
locals {
2+
version = "<REPLACE_BY_GITHUB_RELEASE_VERSION>"
3+
}
4+
5+
module "lambdas" {
6+
source = "../../../modules/download-lambda"
7+
lambdas = [
8+
{
9+
name = "webhook"
10+
tag = local.version
11+
},
12+
{
13+
name = "runners"
14+
tag = local.version
15+
},
16+
{
17+
name = "runner-binaries-syncer"
18+
tag = local.version
19+
}
20+
]
21+
}
22+
23+
output "files" {
24+
value = module.lambdas.files
25+
}

examples/ephemeral/main.tf

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
locals {
2+
environment = "ephemeral"
3+
aws_region = "eu-west-1"
4+
}
5+
6+
resource "random_id" "random" {
7+
byte_length = 20
8+
}
9+
10+
data "aws_caller_identity" "current" {}
11+
12+
module "runners" {
13+
source = "../../"
14+
create_service_linked_role_spot = true
15+
aws_region = local.aws_region
16+
vpc_id = module.vpc.vpc_id
17+
subnet_ids = module.vpc.private_subnets
18+
19+
environment = local.environment
20+
tags = {
21+
Project = "ProjectX"
22+
}
23+
24+
github_app = {
25+
key_base64 = var.github_app_key_base64
26+
id = var.github_app_id
27+
webhook_secret = random_id.random.hex
28+
}
29+
30+
# Grab the lambda packages from local directory. Must run /.ci/build.sh first
31+
webhook_lambda_zip = "../../lambda_output/webhook.zip"
32+
runner_binaries_syncer_lambda_zip = "../../lambda_output/runner-binaries-syncer.zip"
33+
runners_lambda_zip = "../../lambda_output/runners.zip"
34+
35+
enable_organization_runners = true
36+
runner_extra_labels = "default,example"
37+
38+
# enable access to the runners via SSM
39+
enable_ssm_on_runners = true
40+
41+
# Let the module manage the service linked role
42+
# create_service_linked_role_spot = true
43+
44+
instance_types = ["m5.large", "c5.large"]
45+
46+
# override delay of events in seconds
47+
delay_webhook_event = 0
48+
49+
# Ensure you set the number not too low, each build require a new instance
50+
runners_maximum_count = 20
51+
52+
# override scaling down
53+
scale_down_schedule_expression = "cron(* * * * ? *)"
54+
55+
enable_ephemeral_runners = true
56+
57+
# configure your pre-built AMI
58+
# enabled_userdata = false
59+
# ami_filter = { name = ["github-runner-amzn2-x86_64-2021*"] }
60+
# ami_owners = [data.aws_caller_identity.current.account_id]
61+
62+
# Enable logging
63+
# log_level = "debug"
64+
65+
# Setup a dead letter queue, by default scale up lambda will kepp retrying to process event in case of scaling error.
66+
# redrive_policy_build_queue = {
67+
# enabled = true
68+
# maxReceiveCount = 50 # 50 retries every 30 seconds => 25 minutes
69+
# deadLetterTargetArn = null
70+
# }
71+
}

examples/ephemeral/outputs.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
output "runners" {
2+
value = {
3+
lambda_syncer_name = module.runners.binaries_syncer.lambda.function_name
4+
}
5+
}
6+
7+
output "webhook_endpoint" {
8+
value = module.runners.webhook.endpoint
9+
}
10+
11+
output "webhook_secret" {
12+
sensitive = true
13+
value = random_id.random.hex
14+
}
15+

examples/ephemeral/providers.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider "aws" {
2+
region = local.aws_region
3+
}

examples/ephemeral/variables.tf

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

examples/ephemeral/versions.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = ">= 3.27"
6+
}
7+
local = {
8+
source = "hashicorp/local"
9+
}
10+
random = {
11+
source = "hashicorp/random"
12+
}
13+
}
14+
required_version = ">= 0.14"
15+
}

examples/ephemeral/vpc.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module "vpc" {
2+
source = "git::https://github.com/philips-software/terraform-aws-vpc.git?ref=2.2.0"
3+
4+
environment = local.environment
5+
aws_region = local.aws_region
6+
create_private_hosted_zone = false
7+
}

examples/prebuilt/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ This module shows how to create GitHub action runners using a prebuilt AMI for t
44

55
## Usages
66

7-
Steps for the full setup, such as creating a GitHub app can be found in the root module's [README](../../README.md).
7+
Steps for the full setup, such as creating a GitHub app can be found in the root module's [README](../../README.md).
8+
9+
## Variables
10+
11+
| Name | Description | Type | Default | Required |
12+
|------|-------------|------|---------|:--------:|
13+
| <a name="input_ami_filter"></a> [ami\_filter](#input\_ami\_filter) | The amis to search. Use the default for the provided amazon linux image, `github-runner-windows-core-2019-*` for the provided widnows image | `string` | `github-runner-amzn2-x86_64-2021*` | no |
14+
| <a name="input_github_app_key_base64"></a> [github\_app\_key\_base64](#input\_github\_app\_key\_base64) | The base64 encoded private key you downloaded from GitHub when creating the app | `string` | | yes |
15+
| <a name="input_github_app_id"></a> [github\_app\_id](#input\_github\_app\_id) | The id of the app you created on GitHub | `string` | | yes |
16+
| <a name="input_region"></a> [region](#input\_region) | The target aws region | `string` | `eu-west-1` | no |
17+
| <a name="input_runner_os"></a> [runner\_os](#input\_runner\_os) | The os of the image, either `linux` or `windows` | `string` | `linux` | no |
818

919
### Lambdas
1020

examples/prebuilt/main.tf

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
locals {
22
environment = "prebuilt"
3-
aws_region = "eu-west-1"
43
}
54

65
resource "random_id" "random" {
@@ -12,7 +11,7 @@ data "aws_caller_identity" "current" {}
1211
module "runners" {
1312
source = "../../"
1413
create_service_linked_role_spot = true
15-
aws_region = local.aws_region
14+
aws_region = var.aws_region
1615
vpc_id = module.vpc.vpc_id
1716
subnet_ids = module.vpc.private_subnets
1817

@@ -24,15 +23,17 @@ module "runners" {
2423
webhook_secret = random_id.random.hex
2524
}
2625

27-
webhook_lambda_zip = "../../lambda_output/webhook.zip"
28-
runner_binaries_syncer_lambda_zip = "../../lambda_output/runner-binaries-syncer.zip"
29-
runners_lambda_zip = "../../lambda_output/runners.zip"
26+
webhook_lambda_zip = "lambdas-download/webhook.zip"
27+
runner_binaries_syncer_lambda_zip = "lambdas-download/runner-binaries-syncer.zip"
28+
runners_lambda_zip = "lambdas-download/runners.zip"
3029

3130
runner_extra_labels = "default,example"
3231

32+
runner_os = var.runner_os
33+
3334
# configure your pre-built AMI
3435
enabled_userdata = false
35-
ami_filter = { name = ["github-runner-amzn2-x86_64-2021*"] }
36+
ami_filter = { name = [var.ami_name_filter] }
3637
ami_owners = [data.aws_caller_identity.current.account_id]
3738

3839
# enable access to the runners via SSM

examples/prebuilt/providers.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
provider "aws" {
2-
region = local.aws_region
2+
region = var.aws_region
33
}

examples/prebuilt/variables.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,18 @@
22
variable "github_app_key_base64" {}
33

44
variable "github_app_id" {}
5+
6+
variable "runner_os" {
7+
type = string
8+
default = "linux"
9+
}
10+
11+
variable "ami_name_filter" {
12+
type = string
13+
default = "github-runner-amzn2-x86_64-2021*"
14+
}
15+
16+
variable "aws_region" {
17+
type = string
18+
default = "eu-west-1"
19+
}

0 commit comments

Comments
 (0)