Skip to content

Commit 9e6072b

Browse files
committed
change
1 parent fa69895 commit 9e6072b

File tree

3 files changed

+99
-7
lines changed

3 files changed

+99
-7
lines changed

infrastructure/tools/github_runner_lambda.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,18 @@ resource "aws_lambda_function" "github_runner_webhook" {
6363
filename = data.archive_file.github_runner_webhook_artifact.output_path
6464
source_code_hash = data.archive_file.github_runner_webhook_artifact.output_base64sha256
6565
timeout = 60
66+
6667
environment {
6768
variables = {
6869
WEBHOOK_SECRET = random_password.webhook_secret.result
6970
GITHUB_TOKEN_SSM_NAME = data.aws_ssm_parameter.github_token.name
71+
NETWORK_CONFIGURATION = jsonencode({
72+
"awsvpcConfiguration": {
73+
"subnets": [aws_subnet.public["eu-central-1a"].id],
74+
"securityGroups": [],
75+
"assignPublicIp": "ENABLED"
76+
}
77+
})
7078
}
7179
}
7280
}

infrastructure/tools/lambdas/github_runner_webhook.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
WEBHOOK_SECRET = os.environ["WEBHOOK_SECRET"]
99
GITHUB_TOKEN_SSM_NAME = os.environ["GITHUB_TOKEN_SSM_NAME"]
10+
NETWORK_CONFIGURATION = os.environ["NETWORK_CONFIGURATION"]
1011

1112

1213
def handler(event, context):
@@ -42,22 +43,23 @@ def handle_workflow_job(body, context):
4243
return
4344

4445
labels = workflow_job["labels"]
45-
if labels != ["self-hosted", "arm64-fargate"]:
46+
arm64_fargate_label = next(
47+
(label for label in labels if "arm64-fargate-" in label), None
48+
)
49+
if not arm64_fargate_label:
4650
return
4751

52+
unique_run_id = arm64_fargate_label.replace("arm64-fargate-", "")
53+
4854
ssm_client = boto3.client("ssm")
4955
github_token = ssm_client.get_parameter(Name=GITHUB_TOKEN_SSM_NAME)["Parameter"][
5056
"Value"
5157
]
5258

5359
payload = {
54-
"name": "Test from Lambda",
60+
"name": f"Runner for run #{unique_run_id}",
5561
"runner_group_id": 3,
56-
"labels": [
57-
"lambda-test"
58-
# 'self-hosted',
59-
# 'arm64-fargate',
60-
],
62+
"labels": [arm64_fargate_label],
6163
}
6264
payload_encoded = json.dumps(payload).encode("utf-8")
6365
print("sending payload:", payload_encoded)
@@ -82,6 +84,12 @@ def handle_workflow_job(body, context):
8284
print("Body:", body)
8385
print("Context:", context)
8486

87+
ecs_client = boto3.client("ecs")
88+
ecs_client.start_task(
89+
cluster="github-actions-runners",
90+
networkConfiguration=json.loads(NETWORK_CONFIGURATION),
91+
)
92+
8593

8694
def verify_signature(payload_body, secret_token, signature_header):
8795
"""Verify that the payload was sent from GitHub by validating SHA256.

infrastructure/tools/vpc.tf

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
locals {
2+
public_azs_cidr = {
3+
"eu-central-1a" : "10.0.1.0/24",
4+
"eu-central-1b" : "10.0.2.0/24",
5+
"eu-central-1c" : "10.0.3.0/24",
6+
}
7+
private_azs_cidr = {
8+
"eu-central-1a" : "10.0.4.0/24",
9+
"eu-central-1b" : "10.0.5.0/24",
10+
"eu-central-1c" : "10.0.6.0/24",
11+
}
12+
}
13+
14+
resource "aws_vpc" "default" {
15+
cidr_block = "10.0.0.0/16"
16+
enable_dns_hostnames = true
17+
18+
tags = {
19+
Name = "main-vpc"
20+
}
21+
}
22+
23+
resource "aws_subnet" "private" {
24+
for_each = local.private_azs_cidr
25+
vpc_id = aws_vpc.default.id
26+
availability_zone = each.key
27+
cidr_block = each.value
28+
29+
tags = {
30+
Name = "main-vpc-private-subnet-${each.key}"
31+
Type = "private"
32+
AZ = each.key
33+
}
34+
}
35+
36+
resource "aws_subnet" "public" {
37+
for_each = local.public_azs_cidr
38+
vpc_id = aws_vpc.default.id
39+
availability_zone = each.key
40+
cidr_block = each.value
41+
map_public_ip_on_launch = true
42+
43+
tags = {
44+
Name = "main-vpc-public-subnet-${each.key}"
45+
Type = "public"
46+
AZ = each.key
47+
}
48+
}
49+
50+
resource "aws_route_table" "public" {
51+
for_each = toset(keys(local.public_azs_cidr))
52+
vpc_id = aws_vpc.default.id
53+
54+
route {
55+
cidr_block = "0.0.0.0/0"
56+
gateway_id = aws_internet_gateway.default.id
57+
}
58+
59+
tags = {
60+
Name = "main-vpc-public-route-${each.value}"
61+
}
62+
63+
depends_on = [
64+
aws_internet_gateway.default
65+
]
66+
}
67+
68+
resource "aws_route_table_association" "public_subnet_to_public_route" {
69+
for_each = toset(keys(local.public_azs_cidr))
70+
route_table_id = aws_route_table.public[each.value].id
71+
subnet_id = aws_subnet.public[each.value].id
72+
}
73+
74+
resource "aws_internet_gateway" "default" {
75+
vpc_id = aws_vpc.default.id
76+
}

0 commit comments

Comments
 (0)