Skip to content

Commit afe136f

Browse files
committed
Add labels support #11
1 parent 4193ac0 commit afe136f

File tree

10 files changed

+56
-10
lines changed

10 files changed

+56
-10
lines changed

.ci/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node:12
2+
3+
WORKDIR /lambda
4+
5+
COPY . /lambda
6+
7+
RUN apt-get update \
8+
&& apt-get install -y zip \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
RUN yarn install \
12+
&& yarn run dist
13+

.ci/build.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
lambaSrcDirs=("modules/runner-binaries-syncer/lambdas/runner-binaries-syncer" "modules/runners/lambdas/scale-runners" "modules/webhook/lambdas/webhook")
4+
repoRoot=$(dirname "${BASH_SOURCE[0]}")/..
5+
6+
for lambdaDir in ${lambaSrcDirs[@]}; do
7+
cd $repoRoot/${lambdaDir}
8+
docker build -t lambda -f ../../../../.ci/Dockerfile .
9+
docker create --name lambda lambda
10+
zipName=$(basename "$PWD")
11+
docker cp lambda:/lambda/${zipName}.zip ${zipName}.zip
12+
docker rm lambda
13+
done

examples/default/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module "runners" {
2929
}
3030

3131
enable_organization_runners = false
32+
runner_extra_labels = "default,example"
3233
}
3334

3435

main.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ module "runners" {
4646
s3_bucket_runner_binaries = module.runner_binaries.bucket
4747
s3_location_runner_binaries = local.s3_action_runner_url
4848

49-
sqs = aws_sqs_queue.queued_builds
50-
github_app = var.github_app
51-
enable_organization_runners = var.enable_organization_runners
52-
scale_down_schedule_expression = var.scale_down_schedule_expression
49+
sqs = aws_sqs_queue.queued_builds
50+
github_app = var.github_app
51+
enable_organization_runners = var.enable_organization_runners
52+
scale_down_schedule_expression = var.scale_down_schedule_expression
53+
minimum_running_time_in_minutes = var.minimum_running_time_in_minutes
54+
runner_extra_labels = var.runner_extra_labels
5355
}
5456

5557
module "runner_binaries" {

modules/runners/lambdas/scale-runners/src/scale-runners/runners.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export async function createRunner(runnerParameters: RunnerInputParameters): Pro
7272

7373
const subnets = (process.env.SUBNET_IDS as string).split(',');
7474
const randomSubnet = subnets[Math.floor(Math.random() * subnets.length)];
75-
75+
console.debug('Runner configuration: ' + JSON.stringify(runnerParameters));
7676
const ec2 = new EC2();
7777
const runInstancesResponse = await ec2
7878
.runInstances({

modules/runners/lambdas/scale-runners/src/scale-runners/scale-up.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ describe('scaleUp', () => {
3838
process.env.GITHUB_APP_CLIENT_SECRET = 'TEST_CLIENT_SECRET';
3939
process.env.RUNNERS_MAXIMUM_COUNT = '3';
4040
process.env.ENVIRONMENT = 'unit-test-environment';
41+
4142
jest.clearAllMocks();
4243
mockOctokit.actions.listRepoWorkflowRuns.mockImplementation(() => ({
4344
data: {
@@ -115,7 +116,7 @@ describe('scaleUp', () => {
115116
await scaleUp('aws:sqs', TEST_DATA);
116117
expect(createRunner).toBeCalledWith({
117118
environment: 'unit-test-environment',
118-
runnerConfig: `--url https://github.com/${TEST_DATA.repositoryOwner} --token 1234abcd`,
119+
runnerConfig: `--url https://github.com/${TEST_DATA.repositoryOwner} --token 1234abcd `,
119120
orgName: TEST_DATA.repositoryOwner,
120121
repoName: undefined,
121122
});
@@ -149,11 +150,12 @@ describe('scaleUp', () => {
149150
});
150151
});
151152

152-
it('creates a runner with correct config', async () => {
153+
it('creates a runner with correct config and labels', async () => {
154+
process.env.RUNNER_EXTRA_LABELS = 'label1,label2';
153155
await scaleUp('aws:sqs', TEST_DATA);
154156
expect(createRunner).toBeCalledWith({
155157
environment: 'unit-test-environment',
156-
runnerConfig: `--url https://github.com/${TEST_DATA.repositoryOwner}/${TEST_DATA.repositoryName} --token 1234abcd`,
158+
runnerConfig: `--url https://github.com/${TEST_DATA.repositoryOwner}/${TEST_DATA.repositoryName} --token 1234abcd --labels label1,label2`,
157159
orgName: undefined,
158160
repoName: `${TEST_DATA.repositoryOwner}/${TEST_DATA.repositoryName}`,
159161
});

modules/runners/lambdas/scale-runners/src/scale-runners/scale-up.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const scaleUp = async (eventSource: string, payload: ActionRequestMessage
3636
if (eventSource !== 'aws:sqs') throw Error('Cannot handle non-SQS events!');
3737
const enableOrgLevel = yn(process.env.ENABLE_ORGANIZATION_RUNNERS, { default: true });
3838
const maximumRunners = parseInt(process.env.RUNNERS_MAXIMUM_COUNT || '3');
39+
const runnerExtraLabels = process.env.RUNNER_EXTRA_LABELS;
3940
const environment = process.env.ENVIRONMENT as string;
4041
const githubAppAuth = createGithubAppAuth(payload.installationId);
4142
const githubInstallationClient = await createInstallationClient(githubAppAuth);
@@ -72,11 +73,12 @@ export const scaleUp = async (eventSource: string, payload: ActionRequestMessage
7273
});
7374
const token = registrationToken.data.token;
7475

76+
const labelsArgument = runnerExtraLabels !== undefined ? `--labels ${runnerExtraLabels}` : '';
7577
await createRunner({
7678
environment: environment,
7779
runnerConfig: enableOrgLevel
78-
? `--url https://github.com/${payload.repositoryOwner} --token ${token}`
79-
: `--url https://github.com/${payload.repositoryOwner}/${payload.repositoryName} --token ${token}`,
80+
? `--url https://github.com/${payload.repositoryOwner} --token ${token} ${labelsArgument}`
81+
: `--url https://github.com/${payload.repositoryOwner}/${payload.repositoryName} --token ${token} ${labelsArgument}`,
8082
orgName: enableOrgLevel ? payload.repositoryOwner : undefined,
8183
repoName: enableOrgLevel ? undefined : `${payload.repositoryOwner}/${payload.repositoryName}`,
8284
});

modules/runners/scale-up.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ resource "aws_lambda_function" "scale_up" {
1010
environment {
1111
variables = {
1212
ENABLE_ORGANIZATION_RUNNERS = var.enable_organization_runners
13+
RUNNER_EXTRA_LABELS = var.runner_extra_labels
1314
GITHUB_APP_KEY_BASE64 = var.github_app.key_base64
1415
GITHUB_APP_ID = var.github_app.id
1516
GITHUB_APP_CLIENT_ID = var.github_app.client_id

modules/runners/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,9 @@ variable "minimum_running_time_in_minutes" {
120120
type = number
121121
default = 5
122122
}
123+
124+
variable "runner_extra_labels" {
125+
description = "Extra labels for the runners (GitHub). Separate each label by a comma"
126+
type = string
127+
default = ""
128+
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,9 @@ variable "minimum_running_time_in_minutes" {
5151
type = number
5252
default = 5
5353
}
54+
55+
variable "runner_extra_labels" {
56+
description = "Extra labels for the runners (GitHub). Separate each label by a comma"
57+
type = string
58+
default = ""
59+
}

0 commit comments

Comments
 (0)