-
Notifications
You must be signed in to change notification settings - Fork 679
add option ephemeral runners #1374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
0b5d97f
add option ephemeral runners
npalm 585d5ed
fix tests
npalm 89e3a37
Add retry mechanisme for scaling errors
npalm d70e338
Add retry mechanisme for scaling errors
npalm 4c982e5
Add tests for lamda handler
npalm e9f360e
Add basic test for ephemeral case
npalm f26673a
Add basic test for scale down in lambda wrapper
npalm ad16d80
Ensure check_runs are ignored for ephemeral runners
npalm 5fb7237
limit termination to only the instance itself
npalm b6b4fa3
fix: add logging context to runner lambda (#1399)
npalm 14ac0db
feat: Add hooks for prebuilt images (AMI), including amazon linux pac…
npalm 4687395
add option ephemeral runners
npalm 0b6a8e7
Add retry mechanisme for scaling errors
npalm 99399a1
add dead letter queue, and refactor
npalm 3f46be8
cleanup
npalm 4eb82ac
cleanup
npalm bfff210
sync develop
npalm f0e9880
review fix
npalm 5cda294
review fix
npalm 4acb137
review vfix
npalm 7b074c8
review vfix
npalm 3b8f28a
fix review
npalm 2dd5848
process review comments
npalm 6c66965
process review comments
npalm abeac1a
review comment
npalm 17dba00
process review comments
npalm ec7af4c
Update examples/ephemeral/README.md
npalm e08bd36
Process review comments
npalm 7c9f512
Add docs
npalm 49f15a0
review comments
npalm 3269019
update docs
npalm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Build all the lambda's, output on the default place (inside the lambda module) | ||
|
||
lambdaSrcDirs=("modules/runner-binaries-syncer/lambdas/runner-binaries-syncer" "modules/runners/lambdas/runners" "modules/webhook/lambdas/webhook") | ||
repoRoot=$(dirname $(dirname $(realpath ${BASH_SOURCE[0]}))) | ||
|
||
for lambdaDir in ${lambdaSrcDirs[@]}; do | ||
cd "$repoRoot/${lambdaDir}" | ||
yarn && yarn run dist | ||
done |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,30 @@ | ||
# Action runners deployment ephemeral example | ||
|
||
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. | ||
## Usages | ||
|
||
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. | ||
|
||
> 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 | ||
|
||
```bash | ||
cd lambdas-download | ||
terraform init | ||
terraform apply | ||
cd .. | ||
``` | ||
|
||
Before running Terraform, ensure the GitHub app is configured. See the [configuration details](../../README.md#usages) for more details. | ||
|
||
```bash | ||
terraform init | ||
terraform apply | ||
``` | ||
|
||
You can receive the webhook details by running: | ||
|
||
```bash | ||
terraform output -raw webhook_secret | ||
``` | ||
|
||
Be-aware some shells will print some end of line character `%`. |
This file contains hidden or 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,25 @@ | ||
locals { | ||
version = "<REPLACE_BY_GITHUB_RELEASE_VERSION>" | ||
} | ||
|
||
module "lambdas" { | ||
source = "../../../modules/download-lambda" | ||
lambdas = [ | ||
{ | ||
name = "webhook" | ||
tag = local.version | ||
}, | ||
{ | ||
name = "runners" | ||
tag = local.version | ||
}, | ||
{ | ||
name = "runner-binaries-syncer" | ||
tag = local.version | ||
} | ||
] | ||
} | ||
|
||
output "files" { | ||
value = module.lambdas.files | ||
} |
This file contains hidden or 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,71 @@ | ||
locals { | ||
environment = "ephemeraal" | ||
aws_region = "eu-west-1" | ||
} | ||
|
||
resource "random_id" "random" { | ||
byte_length = 20 | ||
} | ||
|
||
data "aws_caller_identity" "current" {} | ||
|
||
module "runners" { | ||
source = "../../" | ||
create_service_linked_role_spot = true | ||
aws_region = local.aws_region | ||
vpc_id = module.vpc.vpc_id | ||
subnet_ids = module.vpc.private_subnets | ||
|
||
environment = local.environment | ||
tags = { | ||
Project = "ProjectX" | ||
} | ||
|
||
github_app = { | ||
key_base64 = var.github_app_key_base64 | ||
id = var.github_app_id | ||
webhook_secret = random_id.random.hex | ||
} | ||
|
||
# Grab the lambda packages from local directory. Must run /.ci/build.sh first | ||
webhook_lambda_zip = "../../lambda_output/webhook.zip" | ||
runner_binaries_syncer_lambda_zip = "../../lambda_output/runner-binaries-syncer.zip" | ||
runners_lambda_zip = "../../lambda_output/runners.zip" | ||
|
||
enable_organization_runners = true | ||
runner_extra_labels = "default,example" | ||
|
||
# enable access to the runners via SSM | ||
enable_ssm_on_runners = true | ||
|
||
# Let the module manage the service linked role | ||
# create_service_linked_role_spot = true | ||
|
||
instance_types = ["m5.large", "c5.large"] | ||
|
||
# override delay of events in seconds | ||
delay_webhook_event = 0 | ||
|
||
# Ensure you set the number not too low, each build require a new instance | ||
runners_maximum_count = 20 | ||
|
||
# override scaling down | ||
scale_down_schedule_expression = "cron(* * * * ? *)" | ||
|
||
enable_ephemeral_runners = true | ||
|
||
# configure your pre-built AMI | ||
# enabled_userdata = false | ||
# ami_filter = { name = ["github-runner-amzn2-x86_64-2021*"] } | ||
# ami_owners = [data.aws_caller_identity.current.account_id] | ||
|
||
# Enable logging | ||
# log_level = "debug" | ||
|
||
# Setup a dead letter queue, by default scale up lambda will kepp retrying to process event in case of scaling error. | ||
# redrive_policy_build_queue = { | ||
# enabled = true | ||
# maxReceiveCount = 50 # 50 retries every 30 seconds => 25 minutes | ||
# deadLetterTargetArn = null | ||
# } | ||
} |
This file contains hidden or 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 @@ | ||
output "runners" { | ||
value = { | ||
lambda_syncer_name = module.runners.binaries_syncer.lambda.function_name | ||
} | ||
} | ||
|
||
output "webhook_endpoint" { | ||
value = module.runners.webhook.endpoint | ||
} | ||
|
||
output "webhook_secret" { | ||
sensitive = true | ||
value = random_id.random.hex | ||
} | ||
|
This file contains hidden or 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,3 @@ | ||
provider "aws" { | ||
region = local.aws_region | ||
} |
This file contains hidden or 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 @@ | ||
|
||
variable "github_app_key_base64" {} | ||
|
||
variable "github_app_id" {} | ||
|
This file contains hidden or 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 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 3.27" | ||
} | ||
local = { | ||
source = "hashicorp/local" | ||
} | ||
random = { | ||
source = "hashicorp/random" | ||
} | ||
} | ||
required_version = ">= 0.14" | ||
} |
This file contains hidden or 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,7 @@ | ||
module "vpc" { | ||
source = "git::https://github.com/philips-software/terraform-aws-vpc.git?ref=2.2.0" | ||
|
||
environment = local.environment | ||
aws_region = local.aws_region | ||
create_private_hosted_zone = false | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.