Skip to content

Commit 1e4320f

Browse files
authored
Make SQS modulair (#7)
* Make queue modulair, refactor and fix naming according architcture * fix creating fake zip file * Fix ci for webhook
1 parent e219b4a commit 1e4320f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+172
-105
lines changed

.github/workflows/lambda-syncer.yml renamed to .github/workflows/lambda-runner-binaries-syncer.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
name: Lambda Runner Distribution Syncer
1+
name: Lambda Runner Binaries Syncer
22
on:
33
push:
44
branches:
55
- master
66
pull_request:
77
paths:
88
- .github/workflows/lambda-agent-webhook.yml
9-
- "modules/action-runner-binary-cache/lambdas/syncer/**"
9+
- "modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/**"
1010

1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
1414
container: node:12
1515
defaults:
1616
run:
17-
working-directory: modules/action-runner-binary-cache/lambdas/syncer
17+
working-directory: modules/runner-binaries-syncer/lambdas/runner-binaries-syncer
1818

1919
steps:
2020
- uses: actions/checkout@v2

.github/workflows/lambda-agent-webhook.yml renamed to .github/workflows/lambda-webhook.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ on:
55
- master
66
pull_request:
77
paths:
8-
- .github/workflows/lambda-agent-webhook.yml
9-
- "modules/agent/lambdas/webhook/**"
8+
- .github/workflows/lambda-webhook.yml
9+
- "modules/webhook/lambdas/webhook/**"
1010

1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
1414
container: node:12
1515
defaults:
1616
run:
17-
working-directory: modules/agent/lambdas/webhook
17+
working-directory: modules/webhook/lambdas/webhook
1818

1919
steps:
2020
- uses: actions/checkout@v2

.github/workflows/terraform.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ jobs:
1919
- name: "Checkout"
2020
uses: actions/checkout@v2
2121
- name: "Fake zip files" # Validate will fail if it cannot find the zip files
22-
run: |
23-
touch modules/action-runner-binary-cache/lambdas/syncer/syncer.zip
24-
touch modules/agent/lambdas/webhook/webhook.zip
22+
run:
23+
touch modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/runner-binaries-syncer.zip
24+
touch modules/webhook/lambdas/webhook/webhook.zip
2525
- name: "Terraform Format"
2626
uses: hashicorp/terraform-github-actions@master
2727
with:

examples/default/outputs.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ output "action_runners" {
55
}
66

77

8-
output "lambda_syncer_function_name" {
9-
value = module.runners.lambda_s3_action_runner_dist_syncer.id
8+
output "lambda_binaries_syncer_name" {
9+
value = module.runners.binaries_syncer.lambda.id
1010
}
1111

1212

1313
output "github_app_webhook_secret" {
1414
value = random_password.random.result
1515
}
16+
17+

main.tf

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,34 @@ locals {
33
Environment = var.environment
44
})
55

6+
s3_action_runner_url = "s3://${module.runner_binaries.bucket.id}/${module.runner_binaries.runner_distribution_object_key}"
67
}
8+
79
resource "random_string" "random" {
810
length = 24
911
special = false
1012
upper = false
1113
}
1214

13-
module "dsitrubtion_cache" {
14-
source = "./modules/action-runner-binary-cache"
15+
resource "aws_sqs_queue" "queued_builds" {
16+
name = "${var.environment}-queued-builds.fifo"
17+
delay_seconds = 30
18+
fifo_queue = true
19+
receive_wait_time_seconds = 10
20+
content_based_deduplication = true
21+
22+
tags = var.tags
23+
}
24+
25+
module "webhook" {
26+
source = "./modules/webhook"
1527

1628
aws_region = var.aws_region
1729
environment = var.environment
1830
tags = local.tags
1931

20-
distribution_bucket_name = "${var.environment}-dist-${random_string.random.result}"
32+
sqs_build_queue = aws_sqs_queue.queued_builds
33+
github_app_webhook_secret = var.github_app_webhook_secret
2134
}
2235

2336
module "runners" {
@@ -28,36 +41,18 @@ module "runners" {
2841
environment = var.environment
2942
tags = local.tags
3043

31-
s3_location_runner_distribution = module.dsitrubtion_cache.s3_location_runner_distribution
44+
s3_bucket_runner_binaries = module.runner_binaries.bucket
45+
s3_location_runner_binaries = local.s3_action_runner_url
3246
}
3347

34-
35-
module "agent" {
36-
source = "./modules/agent"
48+
module "runner_binaries" {
49+
source = "./modules/runner-binaries-syncer"
3750

3851
aws_region = var.aws_region
3952
environment = var.environment
4053
tags = local.tags
4154

42-
github_app_webhook_secret = var.github_app_webhook_secret
43-
}
44-
45-
46-
resource "aws_iam_policy" "dist_bucket" {
47-
name = "${var.environment}-gh-distribution-bucket"
48-
path = "/"
49-
description = "Policy for the runner to download the github action runner."
50-
51-
policy = templatefile("${path.module}/policies/action-runner-s3-policy.json",
52-
{
53-
s3_arn = module.dsitrubtion_cache.distribution_bucket.arn
54-
}
55-
)
56-
}
57-
58-
resource "aws_iam_role_policy_attachment" "dist_bucket" {
59-
role = module.runners.role.name
60-
policy_arn = aws_iam_policy.dist_bucket.arn
55+
distribution_bucket_name = "${var.environment}-dist-${random_string.random.result}"
6156
}
6257

6358
resource "aws_resourcegroups_group" "resourcegroups_group" {

modules/action-runner-binary-cache/outputs.tf

Lines changed: 0 additions & 11 deletions
This file was deleted.

modules/agent/outputs.tf

Lines changed: 0 additions & 3 deletions
This file was deleted.

modules/agent/policies.tf

Lines changed: 0 additions & 17 deletions
This file was deleted.

modules/agent/webhook_queue.tf

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)