Skip to content

Commit fb3fd99

Browse files
committed
Merge branch 'develop' of https://github.com/philips-labs/terraform-aws-github-runner into philips-labs-develop
# Conflicts: # README.md # modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/yarn.lock # modules/runners/lambdas/runners/package.json # modules/runners/lambdas/runners/yarn.lock # modules/webhook/lambdas/webhook/src/webhook/handler.test.ts # modules/webhook/lambdas/webhook/src/webhook/handler.ts # variables.tf
2 parents b5096bb + d5611b0 commit fb3fd99

File tree

24 files changed

+213
-61
lines changed

24 files changed

+213
-61
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ secrets.auto.tfvars
1616
*.zip
1717
*.gz
1818
*.tgz
19-
*.env
19+
*.env*
2020
.vscode
2121

2222
**/coverage/*

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [0.15.0](https://github.com/philips-labs/terraform-aws-github-runner/compare/v0.14.0...v0.15.0) (2021-07-07)
4+
5+
6+
### Features
7+
8+
* Added support for white listing of repositories ([#915](https://github.com/philips-labs/terraform-aws-github-runner/issues/915)) ([b1f451a](https://github.com/philips-labs/terraform-aws-github-runner/commit/b1f451a0bddf8606b443c5150e939e7628645ccf))
9+
310
## [0.14.0](https://github.com/philips-labs/terraform-aws-github-runner/compare/v0.13.1...v0.14.0) (2021-06-17)
411

512

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ Go to GitHub and [create a new app](https://docs.github.com/en/developers/apps/c
118118
- `Administration`: Read & write (to register runner)
119119
7. _Permissions for organization level runners only_:
120120
- Organization
121-
- `Administration`: Read & write (to register runner)
122121
- `Self-hosted runners`: Read & write (to register runner)
123122
8. Save the new app.
124123
9. On the General page, make a note of the "App ID" and "Client ID" parameters.
@@ -348,6 +347,7 @@ No requirements.
348347
| block\_device\_mappings | The EC2 instance block device configuration. Takes the following keys: `device_name`, `delete_on_termination`, `volume_type`, `volume_size`, `encrypted`, `iops` | `map(string)` | `{}` | no |
349348
| cloudwatch\_config | (optional) Replaces the module default cloudwatch log config. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html for details. | `string` | `null` | no |
350349
| create\_service\_linked\_role\_spot | (optional) create the serviced linked role for spot instances that is required by the scale-up lambda. | `bool` | `false` | no |
350+
| delay\_webhook\_event | The number of seconds the event accepted by the webhook is invisible on the queue before the scale up lambda will receive the event. | `number` | `30` | no |
351351
| enable\_cloudwatch\_agent | Enabling the cloudwatch agent on the ec2 runner instances, the runner contains default config. Configuration can be overridden via `cloudwatch_config`. | `bool` | `true` | no |
352352
| enable\_organization\_runners | Register runners to organization, instead of repo level | `bool` | `false` | no |
353353
| enable\_ssm\_on\_runners | Enable to allow access the runner instances for debugging purposes via SSM. Note that this adds additional permissions to the runner instances. | `bool` | `false` | no |
@@ -368,7 +368,7 @@ No requirements.
368368
| manage\_kms\_key | Let the module manage the KMS key. | `bool` | `true` | no |
369369
| market\_options | Market options for the action runner instances. Setting the value to `null` let the scaler create on-demand instances instead of spot instances. | `string` | `"spot"` | no |
370370
| minimum\_running\_time\_in\_minutes | The time an ec2 action runner should be running at minimum before terminated if non busy. | `number` | `5` | no |
371-
| repository\_white\_list | (optional) List of github repository full names (owner/repo_name) that will be allowed to call the runners. Leave empty for no filtering | `list(string)` | `[]` | no |
371+
| repository\_white\_list | List of repositories allowed to use the github app | `list(string)` | `[]` | no |
372372
| role\_path | The path that will be added to role path for created roles, if not set the environment name will be used. | `string` | `null` | no |
373373
| role\_permissions\_boundary | Permissions boundary that will be added to the created roles. | `string` | `null` | no |
374374
| runner\_additional\_security\_group\_ids | (optional) List of additional security groups IDs to apply to the runner | `list(string)` | `[]` | no |

examples/default/.terraform-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.2

examples/default/.terraform.lock.hcl

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

examples/default/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@ terraform apply
1515
cd ..
1616
```
1717

18-
Before running Terraform, ensure the GitHub app is configured.
18+
Before running Terraform, ensure the GitHub app is configured. See the [configuration details](../../README.md#usages) for more details.
1919

2020
```bash
2121
terraform init
2222
terraform apply
2323
```
24+
25+
You can receive the webhook details by running:
26+
27+
```bash
28+
terraform output -raw webhook_secret
29+
```
30+
31+
Be-aware some shells will print some end of line character `%`.

examples/default/outputs.tf

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ output "runners" {
44
}
55
}
66

7-
output "webhook" {
8-
value = {
9-
secret = random_password.random.result
10-
endpoint = module.runners.webhook.endpoint
11-
}
7+
output "webhook_endpoint" {
8+
value = module.runners.webhook.endpoint
129
}
10+
11+
output "webhook_secret" {
12+
sensitive = true
13+
value = random_password.random.result
14+
}
15+

examples/default/providers.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
provider "aws" {
2-
region = local.aws_region
3-
version = "3.20"
2+
region = local.aws_region
43
}

examples/default/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.20"
6+
}
7+
local = {
8+
source = "hashicorp/local"
9+
}
10+
random = {
11+
source = "hashicorp/random"
12+
}
13+
}
14+
required_version = ">= 0.14"
15+
}

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ resource "random_string" "random" {
1717

1818
resource "aws_sqs_queue" "queued_builds" {
1919
name = "${var.environment}-queued-builds.fifo"
20-
delay_seconds = 30
20+
delay_seconds = var.delay_webhook_event
2121
visibility_timeout_seconds = var.runners_scale_up_lambda_timeout
2222
fifo_queue = true
2323
receive_wait_time_seconds = 10

modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@types/request": "^2.48.4",
2222
"@typescript-eslint/eslint-plugin": "^4.28.0",
2323
"@typescript-eslint/parser": "^4.17.0",
24-
"@zeit/ncc": "^0.22.1",
24+
"@vercel/ncc": "^0.29.0",
2525
"aws-sdk": "^2.888.0",
2626
"eslint": "^7.24.0",
2727
"jest": "^26.6.3",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { handle } from './syncer/handler';
22

33
// eslint-disable-next-line
4-
module.exports.handler = async (event: any, context: any, callback: any): Promise<any> => {
4+
export const handler = async (event: any, context: any, callback: any): Promise<void> => {
55
await handle();
6-
return callback();
6+
callback();
77
};

modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -890,10 +890,10 @@
890890
"@typescript-eslint/types" "4.28.0"
891891
eslint-visitor-keys "^2.0.0"
892892

893-
"@zeit/ncc@^0.22.1":
894-
version "0.22.3"
895-
resolved "https://registry.yarnpkg.com/@zeit/ncc/-/ncc-0.22.3.tgz#fca6b86b4454ce7a7e1e7e755165ec06457f16cd"
896-
integrity sha512-jnCLpLXWuw/PAiJiVbLjA8WBC0IJQbFeUwF4I9M+23MvIxTxk5pD4Q8byQBSPmHQjz5aBoA7AKAElQxMpjrCLQ==
893+
"@vercel/ncc@^0.29.0":
894+
version "0.29.0"
895+
resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.29.0.tgz#ac23fc23f1593b05c72360108bcf6d849d2f317a"
896+
integrity sha512-p+sB835wOSDdgm2mgFgSOcXJF84AqZ+vBEnnGS0sm8veA92Hia7sqH0qEnqeFilPl+cXtxbdh2er+WdlfbVCZA==
897897

898898
abab@^2.0.3, abab@^2.0.5:
899899
version "2.0.5"

modules/runners/lambdas/runners/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@types/jest": "^26.0.20",
2121
"@typescript-eslint/eslint-plugin": "^4.17.0",
2222
"@typescript-eslint/parser": "^4.22.0",
23-
"@vercel/ncc": "^0.28.6",
23+
"@vercel/ncc": "^0.29.0",
2424
"eslint": "^7.22.0",
2525
"jest": "^26.6.3",
2626
"jest-mock-extended": "^1.0.13",
@@ -41,4 +41,4 @@
4141
"typescript": "^4.2.3",
4242
"yn": "^4.0.0"
4343
}
44-
}
44+
}
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
import { scaleUp } from './scale-runners/scale-up';
2-
import { scaleDown } from './scale-runners/scale-down';
1+
import { scaleUp as scaleUpAction } from './scale-runners/scale-up';
2+
import { scaleDown as scaleDownAction } from './scale-runners/scale-down';
33
import { SQSEvent, ScheduledEvent, Context } from 'aws-lambda';
44

5-
module.exports.scaleUp = async (event: SQSEvent, context: Context, callback: any) => {
5+
export const scaleUp = async (event: SQSEvent, context: Context, callback: any): Promise<void> => {
66
console.dir(event, { depth: 5 });
77
try {
88
for (const e of event.Records) {
9-
await scaleUp(e.eventSource, JSON.parse(e.body));
9+
await scaleUpAction(e.eventSource, JSON.parse(e.body));
1010
}
11-
return callback(null);
11+
12+
callback(null);
1213
} catch (e) {
1314
console.error(e);
14-
return callback('Failed handling SQS event');
15+
callback('Failed handling SQS event');
1516
}
1617
};
1718

18-
module.exports.scaleDown = async (event: ScheduledEvent, context: Context, callback: any) => {
19+
export const scaleDown = async (event: ScheduledEvent, context: Context, callback: any): Promise<void> => {
1920
try {
20-
scaleDown();
21-
return callback(null);
21+
scaleDownAction();
22+
callback(null);
2223
} catch (e) {
2324
console.error(e);
24-
return callback('Failed');
25+
callback('Failed');
2526
}
2627
};

modules/runners/lambdas/runners/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -983,10 +983,10 @@
983983
"@typescript-eslint/types" "4.27.0"
984984
eslint-visitor-keys "^2.0.0"
985985

986-
"@vercel/ncc@^0.28.6":
987-
version "0.28.6"
988-
resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.28.6.tgz#073c0ce8e0269210c0a9f180fb0bf949eecc20e0"
989-
integrity sha512-t4BoSSuyK8BZaUE0gV18V6bkFs4st7baumtFGa50dv1tMu2GDBEBF8sUZaKBdKiL6DzJ2D2+XVCwYWWDcQOYdQ==
986+
"@vercel/ncc@^0.29.0":
987+
version "0.29.0"
988+
resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.29.0.tgz#ac23fc23f1593b05c72360108bcf6d849d2f317a"
989+
integrity sha512-p+sB835wOSDdgm2mgFgSOcXJF84AqZ+vBEnnGS0sm8veA92Hia7sqH0qEnqeFilPl+cXtxbdh2er+WdlfbVCZA==
990990

991991
abab@^2.0.3, abab@^2.0.5:
992992
version "2.0.5"

modules/runners/policies-runner.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ resource "aws_iam_instance_profile" "runner" {
1414
path = local.instance_profile_path
1515
}
1616

17-
resource "aws_iam_role_policy_attachment" "runner_session_manager_aws_managed" {
18-
count = var.enable_ssm_on_runners ? 1 : 0
19-
role = aws_iam_role.runner.name
20-
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
17+
resource "aws_iam_role_policy" "runner_session_manager_aws_managed" {
18+
name = "runner-ssm-session"
19+
count = var.enable_ssm_on_runners ? 1 : 0
20+
role = aws_iam_role.runner.name
21+
policy = templatefile("${path.module}/policies/instance-ssm-policy.json", {})
2122
}
2223

2324
resource "aws_iam_role_policy" "ssm_parameters" {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Effect": "Allow",
6+
"Action": [
7+
"ssm:DescribeAssociation",
8+
"ssm:GetDeployablePatchSnapshotForInstance",
9+
"ssm:GetDocument",
10+
"ssm:DescribeDocument",
11+
"ssm:GetManifest",
12+
"ssm:ListAssociations",
13+
"ssm:ListInstanceAssociations",
14+
"ssm:PutInventory",
15+
"ssm:PutComplianceItems",
16+
"ssm:PutConfigurePackageResult",
17+
"ssm:UpdateAssociationStatus",
18+
"ssm:UpdateInstanceAssociationStatus",
19+
"ssm:UpdateInstanceInformation"
20+
],
21+
"Resource": "*"
22+
},
23+
{
24+
"Effect": "Allow",
25+
"Action": [
26+
"ssmmessages:CreateControlChannel",
27+
"ssmmessages:CreateDataChannel",
28+
"ssmmessages:OpenControlChannel",
29+
"ssmmessages:OpenDataChannel"
30+
],
31+
"Resource": "*"
32+
},
33+
{
34+
"Effect": "Allow",
35+
"Action": [
36+
"ec2messages:AcknowledgeMessage",
37+
"ec2messages:DeleteMessage",
38+
"ec2messages:FailMessage",
39+
"ec2messages:GetEndpoint",
40+
"ec2messages:GetMessages",
41+
"ec2messages:SendReply"
42+
],
43+
"Resource": "*"
44+
}
45+
]
46+
}

modules/webhook/lambdas/webhook/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@types/node": "^15.12.2",
2222
"@typescript-eslint/eslint-plugin": "^4.22.0",
2323
"@typescript-eslint/parser": "^4.22.0",
24-
"@zeit/ncc": "^0.22.1",
24+
"@vercel/ncc": "0.29.0",
2525
"aws-sdk": "^2.888.0",
2626
"body-parser": "^1.19.0",
2727
"eslint": "^7.29.0",
@@ -33,6 +33,6 @@
3333
},
3434
"dependencies": {
3535
"@octokit/rest": "^18.3.5",
36-
"@octokit/webhooks": "^8.5.4"
36+
"@octokit/webhooks": "^9.10.0"
3737
}
3838
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { handle as githubWebhook } from './webhook/handler';
1+
import { handle } from './webhook/handler';
22

3-
module.exports.githubWebhook = async (event: any, context: any, callback: any) => {
4-
const statusCode = await githubWebhook(event.headers, event.body);
5-
return callback(null, {
3+
export const githubWebhook = async (event: any, context: any, callback: any): Promise<void> => {
4+
const statusCode = await handle(event.headers, event.body);
5+
callback(null, {
66
statusCode: statusCode,
77
});
88
};

modules/webhook/lambdas/webhook/src/webhook/handler.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,4 @@ describe('handler', () => {
9292
expect(resp).toBe(200);
9393
expect(sendActionRequest).toBeCalled();
9494
});
95-
9695
});

0 commit comments

Comments
 (0)