Skip to content

Commit

Permalink
Merge pull request #1645 from philips-labs/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
npalm authored Jan 19, 2022
2 parents 1a409d2 + ec497a2 commit 3376a70
Show file tree
Hide file tree
Showing 25 changed files with 1,130 additions and 886 deletions.
1 change: 1 addition & 0 deletions .github/workflows/packer-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
paths:
- "images/**"
- ".github/workflows/packer-build.yml"
- "module/runners/templates/**"

env:
AWS_REGION: eu-west-1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:

steps:
- name: Generate provenance for release
uses: philips-labs/[email protected].0
uses: philips-labs/[email protected].1
with:
artifact_path: release-assets
output_path: 'build.provenance'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
fail-fast: false
matrix:
terraform: [0.14.3, 0.15.5, 1.0.8]
example: ["default", "ubuntu", "prebuilt"]
example: ["default", "ubuntu", "prebuilt", "arm64", "ephemeral", "windows"]
defaults:
run:
working-directory: examples/${{ matrix.example }}
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ To be able to support a number of use-cases the module has quite a lot configura

#### ARM64 support via Graviton/Graviton2 instance-types

When using the default example or top-level module, specifying an `instance_type` that matches a Graviton/Graviton 2 (ARM64) architecture (e.g. a1, t4g or any 6th-gen `g` or `gd` type), the sub-modules will be automatically configured to provision with ARM64 AMIs and leverage GitHub's ARM64 action runner. See below for more details.
When using the default example or top-level module, specifying `instance_types` that match a Graviton/Graviton 2 (ARM64) architecture (e.g. a1, t4g or any 6th-gen `g` or `gd` type), you must also specify `runner_architecture = "arm64"` and the sub-modules will be automatically configured to provision with ARM64 AMIs and leverage GitHub's ARM64 action runner. See below for more details.

## Usages

Expand Down Expand Up @@ -184,8 +184,6 @@ module "github-runner" {
}
```

**ARM64** support: Specify an `a1`, `t4g` or `*6g*` (6th-gen Graviton2) instance type to stand up an ARM64 runner, otherwise the default is x86_64.

Run terraform by using the following commands

```bash
Expand Down Expand Up @@ -322,9 +320,10 @@ This module also allows you to run agents from a prebuilt AMI to gain faster sta
Examples are located in the [examples](./examples) directory. The following examples are provided:

- _[Default](examples/default/README.md)_: The default example of the module
- _[ARM64](examples/arm64/README.md)_: Example usage with ARM64 architecture
- _[Ubuntu](examples/ubuntu/README.md)_: Example usage of creating a runner using Ubuntu AMIs.
- _[Windows](examples/windows/README.md)_: Example usage of creating a runner using Windows as the OS.
- _[Ephemeral](examples/ephemeral/README.md) : Example usages of ephemeral runners based on the default example.
- _[Ephemeral](examples/ephemeral/README.md)_: Example usages of ephemeral runners based on the default example.
- _[Prebuilt Images](examples/prebuilt/README.md)_: Example usages of deploying runners with a custom prebuilt image.
- _[Permissions boundary](examples/permissions-boundary/README.md)_: Example usages of permissions boundaries.

Expand All @@ -345,7 +344,7 @@ The following sub modules are optional and are provided as example or utility:

### ARM64 configuration for submodules

When using the top level module configure `runner_architecture = arm64` and insure the list of `instance_types` matches. When not using the top-level ensure the bot properties are set on the submodules.
When using the top level module configure `runner_architecture = "arm64"` and ensure the list of `instance_types` matches. When not using the top-level, ensure these properties are set on the submodules.

## Debugging

Expand All @@ -354,7 +353,7 @@ In case the setup does not work as intended follow the trace of events:
- In the GitHub App configuration, the Advanced page displays all webhook events that were sent.
- In AWS CloudWatch, every lambda has a log group. Look at the logs of the `webhook` and `scale-up` lambdas.
- In AWS SQS you can see messages available or in flight.
- Once an EC2 instance is running, you can connect to it in the EC2 user interface using Session Manager. Check the user data script using `cat /var/log/user-data.log`. By default several log files of the instances are streamed to AWS CloudWatch, look for a log group named `<environment>/runners`. In the log group you should see at least the log streams for the user data installation and runner agent.
- Once an EC2 instance is running, you can connect to it in the EC2 user interface using Session Manager (use `enable_ssm_on_runners = true`). Check the user data script using `cat /var/log/user-data.log`. By default several log files of the instances are streamed to AWS CloudWatch, look for a log group named `<environment>/runners`. In the log group you should see at least the log streams for the user data installation and runner agent.
- Registered instances should show up in the Settings - Actions page of the repository or organization (depending on the installation mode).

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Expand Down
57 changes: 57 additions & 0 deletions examples/arm64/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions examples/arm64/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Action runners deployment with ARM64 architecture

This module shows how to create GitHub action runners using AWS Graviton instances which have ARM64 architecture. Lambda release will be downloaded from GitHub.

## 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 `%`.
25 changes: 25 additions & 0 deletions examples/arm64/lambdas-download/main.tf
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
}
77 changes: 77 additions & 0 deletions examples/arm64/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
locals {
environment = "default"
aws_region = "eu-west-1"
}

resource "random_id" "random" {
byte_length = 20
}


################################################################################
### Hybrid account
################################################################################

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 zip files via lambda_download, will automatically get the ARM64 build
webhook_lambda_zip = "lambdas-download/webhook.zip"
runner_binaries_syncer_lambda_zip = "lambdas-download/runner-binaries-syncer.zip"
runners_lambda_zip = "lambdas-download/runners.zip"

enable_organization_runners = false
# Runners will automatically get the "arm64" label
runner_extra_labels = "default,example"

# enable access to the runners via SSM
enable_ssm_on_runners = true

# use S3 or KMS SSE to runners S3 bucket
# runner_binaries_s3_sse_configuration = {
# rule = {
# apply_server_side_encryption_by_default = {
# sse_algorithm = "AES256"
# }
# }
# }

# Uncommet idle config to have idle runners from 9 to 5 in time zone Amsterdam
# idle_config = [{
# cron = "* * 9-17 * * *"
# timeZone = "Europe/Amsterdam"
# idleCount = 1
# }]

# Let the module manage the service linked role
# create_service_linked_role_spot = true

runner_architecture = "arm64"
# Ensure all instance types have ARM64 architecture (ie. AWS Graviton processors)
instance_types = ["t4g.large", "c6g.large"]

# override delay of events in seconds
delay_webhook_event = 5
runners_maximum_count = 1

# set up a fifo queue to remain order
fifo_build_queue = true

# override scaling down
scale_down_schedule_expression = "cron(* * * * ? *)"
}
15 changes: 15 additions & 0 deletions examples/arm64/outputs.tf
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
}

3 changes: 3 additions & 0 deletions examples/arm64/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "aws" {
region = local.aws_region
}
4 changes: 4 additions & 0 deletions examples/arm64/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

variable "github_app_key_base64" {}

variable "github_app_id" {}
15 changes: 15 additions & 0 deletions examples/arm64/versions.tf
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"
}
7 changes: 7 additions & 0 deletions examples/arm64/vpc.tf
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
}
2 changes: 1 addition & 1 deletion examples/default/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ resource "random_id" "random" {


################################################################################
### Hybrid acccount
### Hybrid account
################################################################################

module "runners" {
Expand Down
3 changes: 2 additions & 1 deletion images/linux-amzn2/github_agent.linux.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ build {
install_runner = templatefile("../../modules/runners/templates/install-runner.sh", {
ARM_PATCH = ""
S3_LOCATION_RUNNER_DISTRIBUTION = ""
RUNNER_ARCHITECTURE = "x64"
})
})
destination = "/tmp/install-runner.sh"
Expand All @@ -113,7 +114,7 @@ build {
]
inline = [
"sudo chmod +x /tmp/install-runner.sh",
"sudo RUNNER_TARBALL_URL=$RUNNER_TARBALL_URL /tmp/install-runner.sh"
"sudo RUNNER_ARCHITECTURE=x64 RUNNER_TARBALL_URL=$RUNNER_TARBALL_URL /tmp/install-runner.sh"
]
}

Expand Down
4 changes: 2 additions & 2 deletions images/start-runner.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash -e
exec > >(tee /var/log/runner-startup.log | logger -t user-data -s 2>/dev/console) 2>&1

cd /home/ec2-user/actions-runner
cd /opt/actions-runner

## This wrapper file re-uses scripts in the /modules/runners/templates directory
## of this repo. These are the same that are used by the user_data functionality
## to bootstrap the instance if it is started from an existing AMI.
${start_runner}
${start_runner}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
"@octokit/rest": "^18.12.0",
"@trivago/prettier-plugin-sort-imports": "^3.1.1",
"@types/jest": "^27.4.0",
"@types/node": "^17.0.8",
"@types/node": "^17.0.9",
"@types/request": "^2.48.8",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"@vercel/ncc": "^0.33.1",
"aws-sdk": "^2.1055.0",
"aws-sdk": "^2.1058.0",
"eslint": "^7.32.0",
"eslint-plugin-prettier": "4.0.0",
"jest": "^27.4.7",
"jest-mock": "^27.4.6",
"prettier": "2.5.1",
"ts-jest": "^27.1.2",
"ts-jest": "^27.1.3",
"ts-node-dev": "^1.1.6",
"typescript": "^4.5.4"
},
Expand Down
Loading

0 comments on commit 3376a70

Please sign in to comment.