Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit dbba705

Browse files
ScottGuymernpalmRichiCoder1seemethere
authored
feat: add windows support (#1476)
Integrate the windows support to the module. Co-authored-by: Niek Palm <[email protected]> Co-authored-by: Richard Simpson <[email protected]> Co-authored-by: Eli Uriegas <[email protected]>
1 parent 83bb07b commit dbba705

34 files changed

+496
-114
lines changed

Diff for: README.md

+4
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ idle_config = [{
266266
}]
267267
```
268268

269+
_**Note**_: When using Windows runners it's recommended to keep a few runners warmed up due to the minutes-long cold start time.
270+
269271
### Prebuilt Images
270272

271273
This module also allows you to run agents from a prebuilt AMI to gain faster startup times. You can find more information in [the image README.md](/images/README.md)
@@ -294,7 +296,9 @@ Examples are located in the [examples](./examples) directory. The following exam
294296

295297
- _[Default](examples/default/README.md)_: The default example of the module
296298
- _[Permissions boundary](examples/permissions-boundary/README.md)_: Example usages of permissions boundaries.
299+
- _[Ubuntu](examples/ubuntu/README.md)_: Example usage of creating a runner using Ubuntu AMIs.
297300
- _[Prebuilt Images](examples/prebuilt/README.md)_: Example usages of deploying runners with a custom prebuilt image.
301+
- _[Windows](examples/windows/README.md)_: Example usage of creating a runner using Windows as the OS.
298302

299303
## Sub modules
300304

Diff for: examples/default/main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ locals {
33
aws_region = "eu-west-1"
44
}
55

6-
resource "random_password" "random" {
7-
length = 28
6+
resource "random_id" "random" {
7+
byte_length = 20
88
}
99

1010

@@ -27,7 +27,7 @@ module "runners" {
2727
github_app = {
2828
key_base64 = var.github_app_key_base64
2929
id = var.github_app_id
30-
webhook_secret = random_password.random.result
30+
webhook_secret = random_id.random.hex
3131
}
3232

3333
webhook_lambda_zip = "lambdas-download/webhook.zip"

Diff for: examples/default/outputs.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ output "webhook_endpoint" {
1010

1111
output "webhook_secret" {
1212
sensitive = true
13-
value = random_password.random.result
13+
value = random_id.random.hex
1414
}
1515

Diff for: examples/permissions-boundary/main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ locals {
33
aws_region = "eu-west-1"
44
}
55

6-
resource "random_password" "random" {
7-
length = 32
6+
resource "random_id" "random" {
7+
byte_length = 20
88
}
99

1010
data "terraform_remote_state" "iam" {
@@ -46,7 +46,7 @@ module "runners" {
4646
id = var.github_app_id
4747
client_id = var.github_app_client_id
4848
client_secret = var.github_app_client_secret
49-
webhook_secret = random_password.random.result
49+
webhook_secret = random_id.random.hex
5050
}
5151

5252
webhook_lambda_zip = "lambdas-download/webhook.zip"

Diff for: examples/permissions-boundary/outputs.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ output "runners" {
66

77
output "webhook" {
88
value = {
9-
secret = random_password.random.result
9+
secret = random_id.random.hex
1010
endpoint = module.runners.webhook.endpoint
1111
}
1212
}

Diff for: examples/prebuilt/main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ locals {
33
aws_region = "eu-west-1"
44
}
55

6-
resource "random_password" "random" {
7-
length = 28
6+
resource "random_id" "random" {
7+
byte_length = 20
88
}
99

1010
data "aws_caller_identity" "current" {}
@@ -21,7 +21,7 @@ module "runners" {
2121
github_app = {
2222
key_base64 = var.github_app_key_base64
2323
id = var.github_app_id
24-
webhook_secret = random_password.random.result
24+
webhook_secret = random_id.random.hex
2525
}
2626

2727
webhook_lambda_zip = "../../lambda_output/webhook.zip"

Diff for: examples/prebuilt/outputs.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ output "webhook_endpoint" {
1010

1111
output "webhook_secret" {
1212
sensitive = true
13-
value = random_password.random.result
13+
value = random_id.random.hex
1414
}
1515

Diff for: examples/ubuntu/main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ locals {
33
aws_region = "eu-west-1"
44
}
55

6-
resource "random_password" "random" {
7-
length = 28
6+
resource "random_id" "random" {
7+
byte_length = 20
88
}
99

1010
module "runners" {
@@ -22,7 +22,7 @@ module "runners" {
2222
github_app = {
2323
key_base64 = var.github_app_key_base64
2424
id = var.github_app_id
25-
webhook_secret = random_password.random.result
25+
webhook_secret = random_id.random.hex
2626
}
2727

2828
# webhook_lambda_zip = "lambdas-download/webhook.zip"

Diff for: examples/ubuntu/outputs.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ output "runners" {
66

77
output "webhook" {
88
value = {
9-
secret = random_password.random.result
9+
secret = random_id.random.hex
1010
endpoint = module.runners.webhook.endpoint
1111
}
1212
}

Diff for: examples/windows/.terraform.lock.hcl

+39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/windows/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Action runners deployment windows example
2+
3+
This module shows how to create GitHub action runners using an Windows Runners. Lambda release will be downloaded from GitHub.
4+
5+
## Usages
6+
7+
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, for which there is a build script available at `<root>/.ci/build.sh`. In the `main.tf` you can remove the location of the lambda zip files, the default location will work in this case.
8+
9+
> 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>
10+
11+
12+
```pwsh
13+
cd lambdas-download
14+
terraform init
15+
terraform apply
16+
cd ..
17+
```
18+
19+
Before running Terraform, ensure the GitHub app is configured.
20+
21+
```bash
22+
terraform init
23+
terraform apply
24+
```
25+
26+
_**Note**_: It can take upwards of ten minutes for a runner to start processing jobs, and about as long for logs to start showing up. It's recommend that scale the runners via a warm-up job and then keep them idled.

Diff for: examples/windows/lambdas-download/main.tf

+25
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+
}

Diff for: examples/windows/main.tf

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
locals {
2+
environment = "windows"
3+
aws_region = "eu-west-1"
4+
}
5+
6+
resource "random_id" "random" {
7+
byte_length = 20
8+
}
9+
10+
module "runners" {
11+
source = "../../"
12+
13+
aws_region = local.aws_region
14+
vpc_id = module.vpc.vpc_id
15+
subnet_ids = module.vpc.private_subnets
16+
environment = local.environment
17+
18+
github_app = {
19+
key_base64 = var.github_app_key_base64
20+
id = var.github_app_id
21+
webhook_secret = random_id.random.hex
22+
}
23+
24+
# Grab the lambda packages from local directory. Must run /.ci/build.sh first
25+
webhook_lambda_zip = "../../lambda_output/webhook.zip"
26+
runner_binaries_syncer_lambda_zip = "../../lambda_output/runner-binaries-syncer.zip"
27+
runners_lambda_zip = "../../lambda_output/runners.zip"
28+
29+
enable_organization_runners = false
30+
# no need to add extra windows tag here as it is automatically added by GitHub
31+
runner_extra_labels = "default,example"
32+
33+
# Set the OS to Windows
34+
runner_os = "win"
35+
# we need to give the runner time to start because this is windows.
36+
runner_boot_time_in_minutes = 20
37+
38+
# enable access to the runners via SSM
39+
enable_ssm_on_runners = true
40+
41+
instance_types = ["m5.large", "c5.large"]
42+
43+
# override delay of events in seconds for testing
44+
delay_webhook_event = 5
45+
46+
# override scaling down for testing
47+
scale_down_schedule_expression = "cron(* * * * ? *)"
48+
}

Diff for: examples/windows/outputs.tf

+15
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+

Diff for: examples/windows/providers.tf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider "aws" {
2+
region = local.aws_region
3+
}

Diff for: examples/windows/variables.tf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
variable "github_app_key_base64" {}
3+
4+
variable "github_app_id" {}

Diff for: examples/windows/vpc.tf

+7
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+
}

Diff for: main.tf

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ locals {
66

77
s3_action_runner_url = "s3://${module.runner_binaries.bucket.id}/${module.runner_binaries.runner_distribution_object_key}"
88
runner_architecture = substr(var.instance_type, 0, 2) == "a1" || substr(var.instance_type, 1, 2) == "6g" ? "arm64" : "x64"
9-
10-
ami_filter = length(var.ami_filter) > 0 ? var.ami_filter : local.runner_architecture == "arm64" ? { name = ["amzn2-ami-hvm-2*-arm64-gp2"] } : { name = ["amzn2-ami-hvm-2.*-x86_64-ebs"] }
11-
129
github_app_parameters = {
1310
id = module.ssm.parameters.github_app_id
1411
key_base64 = module.ssm.parameters.github_app_key_base64
@@ -82,20 +79,22 @@ module "runners" {
8279
s3_bucket_runner_binaries = module.runner_binaries.bucket
8380
s3_location_runner_binaries = local.s3_action_runner_url
8481

82+
runner_os = var.runner_os
8583
instance_type = var.instance_type
8684
instance_types = var.instance_types
8785
market_options = var.market_options
8886
block_device_mappings = var.block_device_mappings
8987

9088
runner_architecture = local.runner_architecture
91-
ami_filter = local.ami_filter
89+
ami_filter = var.ami_filter
9290
ami_owners = var.ami_owners
9391

9492
sqs_build_queue = aws_sqs_queue.queued_builds
9593
github_app_parameters = local.github_app_parameters
9694
enable_organization_runners = var.enable_organization_runners
9795
scale_down_schedule_expression = var.scale_down_schedule_expression
9896
minimum_running_time_in_minutes = var.minimum_running_time_in_minutes
97+
runner_boot_time_in_minutes = var.runner_boot_time_in_minutes
9998
runner_extra_labels = var.runner_extra_labels
10099
runner_as_root = var.runner_as_root
101100
runners_maximum_count = var.runners_maximum_count
@@ -155,6 +154,7 @@ module "runner_binaries" {
155154

156155
distribution_bucket_name = "${var.environment}-dist-${random_string.random.result}"
157156

157+
runner_os = var.runner_os
158158
runner_architecture = local.runner_architecture
159159
runner_allow_prerelease_binaries = var.runner_allow_prerelease_binaries
160160

Diff for: modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/src/syncer/syncer.test.ts

+20
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,23 @@ describe('Synchronize action distribution for arm64.', () => {
310310
await expect(sync()).rejects.toThrow(errorMessage);
311311
});
312312
});
313+
314+
describe('Synchronize action distribution for windows.', () => {
315+
const errorMessage = 'Cannot find GitHub release asset.';
316+
beforeEach(() => {
317+
process.env.S3_BUCKET_NAME = bucketName;
318+
process.env.S3_OBJECT_KEY = bucketObjectKey;
319+
process.env.GITHUB_RUNNER_OS = 'win';
320+
});
321+
322+
it('No win asset.', async () => {
323+
mockOctokit.repos.listReleases.mockImplementation(() => ({
324+
data: listReleases.map((release) => ({
325+
...release,
326+
assets: release.assets.filter((asset) => !asset.name.includes('win')),
327+
})),
328+
}));
329+
330+
await expect(sync()).rejects.toThrow(errorMessage);
331+
});
332+
});

0 commit comments

Comments
 (0)