Skip to content

Commit 65b2a77

Browse files
authored
Merge branch 'main' into update-docs-e96ilc1
2 parents 9fb9063 + 1aef82b commit 65b2a77

File tree

24 files changed

+1010
-927
lines changed

24 files changed

+1010
-927
lines changed

.github/workflows/stale.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
stale-pr-message: >
1919
This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs. Thank you for your contributions.
2020
21-
days-before-stale: 30
22-
days-before-close: 10
21+
days-before-stale: 90
22+
days-before-close: 14
2323
close-issue-label: "abandoned"
2424
exempt-issue-labels: "stale:exempt"

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Changelog
22

3+
## [5.11.0](https://github.com/philips-labs/terraform-aws-github-runner/compare/v5.10.4...v5.11.0) (2024-05-22)
4+
5+
6+
### Features
7+
8+
* add variable to configure ebs optimization for runner instances ([479b779](https://github.com/philips-labs/terraform-aws-github-runner/commit/479b779a71c77a62dd28d247f8a74cb75ce083f0))
9+
* add variable to configure ebs optimization for runner instances ([#3901](https://github.com/philips-labs/terraform-aws-github-runner/issues/3901)) ([479b779](https://github.com/philips-labs/terraform-aws-github-runner/commit/479b779a71c77a62dd28d247f8a74cb75ce083f0))
10+
* Restrict instance SSM permissions ([#3918](https://github.com/philips-labs/terraform-aws-github-runner/issues/3918)) ([9399cf2](https://github.com/philips-labs/terraform-aws-github-runner/commit/9399cf29bec963dfa305f367f37c098a76130371))
11+
12+
13+
### Bug Fixes
14+
15+
* adding missing permissions to boundaries ([#3873](https://github.com/philips-labs/terraform-aws-github-runner/issues/3873)) ([93e8d27](https://github.com/philips-labs/terraform-aws-github-runner/commit/93e8d2746b647539212dbc65887ec748a1d734b7))
16+
* **lambda:** bump the aws group across 1 directory with 6 updates ([#3907](https://github.com/philips-labs/terraform-aws-github-runner/issues/3907)) ([50dda9a](https://github.com/philips-labs/terraform-aws-github-runner/commit/50dda9a465229bdb8d106e7ebc5d5b1de115a286))
17+
318
## [5.10.4](https://github.com/philips-labs/terraform-aws-github-runner/compare/v5.10.3...v5.10.4) (2024-05-06)
419

520

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ Talk to the forestkeepers in the `runners-channel` on Slack.
179179
| <a name="input_log_level"></a> [log\_level](#input\_log\_level) | Logging level for lambda logging. Valid values are 'silly', 'trace', 'debug', 'info', 'warn', 'error', 'fatal'. | `string` | `"info"` | no |
180180
| <a name="input_logging_kms_key_id"></a> [logging\_kms\_key\_id](#input\_logging\_kms\_key\_id) | Specifies the kms key id to encrypt the logs with. | `string` | `null` | no |
181181
| <a name="input_logging_retention_in_days"></a> [logging\_retention\_in\_days](#input\_logging\_retention\_in\_days) | Specifies the number of days you want to retain log events for the lambda log group. Possible values are: 0, 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, and 3653. | `number` | `180` | no |
182+
| <a name="input_matcher_config_parameter_store_tier"></a> [matcher\_config\_parameter\_store\_tier](#input\_matcher\_config\_parameter\_store\_tier) | The tier of the parameter store for the matcher configuration. Valid values are `Standard`, and `Advanced`. | `string` | `"Standard"` | no |
182183
| <a name="input_metrics_namespace"></a> [metrics\_namespace](#input\_metrics\_namespace) | The namespace for the metrics created by the module. Merics will only be created if explicit enabled. | `string` | `"GitHub Runners"` | no |
183184
| <a name="input_minimum_running_time_in_minutes"></a> [minimum\_running\_time\_in\_minutes](#input\_minimum\_running\_time\_in\_minutes) | The time an ec2 action runner should be running at minimum before terminated, if not busy. | `number` | `null` | no |
184185
| <a name="input_pool_config"></a> [pool\_config](#input\_pool\_config) | The configuration for updating the pool. The `pool_size` to adjust to by the events triggered by the `schedule_expression`. For example you can configure a cron expression for weekdays to adjust the pool to 10 and another expression for the weekend to adjust the pool to 1. | <pre>list(object({<br> schedule_expression = string<br> size = number<br> }))</pre> | `[]` | no |

lambdas/functions/ami-housekeeper/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
"ts-node-dev": "^2.0.0"
3838
},
3939
"dependencies": {
40-
"@aws-sdk/client-ec2": "^3.575.0",
41-
"@aws-sdk/client-ssm": "^3.575.0",
40+
"@aws-sdk/client-ec2": "^3.600.0",
41+
"@aws-sdk/client-ssm": "^3.600.0",
4242
"@aws-sdk/types": "^3.433.0",
4343
"@terraform-aws-github-runner/aws-powertools-util": "*",
4444
"@terraform-aws-github-runner/aws-ssm-util": "*",

lambdas/functions/control-plane/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"ts-node-dev": "^2.0.0"
3939
},
4040
"dependencies": {
41-
"@aws-sdk/client-ec2": "^3.575.0",
41+
"@aws-sdk/client-ec2": "^3.600.0",
4242
"@aws-sdk/types": "^3.433.0",
4343
"@middy/core": "^4.7.0",
4444
"@octokit/auth-app": "6.0.3",

lambdas/functions/control-plane/src/aws/runners.ts

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ function getRunnerInfo(runningInstances: DescribeInstancesResult) {
9494
}
9595

9696
export async function terminateRunner(instanceId: string): Promise<void> {
97+
logger.info(`Runner '${instanceId}' will be terminated.`);
9798
const ec2 = getTracedAWSV3Client(new EC2Client({ region: process.env.AWS_REGION }));
9899
await ec2.send(new TerminateInstancesCommand({ InstanceIds: [instanceId] }));
99100
logger.info(`Runner ${instanceId} has been terminated.`);

lambdas/functions/control-plane/src/scale-runners/scale-down.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ async function listGitHubRunners(runner: RunnerInfo): Promise<GhRunners> {
8888
per_page: 100,
8989
});
9090
githubCache.runners.set(key, runners);
91-
91+
logger.debug(`[listGithubRunners] Cache set for ${key}`);
92+
logger.debug(`[listGithubRunners] Runners: ${JSON.stringify(runners)}`);
9293
return runners;
9394
}
9495

@@ -156,18 +157,25 @@ async function evaluateAndRemoveRunners(
156157
.filter((runner) => runner.owner === ownerTag)
157158
.sort(evictionStrategy === 'oldest_first' ? oldestFirstStrategy : newestFirstStrategy);
158159
logger.debug(`Found: '${ec2RunnersFiltered.length}' active GitHub runners with owner tag: '${ownerTag}'`);
160+
logger.debug(`Active GitHub runners with owner tag: '${ownerTag}': ${JSON.stringify(ec2RunnersFiltered)}`);
159161
for (const ec2Runner of ec2RunnersFiltered) {
160162
const ghRunners = await listGitHubRunners(ec2Runner);
161163
const ghRunnersFiltered = ghRunners.filter((runner: { name: string }) =>
162164
runner.name.endsWith(ec2Runner.instanceId),
163165
);
166+
logger.debug(
167+
`Found: '${ghRunnersFiltered.length}' GitHub runners for AWS runner instance: '${ec2Runner.instanceId}'`,
168+
);
169+
logger.debug(
170+
`GitHub runners for AWS runner instance: '${ec2Runner.instanceId}': ${JSON.stringify(ghRunnersFiltered)}`,
171+
);
164172
if (ghRunnersFiltered.length) {
165173
if (runnerMinimumTimeExceeded(ec2Runner)) {
166174
if (idleCounter > 0) {
167175
idleCounter--;
168176
logger.info(`Runner '${ec2Runner.instanceId}' will be kept idle.`);
169177
} else {
170-
logger.info(`Runner '${ec2Runner.instanceId}' will be terminated.`);
178+
logger.info(`Will try to terminate runners that are not busy`);
171179
await removeRunner(
172180
ec2Runner,
173181
ghRunnersFiltered.map((runner: { id: number }) => runner.id),
@@ -224,6 +232,7 @@ export async function scaleDown(): Promise<void> {
224232
const ec2Runners = await listRunners(environment);
225233
const activeEc2RunnersCount = ec2Runners.length;
226234
logger.info(`Found: '${activeEc2RunnersCount}' active GitHub EC2 runner instances before clean-up.`);
235+
logger.debug(`Active GitHub EC2 runner instances: ${JSON.stringify(ec2Runners)}`);
227236

228237
if (activeEc2RunnersCount === 0) {
229238
logger.debug(`No active runners found for environment: '${environment}'`);

lambdas/functions/gh-agent-syncer/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
"typescript": "^5.4.5"
3838
},
3939
"dependencies": {
40-
"@aws-sdk/client-s3": "^3.575.0",
41-
"@aws-sdk/lib-storage": "^3.575.0",
40+
"@aws-sdk/client-s3": "^3.600.0",
41+
"@aws-sdk/lib-storage": "^3.600.0",
4242
"@aws-sdk/types": "^3.433.0",
4343
"@middy/core": "^4.7.0",
4444
"@terraform-aws-github-runner/aws-powertools-util": "*",

lambdas/functions/termination-watcher/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"ts-node-dev": "^2.0.0"
3636
},
3737
"dependencies": {
38-
"@aws-sdk/client-ec2": "^3.575.0",
38+
"@aws-sdk/client-ec2": "^3.600.0",
3939
"@aws-sdk/types": "^3.433.0",
4040
"@middy/core": "^4.7.0",
4141
"@terraform-aws-github-runner/aws-powertools-util": "*",

lambdas/functions/webhook/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"typescript": "^5.4.5"
3939
},
4040
"dependencies": {
41-
"@aws-sdk/client-sqs": "^3.575.0",
41+
"@aws-sdk/client-sqs": "^3.600.0",
4242
"@middy/core": "^4.7.0",
4343
"@octokit/rest": "^20.0.1",
4444
"@octokit/types": "^12.5.0",

lambdas/functions/webhook/src/ConfigResolver.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class Config {
2929
Config.matcherConfig = JSON.parse(matcherConfigVal) as Array<RunnerMatcherConfig>;
3030
logger.debug('Loaded queues config', { matcherConfig: Config.matcherConfig });
3131
}
32-
const workflowJobEventSecondaryQueue = process.env.SQS_WORKFLOW_JOB_QUEUE ?? undefined;
32+
const workflowJobEventSecondaryQueue = process.env.SQS_WORKFLOW_JOB_QUEUE || undefined;
3333
return new Config(repositoryAllowList, workflowJobEventSecondaryQueue);
3434
}
3535

lambdas/functions/webhook/src/sqs/index.test.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jest.mock('@aws-sdk/client-sqs', () => ({
1616
}));
1717
jest.mock('@terraform-aws-github-runner/aws-ssm-util');
1818

19+
import { SQS } from '@aws-sdk/client-sqs';
20+
1921
describe('Test sending message to SQS.', () => {
2022
const queueUrl = 'https://sqs.eu-west-1.amazonaws.com/123456789/queued-builds';
2123
const message = {
@@ -98,15 +100,27 @@ describe('Test sending message to SQS.', () => {
98100
expect(result).resolves;
99101
});
100102

101-
it('Does not send webhook events to workflow job event copy queue', async () => {
103+
it('Does not send webhook events to workflow job event copy queue when job queue is not in environment', async () => {
104+
// Arrange
105+
delete process.env.SQS_WORKFLOW_JOB_QUEUE;
106+
const config = await Config.load();
107+
108+
// Act
109+
await sendWebhookEventToWorkflowJobQueue(message, config);
110+
111+
// Assert
112+
expect(SQS).not.toHaveBeenCalled();
113+
});
114+
115+
it('Does not send webhook events to workflow job event copy queue when job queue is set to empty string', async () => {
102116
// Arrange
103117
process.env.SQS_WORKFLOW_JOB_QUEUE = '';
104118
const config = await Config.load();
105119
// Act
106120
await sendWebhookEventToWorkflowJobQueue(message, config);
107121

108122
// Assert
109-
expect(mockSQS.sendMessage).not.toHaveBeenCalledWith(sqsMessage);
123+
expect(SQS).not.toHaveBeenCalled();
110124
});
111125

112126
it('Catch the exception when even copy queue throws exception', async () => {

lambdas/functions/webhook/src/sqs/index.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,21 @@ export const sendActionRequest = async (message: ActionRequestMessage): Promise<
5050
};
5151

5252
export async function sendWebhookEventToWorkflowJobQueue(message: GithubWorkflowEvent, config: Config): Promise<void> {
53-
if (config.workflowJobEventSecondaryQueue != undefined) {
54-
const sqs = new SQS({ region: process.env.AWS_REGION });
55-
const sqsMessage: SendMessageCommandInput = {
56-
QueueUrl: String(config.workflowJobEventSecondaryQueue),
57-
MessageBody: JSON.stringify(message),
58-
};
59-
logger.debug(`Sending Webhook events to the workflow job queue: ${config.workflowJobEventSecondaryQueue}`);
60-
try {
61-
await sqs.sendMessage(sqsMessage);
62-
} catch (e) {
63-
logger.warn(`Error in sending webhook events to workflow job queue: ${(e as Error).message}`);
64-
}
53+
if (!config.workflowJobEventSecondaryQueue) {
54+
return;
55+
}
56+
57+
const sqs = new SQS({ region: process.env.AWS_REGION });
58+
const sqsMessage: SendMessageCommandInput = {
59+
QueueUrl: String(config.workflowJobEventSecondaryQueue),
60+
MessageBody: JSON.stringify(message),
61+
};
62+
63+
logger.debug(`Sending Webhook events to the workflow job queue: ${config.workflowJobEventSecondaryQueue}`);
64+
65+
try {
66+
await sqs.sendMessage(sqsMessage);
67+
} catch (e) {
68+
logger.warn(`Error in sending webhook events to workflow job queue: ${(e as Error).message}`);
6569
}
6670
}

lambdas/libs/aws-ssm-util/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"typescript": "^5.4.5"
3737
},
3838
"dependencies": {
39-
"@aws-sdk/client-ssm": "^3.575.0",
39+
"@aws-sdk/client-ssm": "^3.600.0",
4040
"@aws-sdk/types": "^3.433.0",
4141
"@terraform-aws-github-runner/aws-powertools-util": "*"
4242
},

0 commit comments

Comments
 (0)