Skip to content

Commit 9522041

Browse files
authored
Merge pull request #2714 from philips-labs/develop
chore: Release
2 parents 171ea71 + c91a96b commit 9522041

File tree

11 files changed

+1033
-1028
lines changed

11 files changed

+1033
-1028
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ The setup consists of running Terraform to create all AWS resources and manually
109109

110110
### Setup GitHub App (part 1)
111111

112-
Go to GitHub and [create a new app](https://docs.github.com/en/developers/apps/creating-a-github-app). Beware you can create apps your organization or for a user. For now we support only organization level apps.
112+
Go to GitHub and [create a new app](https://docs.github.com/en/developers/apps/creating-a-github-app). Beware you can create apps for your organization or for a user. For now we support only organization level apps.
113113

114114
1. Create app in Github
115115
2. Choose a name

main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,5 +289,8 @@ module "runner_binaries" {
289289
log_type = var.log_type
290290
log_level = var.log_level
291291

292+
lambda_subnet_ids = var.lambda_subnet_ids
293+
lambda_security_group_ids = var.lambda_security_group_ids
294+
292295
lambda_principals = var.lambda_principals
293296
}

modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
"@typescript-eslint/eslint-plugin": "^4.33.0",
2424
"@typescript-eslint/parser": "^4.33.0",
2525
"@vercel/ncc": "^0.34.0",
26-
"aws-sdk": "^2.1256.0",
26+
"aws-sdk": "^2.1265.0",
2727
"eslint": "^7.32.0",
2828
"eslint-plugin-prettier": "4.2.1",
2929
"jest": "^29.3",
3030
"jest-mock": "^29.3.1",
31-
"prettier": "2.7.1",
31+
"prettier": "2.8.0",
3232
"ts-jest": "^29.0.3",
3333
"ts-node-dev": "^2.0.0",
34-
"typescript": "^4.8.4"
34+
"typescript": "^4.9.3"
3535
},
3636
"dependencies": {
37-
"axios": "^1.1.3",
37+
"axios": "^1.2.0",
3838
"tslog": "^3.3.4"
3939
}
4040
}

modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/yarn.lock

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,10 +1392,10 @@ available-typed-arrays@^1.0.5:
13921392
resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7"
13931393
integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==
13941394

1395-
aws-sdk@^2.1256.0:
1396-
version "2.1256.0"
1397-
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.1256.0.tgz#4cac62e8bbd1f8a363cd506328103b3498bfa767"
1398-
integrity sha512-/Dh81PZdjqyZwA3BMBUO2PMUakv0hqjxCReE59sskIFdQJdSOW+26EQ4LcV07YP6umz3n5TKC28bEfx6l2kTJQ==
1395+
aws-sdk@^2.1265.0:
1396+
version "2.1265.0"
1397+
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.1265.0.tgz#ec034b10126d7c81242b2501567cb4d5179a4e61"
1398+
integrity sha512-PcW3VAxatnOgSwdENkXpFAKnE6P5GJeI7yxjEhjHSLXFyOzQZQZIT5NMCs7B25nB6iACzxizjKaYbU0kNA/8/Q==
13991399
dependencies:
14001400
buffer "4.9.2"
14011401
events "1.1.1"
@@ -1408,10 +1408,10 @@ aws-sdk@^2.1256.0:
14081408
uuid "8.0.0"
14091409
xml2js "0.4.19"
14101410

1411-
axios@^1.1.3:
1412-
version "1.1.3"
1413-
resolved "https://registry.yarnpkg.com/axios/-/axios-1.1.3.tgz#8274250dada2edf53814ed7db644b9c2866c1e35"
1414-
integrity sha512-00tXVRwKx/FZr/IDVFt4C+f9FYairX517WoGCL6dpOntqLkZofjhu43F/Xl44UOpqa+9sLFDrG/XAnFsUYgkDA==
1411+
axios@^1.2.0:
1412+
version "1.2.0"
1413+
resolved "https://registry.yarnpkg.com/axios/-/axios-1.2.0.tgz#1cb65bd75162c70e9f8d118a905126c4a201d383"
1414+
integrity sha512-zT7wZyNYu3N5Bu0wuZ6QccIf93Qk1eV8LOewxgjOZFd2DenOs98cJ7+Y6703d0wkaXGY6/nZd4EweJaHz9uzQw==
14151415
dependencies:
14161416
follow-redirects "^1.15.0"
14171417
form-data "^4.0.0"
@@ -1693,7 +1693,7 @@ combined-stream@^1.0.6, combined-stream@^1.0.8:
16931693
16941694
version "0.0.1"
16951695
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
1696-
integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=
1696+
integrity sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==
16971697

16981698
convert-source-map@^1.6.0, convert-source-map@^1.7.0:
16991699
version "1.8.0"
@@ -3151,9 +3151,9 @@ mimic-fn@^2.1.0:
31513151
integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==
31523152

31533153
minimatch@^3.0.4:
3154-
version "3.0.4"
3155-
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
3156-
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
3154+
version "3.1.2"
3155+
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"
3156+
integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==
31573157
dependencies:
31583158
brace-expansion "^1.1.7"
31593159

@@ -3368,10 +3368,10 @@ prettier-linter-helpers@^1.0.0:
33683368
dependencies:
33693369
fast-diff "^1.1.2"
33703370

3371-
prettier@2.7.1:
3372-
version "2.7.1"
3373-
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64"
3374-
integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==
3371+
prettier@2.8.0:
3372+
version "2.8.0"
3373+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.0.tgz#c7df58393c9ba77d6fba3921ae01faf994fb9dc9"
3374+
integrity sha512-9Lmg8hTFZKG0Asr/kW9Bp8tJjRVluO8EJQVfY2T7FMw9T5jy4I/Uvx0Rca/XWf50QQ1/SS48+6IJWnrb+2yemA==
33753375

33763376
pretty-format@^29.0.0, pretty-format@^29.3.1:
33773377
version "29.3.1"
@@ -3882,10 +3882,10 @@ type-fest@^0.21.3:
38823882
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37"
38833883
integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==
38843884

3885-
typescript@^4.8.4:
3886-
version "4.8.4"
3887-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.4.tgz#c464abca159669597be5f96b8943500b238e60e6"
3888-
integrity sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==
3885+
typescript@^4.9.3:
3886+
version "4.9.3"
3887+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.3.tgz#3aea307c1746b8c384435d8ac36b8a2e580d85db"
3888+
integrity sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==
38893889

38903890
unbox-primitive@^1.0.2:
38913891
version "1.0.2"

modules/runners/lambdas/runners/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,24 @@
2828
"jest": "^29.3",
2929
"jest-mock": "^29.3.1",
3030
"jest-mock-extended": "^3.0.1",
31-
"moment-timezone": "^0.5.38",
31+
"moment-timezone": "^0.5.39",
3232
"nock": "^13.2.9",
3333
"prettier": "2.7.1",
3434
"ts-jest": "^29.0.3",
3535
"ts-node": "^10.9.1",
3636
"ts-node-dev": "^2.0.0"
3737
},
3838
"dependencies": {
39-
"@aws-sdk/client-ssm": "^3.210.0",
39+
"@aws-sdk/client-ssm": "^3.218.0",
4040
"@octokit/auth-app": "4.0.7",
4141
"@octokit/rest": "^19.0.5",
4242
"@octokit/types": "^8.0.0",
4343
"@types/aws-lambda": "^8.10.108",
4444
"@types/express": "^4.17.14",
4545
"@types/node": "^18.11.9",
46-
"aws-sdk": "^2.1253.0",
46+
"aws-sdk": "^2.1265.0",
4747
"cron-parser": "^4.6.0",
4848
"tslog": "^3.3.4",
49-
"typescript": "^4.8.4"
49+
"typescript": "^4.9.3"
5050
}
5151
}

modules/runners/lambdas/runners/src/aws/runners.test.ts

Lines changed: 66 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,53 @@ const ORG_NAME = 'SomeAwesomeCoder';
1515
const REPO_NAME = `${ORG_NAME}/some-amazing-library`;
1616
const ENVIRONMENT = 'unit-test-environment';
1717

18-
describe('list instances', () => {
19-
const mockDescribeInstances = { promise: jest.fn() };
20-
beforeEach(() => {
21-
jest.clearAllMocks();
22-
mockEC2.describeInstances.mockImplementation(() => mockDescribeInstances);
23-
const mockRunningInstances: AWS.EC2.DescribeInstancesResult = {
24-
Reservations: [
18+
const mockDescribeInstances = { promise: jest.fn() };
19+
mockEC2.describeInstances.mockImplementation(() => mockDescribeInstances);
20+
const mockRunningInstances: AWS.EC2.DescribeInstancesResult = {
21+
Reservations: [
22+
{
23+
Instances: [
2524
{
26-
Instances: [
27-
{
28-
LaunchTime: new Date('2020-10-10T14:48:00.000+09:00'),
29-
InstanceId: 'i-1234',
30-
Tags: [
31-
{ Key: 'Application', Value: 'github-action-runner' },
32-
{ Key: 'Type', Value: 'Org' },
33-
{ Key: 'Owner', Value: 'CoderToCat' },
34-
],
35-
},
36-
{
37-
LaunchTime: new Date('2020-10-11T14:48:00.000+09:00'),
38-
InstanceId: 'i-5678',
39-
Tags: [
40-
{ Key: 'Owner', Value: REPO_NAME },
41-
{ Key: 'Type', Value: 'Repo' },
42-
{ Key: 'Application', Value: 'github-action-runner' },
43-
],
44-
},
25+
LaunchTime: new Date('2020-10-10T14:48:00.000+09:00'),
26+
InstanceId: 'i-1234',
27+
Tags: [
28+
{ Key: 'ghr:Application', Value: 'github-action-runner' },
29+
{ Key: 'Type', Value: 'Org' },
30+
{ Key: 'Owner', Value: 'CoderToCat' },
4531
],
4632
},
4733
],
48-
};
49-
mockDescribeInstances.promise.mockReturnValue(mockRunningInstances);
34+
},
35+
],
36+
};
37+
const mockRunningInstancesLegacy: AWS.EC2.DescribeInstancesResult = {
38+
Reservations: [
39+
{
40+
Instances: [
41+
{
42+
LaunchTime: new Date('2020-10-11T14:48:00.000+09:00'),
43+
InstanceId: 'i-5678',
44+
Tags: [
45+
{ Key: 'Owner', Value: REPO_NAME },
46+
{ Key: 'Type', Value: 'Repo' },
47+
{ Key: 'Application', Value: 'github-action-runner' },
48+
],
49+
},
50+
],
51+
},
52+
],
53+
};
54+
55+
describe('list instances', () => {
56+
beforeEach(() => {
57+
jest.resetModules();
58+
jest.clearAllMocks();
5059
});
5160

5261
it('returns a list of instances', async () => {
62+
mockDescribeInstances.promise
63+
.mockReturnValueOnce(mockRunningInstances)
64+
.mockReturnValueOnce(mockRunningInstancesLegacy);
5365
const resp = await listEC2Runners();
5466
expect(resp.length).toBe(2);
5567
expect(resp).toContainEqual({
@@ -67,41 +79,61 @@ describe('list instances', () => {
6779
});
6880

6981
it('calls EC2 describe instances', async () => {
82+
mockDescribeInstances.promise
83+
.mockReturnValueOnce(mockRunningInstances)
84+
.mockReturnValueOnce(mockRunningInstancesLegacy);
7085
await listEC2Runners();
7186
expect(mockEC2.describeInstances).toBeCalled();
7287
});
7388

7489
it('filters instances on repo name', async () => {
90+
mockDescribeInstances.promise
91+
.mockReturnValueOnce(mockRunningInstances)
92+
.mockReturnValueOnce(mockRunningInstancesLegacy);
7593
await listEC2Runners({ runnerType: 'Repo', runnerOwner: REPO_NAME, environment: undefined });
7694
expect(mockEC2.describeInstances).toBeCalledWith({
7795
Filters: [
78-
{ Name: 'tag:Application', Values: ['github-action-runner'] },
7996
{ Name: 'instance-state-name', Values: ['running', 'pending'] },
8097
{ Name: 'tag:Type', Values: ['Repo'] },
8198
{ Name: 'tag:Owner', Values: [REPO_NAME] },
99+
{ Name: 'tag:ghr:Application', Values: ['github-action-runner'] },
100+
],
101+
});
102+
expect(mockEC2.describeInstances).toBeCalledWith({
103+
Filters: [
104+
{ Name: 'instance-state-name', Values: ['running', 'pending'] },
105+
{ Name: 'tag:Type', Values: ['Repo'] },
106+
{ Name: 'tag:Owner', Values: [REPO_NAME] },
107+
{ Name: 'tag:Application', Values: ['github-action-runner'] },
82108
],
83109
});
84110
});
85111

86112
it('filters instances on org name', async () => {
113+
mockDescribeInstances.promise
114+
.mockReturnValueOnce(mockRunningInstances)
115+
.mockReturnValueOnce(mockRunningInstancesLegacy);
87116
await listEC2Runners({ runnerType: 'Org', runnerOwner: ORG_NAME, environment: undefined });
88117
expect(mockEC2.describeInstances).toBeCalledWith({
89118
Filters: [
90-
{ Name: 'tag:Application', Values: ['github-action-runner'] },
91119
{ Name: 'instance-state-name', Values: ['running', 'pending'] },
92120
{ Name: 'tag:Type', Values: ['Org'] },
93121
{ Name: 'tag:Owner', Values: [ORG_NAME] },
122+
{ Name: 'tag:ghr:Application', Values: ['github-action-runner'] },
94123
],
95124
});
96125
});
97126

98127
it('filters instances on environment', async () => {
128+
mockDescribeInstances.promise
129+
.mockReturnValueOnce(mockRunningInstances)
130+
.mockReturnValueOnce(mockRunningInstancesLegacy);
99131
await listEC2Runners({ environment: ENVIRONMENT });
100132
expect(mockEC2.describeInstances).toBeCalledWith({
101133
Filters: [
102-
{ Name: 'tag:Application', Values: ['github-action-runner'] },
103134
{ Name: 'instance-state-name', Values: ['running', 'pending'] },
104135
{ Name: 'tag:ghr:environment', Values: [ENVIRONMENT] },
136+
{ Name: 'tag:ghr:Application', Values: ['github-action-runner'] },
105137
],
106138
});
107139
});
@@ -123,7 +155,7 @@ describe('list instances', () => {
123155
},
124156
],
125157
};
126-
mockDescribeInstances.promise.mockReturnValue(noInstances);
158+
mockDescribeInstances.promise.mockReturnValueOnce(noInstances).mockReturnValueOnce(noInstances);
127159
const resp = await listEC2Runners();
128160
expect(resp.length).toBe(0);
129161
});
@@ -142,7 +174,7 @@ describe('list instances', () => {
142174
},
143175
],
144176
};
145-
mockDescribeInstances.promise.mockReturnValue(noInstances);
177+
mockDescribeInstances.promise.mockReturnValueOnce(noInstances).mockReturnValue({});
146178
const resp = await listEC2Runners();
147179
expect(resp.length).toBe(1);
148180
});
@@ -459,7 +491,7 @@ function expectedCreateFleetRequest(expectedValues: ExpectedFleetRequestValues):
459491
{
460492
ResourceType: 'instance',
461493
Tags: [
462-
{ Key: 'Application', Value: 'github-action-runner' },
494+
{ Key: 'ghr:Application', Value: 'github-action-runner' },
463495
{ Key: 'Type', Value: expectedValues.type },
464496
{ Key: 'Owner', Value: REPO_NAME },
465497
],

modules/runners/lambdas/runners/src/aws/runners.ts

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,47 @@ export interface RunnerInputParameters {
4545
amiIdSsmParameterName?: string;
4646
}
4747

48+
interface Ec2Filter {
49+
Name: string;
50+
Values: string[];
51+
}
52+
4853
export async function listEC2Runners(filters: ListRunnerFilters | undefined = undefined): Promise<RunnerList[]> {
49-
const ec2Statuses = filters?.statuses ? filters.statuses : ['running', 'pending'];
50-
const ec2 = new EC2();
51-
const ec2Filters = [
52-
{ Name: 'tag:Application', Values: ['github-action-runner'] },
53-
{ Name: 'instance-state-name', Values: ec2Statuses },
54-
];
54+
const ec2Filters = constructFilters(filters);
55+
const runners: RunnerList[] = [];
56+
for (const filter of ec2Filters) {
57+
runners.push(...(await getRunners(filter)));
58+
}
59+
return runners;
60+
}
5561

62+
function constructFilters(filters?: ListRunnerFilters): Ec2Filter[][] {
63+
const ec2Statuses = filters?.statuses ? filters.statuses : ['running', 'pending'];
64+
const ec2Filters: Ec2Filter[][] = [];
65+
const ec2FiltersBase = [{ Name: 'instance-state-name', Values: ec2Statuses }];
5666
if (filters) {
5767
if (filters.environment !== undefined) {
58-
ec2Filters.push({ Name: 'tag:ghr:environment', Values: [filters.environment] });
68+
ec2FiltersBase.push({ Name: 'tag:ghr:environment', Values: [filters.environment] });
5969
}
6070
if (filters.runnerType && filters.runnerOwner) {
61-
ec2Filters.push({ Name: `tag:Type`, Values: [filters.runnerType] });
62-
ec2Filters.push({ Name: `tag:Owner`, Values: [filters.runnerOwner] });
71+
ec2FiltersBase.push({ Name: `tag:Type`, Values: [filters.runnerType] });
72+
ec2FiltersBase.push({ Name: `tag:Owner`, Values: [filters.runnerOwner] });
6373
}
6474
}
6575

76+
// ***Deprecation Notice***
77+
// Support for legacy `Application` tag keys
78+
// will be removed in next major release.
79+
for (const key of ['tag:ghr:Application', 'tag:Application']) {
80+
const filter = [...ec2FiltersBase];
81+
filter.push({ Name: key, Values: ['github-action-runner'] });
82+
ec2Filters.push(filter);
83+
}
84+
return ec2Filters;
85+
}
86+
87+
async function getRunners(ec2Filters: Ec2Filter[]): Promise<RunnerList[]> {
88+
const ec2 = new EC2();
6689
const runners: RunnerList[] = [];
6790
let nextToken;
6891
let hasNext = true;
@@ -191,7 +214,7 @@ export async function createRunner(runnerParameters: RunnerInputParameters): Pro
191214
{
192215
ResourceType: 'instance',
193216
Tags: [
194-
{ Key: 'Application', Value: 'github-action-runner' },
217+
{ Key: 'ghr:Application', Value: 'github-action-runner' },
195218
{ Key: 'Type', Value: runnerParameters.runnerType },
196219
{ Key: 'Owner', Value: runnerParameters.runnerOwner },
197220
],

0 commit comments

Comments
 (0)