Skip to content

Commit b905ea3

Browse files
committed
change
1 parent 9e6072b commit b905ea3

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

.github/workflows/build-backend.yml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,12 @@ jobs:
2020
aws-access-key-id: ${{ secrets.aws_access_key_id }}
2121
aws-secret-access-key: ${{ secrets.aws_secret_access_key }}
2222
aws-region: eu-central-1
23-
- name: Set up QEMU dependency
24-
uses: docker/setup-qemu-action@v3
2523
- name: Login to Amazon ECR
2624
uses: aws-actions/amazon-ecr-login@v2
27-
- name: Set up Docker Buildx
28-
id: buildx
29-
uses: docker/setup-buildx-action@v3
30-
- name: Build and push
31-
uses: docker/build-push-action@v6
25+
- name: Run kaniko
26+
uses: pythonitalia/kaniko-action@main
3227
with:
33-
context: ./backend
34-
file: ./backend/Dockerfile
35-
builder: ${{ steps.buildx.outputs.name }}
36-
provenance: false
3728
push: true
38-
tags: |
39-
${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-central-1.amazonaws.com/pythonit/pycon-backend:arm-${{ inputs.githash }}
40-
cache-from: type=local,src=/tmp/.buildx-cache
41-
cache-to: type=local,dest=/tmp/.buildx-cache
42-
platforms: linux/arm64
29+
tags: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-central-1.amazonaws.com/pythonit/pycon-backend:arm-${{ inputs.githash }}
30+
cache: true
31+
cache-repository: ghcr.io/${{ github.repository }}/cache

infrastructure/tools/github_runner_lambda.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,24 @@ resource "aws_iam_role_policy" "github_runner_webhook_lambda_policy" {
4444
Resource = [
4545
data.aws_ssm_parameter.github_token.arn
4646
]
47+
},
48+
{
49+
Effect = "Allow"
50+
Action = [
51+
"ecs:RunTask"
52+
]
53+
Resource = [
54+
"${aws_ecs_task_definition.github_runner.arn}*",
55+
]
56+
},
57+
{
58+
Effect = "Allow"
59+
Action = [
60+
"iam:PassRole"
61+
]
62+
Resource = [
63+
aws_iam_role.github_runner_execution_role.arn
64+
]
4765
}
4866
]
4967
})
@@ -75,6 +93,8 @@ resource "aws_lambda_function" "github_runner_webhook" {
7593
"assignPublicIp": "ENABLED"
7694
}
7795
})
96+
ECS_CLUSTER_NAME = aws_ecs_cluster.github_runners.name
97+
ECS_TASK_DEFINITION = aws_ecs_task_definition.github_runner.arn
7898
}
7999
}
80100
}

infrastructure/tools/github_runner_task.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ resource "aws_ecs_task_definition" "github_runner" {
6767
name = "runner"
6868
image = "ghcr.io/actions/actions-runner:2.321.0"
6969
essential = true
70+
entrypoint = ["bash", "-c"]
7071
portMappings = []
7172
logConfiguration = {
7273
logDriver = "awslogs"

infrastructure/tools/lambdas/github_runner_webhook.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
WEBHOOK_SECRET = os.environ["WEBHOOK_SECRET"]
99
GITHUB_TOKEN_SSM_NAME = os.environ["GITHUB_TOKEN_SSM_NAME"]
1010
NETWORK_CONFIGURATION = os.environ["NETWORK_CONFIGURATION"]
11+
ECS_CLUSTER_NAME = os.environ["ECS_CLUSTER_NAME"]
12+
ECS_TASK_DEFINITION = os.environ["ECS_TASK_DEFINITION"]
1113

1214

1315
def handler(event, context):
@@ -62,7 +64,7 @@ def handle_workflow_job(body, context):
6264
"labels": [arm64_fargate_label],
6365
}
6466
payload_encoded = json.dumps(payload).encode("utf-8")
65-
print("sending payload:", payload_encoded)
67+
6668
req = request.Request(
6769
"https://api.github.com/orgs/pythonitalia/actions/runners/generate-jitconfig",
6870
data=payload_encoded,
@@ -85,9 +87,17 @@ def handle_workflow_job(body, context):
8587
print("Context:", context)
8688

8789
ecs_client = boto3.client("ecs")
88-
ecs_client.start_task(
89-
cluster="github-actions-runners",
90+
ecs_client.run_task(
91+
cluster=ECS_CLUSTER_NAME,
92+
taskDefinition=ECS_TASK_DEFINITION,
9093
networkConfiguration=json.loads(NETWORK_CONFIGURATION),
94+
count=1,
95+
launchType="FARGATE",
96+
overrides={
97+
"containerOverrides": [
98+
{"name": "runner", "command": [f"./run.sh --jitconfig {jit_config}"]}
99+
]
100+
},
91101
)
92102

93103

0 commit comments

Comments
 (0)