Skip to content

Commit e219b4a

Browse files
npalmgertjanmaas
andauthored
sync GitHub action distribution to S3 (#5)
* WIP lambda to sync s3 dist * Add update check * Add syncer * Refactor * Refactor to functions * Fix terraform validate * Fix error * Add linter, clenup * Add modules to root modules * Update modules/action-runner-binary-cache/variables.tf Co-authored-by: Gertjan Maas <[email protected]> * Fix review comments * Update jabascript libs * Add aws tags * Update default example Co-authored-by: Gertjan Maas <[email protected]>
1 parent d3d580e commit e219b4a

File tree

25 files changed

+5072
-8
lines changed

25 files changed

+5072
-8
lines changed

.github/workflows/lambda-syncer.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Lambda Runner Distribution Syncer
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
paths:
8+
- .github/workflows/lambda-agent-webhook.yml
9+
- "modules/action-runner-binary-cache/lambdas/syncer/**"
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
container: node:12
15+
defaults:
16+
run:
17+
working-directory: modules/action-runner-binary-cache/lambdas/syncer
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: Install dependencies
22+
run: yarn install
23+
- name: Run linter
24+
run: yarn lint
25+
- name: Build distribution
26+
run: yarn build

.github/workflows/terraform.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ jobs:
1818
steps:
1919
- name: "Checkout"
2020
uses: actions/checkout@v2
21+
- 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
2125
- name: "Terraform Format"
2226
uses: hashicorp/terraform-github-actions@master
2327
with:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
*.out
1414
example/*.secrets*.tfvars
1515
.envrc
16+
*.zip
17+
*.gz
18+
*.tgz

examples/default/main.tf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
locals {
2-
environment = "default-action-runners"
2+
environment = "default"
33
aws_region = "eu-west-1"
44
}
55

6+
7+
resource "random_password" "random" {
8+
length = 32
9+
}
10+
11+
612
module "runners" {
713
source = "../../"
814

@@ -14,5 +20,8 @@ module "runners" {
1420
Project = "ProjectX"
1521
}
1622

23+
github_app_webhook_secret = random_password.random.result
24+
1725
}
1826

27+

examples/default/outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,13 @@ output "action_runners" {
33
runners = module.runners.runners
44
}
55
}
6+
7+
8+
output "lambda_syncer_function_name" {
9+
value = module.runners.lambda_s3_action_runner_dist_syncer.id
10+
}
11+
12+
13+
output "github_app_webhook_secret" {
14+
value = random_password.random.result
15+
}

main.tf

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
locals {
2+
tags = merge(var.tags, {
3+
Environment = var.environment
4+
})
5+
6+
}
17
resource "random_string" "random" {
28
length = 24
39
special = false
@@ -9,7 +15,7 @@ module "dsitrubtion_cache" {
915

1016
aws_region = var.aws_region
1117
environment = var.environment
12-
tags = var.tags
18+
tags = local.tags
1319

1420
distribution_bucket_name = "${var.environment}-dist-${random_string.random.result}"
1521
}
@@ -20,12 +26,23 @@ module "runners" {
2026
aws_region = var.aws_region
2127
vpc_id = var.vpc_id
2228
environment = var.environment
23-
tags = var.tags
29+
tags = local.tags
2430

2531
s3_location_runner_distribution = module.dsitrubtion_cache.s3_location_runner_distribution
2632
}
2733

2834

35+
module "agent" {
36+
source = "./modules/agent"
37+
38+
aws_region = var.aws_region
39+
environment = var.environment
40+
tags = local.tags
41+
42+
github_app_webhook_secret = var.github_app_webhook_secret
43+
}
44+
45+
2946
resource "aws_iam_policy" "dist_bucket" {
3047
name = "${var.environment}-gh-distribution-bucket"
3148
path = "/"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
root: true,
3+
parser: '@typescript-eslint/parser',
4+
plugins: ['@typescript-eslint'],
5+
extends: [
6+
'eslint:recommended',
7+
'plugin:@typescript-eslint/eslint-recommended',
8+
'plugin:@typescript-eslint/recommended',
9+
],
10+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# dependencies
2+
node_modules/
3+
4+
# production
5+
dist/
6+
build/
7+
8+
# misc
9+
.DS_Store
10+
.env*
11+
*.zip
12+
13+
npm-debug.log*
14+
yarn-debug.log*
15+
yarn-error.log*
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v12.16.1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"printWidth": 120,
3+
"singleQuote": true,
4+
"trailingComma": "all"
5+
}

0 commit comments

Comments
 (0)