@cloudsnorkel/cdk-github-runners 0.14.9 → 0.14.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/.jsii +35 -35
  2. package/assets/delete-failed-runner.lambda/index.js +18 -12
  3. package/assets/idle-runner-repear.lambda/index.js +32 -20
  4. package/assets/setup.lambda/index.html +7 -7
  5. package/assets/token-retriever.lambda/index.js +18 -12
  6. package/assets/webhook-handler.lambda/index.js +22 -16
  7. package/assets/webhook-redelivery.lambda/index.js +13401 -0
  8. package/lib/access.js +1 -1
  9. package/lib/idle-runner-repear.lambda.js +19 -11
  10. package/lib/image-builders/api.js +1 -1
  11. package/lib/image-builders/aws-image-builder/builder.js +1 -1
  12. package/lib/image-builders/aws-image-builder/deprecated/ami.js +1 -1
  13. package/lib/image-builders/aws-image-builder/deprecated/container.js +1 -1
  14. package/lib/image-builders/aws-image-builder/deprecated/linux-components.js +1 -1
  15. package/lib/image-builders/aws-image-builder/deprecated/windows-components.js +1 -1
  16. package/lib/image-builders/codebuild-deprecated.js +1 -1
  17. package/lib/image-builders/components.js +1 -1
  18. package/lib/image-builders/static.js +1 -1
  19. package/lib/lambda-github.d.ts +4 -0
  20. package/lib/lambda-github.js +57 -16
  21. package/lib/lambda-helpers.js +1 -1
  22. package/lib/providers/codebuild.js +2 -2
  23. package/lib/providers/common.js +3 -3
  24. package/lib/providers/ec2.js +2 -2
  25. package/lib/providers/ecs.js +1 -1
  26. package/lib/providers/fargate.js +2 -2
  27. package/lib/providers/lambda.js +2 -2
  28. package/lib/runner.d.ts +1 -0
  29. package/lib/runner.js +19 -2
  30. package/lib/secrets.js +1 -1
  31. package/lib/webhook-handler.lambda.d.ts +1 -1
  32. package/lib/webhook-handler.lambda.js +5 -5
  33. package/lib/webhook-redelivery-function.d.ts +13 -0
  34. package/lib/webhook-redelivery-function.js +23 -0
  35. package/lib/webhook-redelivery.d.ts +26 -0
  36. package/lib/webhook-redelivery.js +43 -0
  37. package/lib/webhook-redelivery.lambda.d.ts +9 -0
  38. package/lib/webhook-redelivery.lambda.js +149 -0
  39. package/package.json +16 -14
package/.jsii CHANGED
@@ -3834,7 +3834,7 @@
3834
3834
  "stability": "experimental"
3835
3835
  },
3836
3836
  "homepage": "https://github.com/CloudSnorkel/cdk-github-runners.git",
3837
- "jsiiVersion": "5.8.13 (build 2043962)",
3837
+ "jsiiVersion": "5.8.15 (build af1b019)",
3838
3838
  "keywords": [
3839
3839
  "aws",
3840
3840
  "aws-cdk",
@@ -9058,7 +9058,7 @@
9058
9058
  },
9059
9059
  "locationInModule": {
9060
9060
  "filename": "src/runner.ts",
9061
- "line": 270
9061
+ "line": 272
9062
9062
  },
9063
9063
  "parameters": [
9064
9064
  {
@@ -9088,7 +9088,7 @@
9088
9088
  "kind": "class",
9089
9089
  "locationInModule": {
9090
9090
  "filename": "src/runner.ts",
9091
- "line": 244
9091
+ "line": 245
9092
9092
  },
9093
9093
  "methods": [
9094
9094
  {
@@ -9099,7 +9099,7 @@
9099
9099
  },
9100
9100
  "locationInModule": {
9101
9101
  "filename": "src/runner.ts",
9102
- "line": 787
9102
+ "line": 793
9103
9103
  },
9104
9104
  "name": "createLogsInsightsQueries"
9105
9105
  },
@@ -9111,7 +9111,7 @@
9111
9111
  },
9112
9112
  "locationInModule": {
9113
9113
  "filename": "src/runner.ts",
9114
- "line": 767
9114
+ "line": 773
9115
9115
  },
9116
9116
  "name": "failedImageBuildsTopic",
9117
9117
  "returns": {
@@ -9128,7 +9128,7 @@
9128
9128
  },
9129
9129
  "locationInModule": {
9130
9130
  "filename": "src/runner.ts",
9131
- "line": 749
9131
+ "line": 755
9132
9132
  },
9133
9133
  "name": "metricFailed",
9134
9134
  "parameters": [
@@ -9154,7 +9154,7 @@
9154
9154
  },
9155
9155
  "locationInModule": {
9156
9156
  "filename": "src/runner.ts",
9157
- "line": 694
9157
+ "line": 700
9158
9158
  },
9159
9159
  "name": "metricJobCompleted",
9160
9160
  "parameters": [
@@ -9180,7 +9180,7 @@
9180
9180
  },
9181
9181
  "locationInModule": {
9182
9182
  "filename": "src/runner.ts",
9183
- "line": 740
9183
+ "line": 746
9184
9184
  },
9185
9185
  "name": "metricSucceeded",
9186
9186
  "parameters": [
@@ -9206,7 +9206,7 @@
9206
9206
  },
9207
9207
  "locationInModule": {
9208
9208
  "filename": "src/runner.ts",
9209
- "line": 756
9209
+ "line": 762
9210
9210
  },
9211
9211
  "name": "metricTime",
9212
9212
  "parameters": [
@@ -9236,7 +9236,7 @@
9236
9236
  "immutable": true,
9237
9237
  "locationInModule": {
9238
9238
  "filename": "src/runner.ts",
9239
- "line": 260
9239
+ "line": 261
9240
9240
  },
9241
9241
  "name": "connections",
9242
9242
  "overrides": "aws-cdk-lib.aws_ec2.IConnectable",
@@ -9252,7 +9252,7 @@
9252
9252
  "immutable": true,
9253
9253
  "locationInModule": {
9254
9254
  "filename": "src/runner.ts",
9255
- "line": 248
9255
+ "line": 249
9256
9256
  },
9257
9257
  "name": "providers",
9258
9258
  "type": {
@@ -9272,7 +9272,7 @@
9272
9272
  "immutable": true,
9273
9273
  "locationInModule": {
9274
9274
  "filename": "src/runner.ts",
9275
- "line": 253
9275
+ "line": 254
9276
9276
  },
9277
9277
  "name": "secrets",
9278
9278
  "type": {
@@ -9286,7 +9286,7 @@
9286
9286
  "immutable": true,
9287
9287
  "locationInModule": {
9288
9288
  "filename": "src/runner.ts",
9289
- "line": 270
9289
+ "line": 272
9290
9290
  },
9291
9291
  "name": "props",
9292
9292
  "optional": true,
@@ -9308,7 +9308,7 @@
9308
9308
  "kind": "interface",
9309
9309
  "locationInModule": {
9310
9310
  "filename": "src/runner.ts",
9311
- "line": 39
9311
+ "line": 40
9312
9312
  },
9313
9313
  "name": "GitHubRunnersProps",
9314
9314
  "properties": [
@@ -9323,7 +9323,7 @@
9323
9323
  "immutable": true,
9324
9324
  "locationInModule": {
9325
9325
  "filename": "src/runner.ts",
9326
- "line": 80
9326
+ "line": 81
9327
9327
  },
9328
9328
  "name": "allowPublicSubnet",
9329
9329
  "optional": true,
@@ -9341,7 +9341,7 @@
9341
9341
  "immutable": true,
9342
9342
  "locationInModule": {
9343
9343
  "filename": "src/runner.ts",
9344
- "line": 117
9344
+ "line": 118
9345
9345
  },
9346
9346
  "name": "extraCertificates",
9347
9347
  "optional": true,
@@ -9360,7 +9360,7 @@
9360
9360
  "immutable": true,
9361
9361
  "locationInModule": {
9362
9362
  "filename": "src/runner.ts",
9363
- "line": 124
9363
+ "line": 125
9364
9364
  },
9365
9365
  "name": "idleTimeout",
9366
9366
  "optional": true,
@@ -9378,7 +9378,7 @@
9378
9378
  "immutable": true,
9379
9379
  "locationInModule": {
9380
9380
  "filename": "src/runner.ts",
9381
- "line": 131
9381
+ "line": 132
9382
9382
  },
9383
9383
  "name": "logOptions",
9384
9384
  "optional": true,
@@ -9397,7 +9397,7 @@
9397
9397
  "immutable": true,
9398
9398
  "locationInModule": {
9399
9399
  "filename": "src/runner.ts",
9400
- "line": 45
9400
+ "line": 46
9401
9401
  },
9402
9402
  "name": "providers",
9403
9403
  "optional": true,
@@ -9421,7 +9421,7 @@
9421
9421
  "immutable": true,
9422
9422
  "locationInModule": {
9423
9423
  "filename": "src/runner.ts",
9424
- "line": 54
9424
+ "line": 55
9425
9425
  },
9426
9426
  "name": "requireSelfHostedLabel",
9427
9427
  "optional": true,
@@ -9440,7 +9440,7 @@
9440
9440
  "immutable": true,
9441
9441
  "locationInModule": {
9442
9442
  "filename": "src/runner.ts",
9443
- "line": 168
9443
+ "line": 169
9444
9444
  },
9445
9445
  "name": "retryOptions",
9446
9446
  "optional": true,
@@ -9459,7 +9459,7 @@
9459
9459
  "immutable": true,
9460
9460
  "locationInModule": {
9461
9461
  "filename": "src/runner.ts",
9462
- "line": 87
9462
+ "line": 88
9463
9463
  },
9464
9464
  "name": "securityGroup",
9465
9465
  "optional": true,
@@ -9477,7 +9477,7 @@
9477
9477
  "immutable": true,
9478
9478
  "locationInModule": {
9479
9479
  "filename": "src/runner.ts",
9480
- "line": 92
9480
+ "line": 93
9481
9481
  },
9482
9482
  "name": "securityGroups",
9483
9483
  "optional": true,
@@ -9501,7 +9501,7 @@
9501
9501
  "immutable": true,
9502
9502
  "locationInModule": {
9503
9503
  "filename": "src/runner.ts",
9504
- "line": 138
9504
+ "line": 139
9505
9505
  },
9506
9506
  "name": "setupAccess",
9507
9507
  "optional": true,
@@ -9520,7 +9520,7 @@
9520
9520
  "immutable": true,
9521
9521
  "locationInModule": {
9522
9522
  "filename": "src/runner.ts",
9523
- "line": 157
9523
+ "line": 158
9524
9524
  },
9525
9525
  "name": "statusAccess",
9526
9526
  "optional": true,
@@ -9538,7 +9538,7 @@
9538
9538
  "immutable": true,
9539
9539
  "locationInModule": {
9540
9540
  "filename": "src/runner.ts",
9541
- "line": 68
9541
+ "line": 69
9542
9542
  },
9543
9543
  "name": "vpc",
9544
9544
  "optional": true,
@@ -9556,7 +9556,7 @@
9556
9556
  "immutable": true,
9557
9557
  "locationInModule": {
9558
9558
  "filename": "src/runner.ts",
9559
- "line": 73
9559
+ "line": 74
9560
9560
  },
9561
9561
  "name": "vpcSubnets",
9562
9562
  "optional": true,
@@ -9575,7 +9575,7 @@
9575
9575
  "immutable": true,
9576
9576
  "locationInModule": {
9577
9577
  "filename": "src/runner.ts",
9578
- "line": 150
9578
+ "line": 151
9579
9579
  },
9580
9580
  "name": "webhookAccess",
9581
9581
  "optional": true,
@@ -11645,7 +11645,7 @@
11645
11645
  "kind": "interface",
11646
11646
  "locationInModule": {
11647
11647
  "filename": "src/runner.ts",
11648
- "line": 174
11648
+ "line": 175
11649
11649
  },
11650
11650
  "name": "LogOptions",
11651
11651
  "properties": [
@@ -11659,7 +11659,7 @@
11659
11659
  "immutable": true,
11660
11660
  "locationInModule": {
11661
11661
  "filename": "src/runner.ts",
11662
- "line": 185
11662
+ "line": 186
11663
11663
  },
11664
11664
  "name": "includeExecutionData",
11665
11665
  "optional": true,
@@ -11677,7 +11677,7 @@
11677
11677
  "immutable": true,
11678
11678
  "locationInModule": {
11679
11679
  "filename": "src/runner.ts",
11680
- "line": 192
11680
+ "line": 193
11681
11681
  },
11682
11682
  "name": "level",
11683
11683
  "optional": true,
@@ -11694,7 +11694,7 @@
11694
11694
  "immutable": true,
11695
11695
  "locationInModule": {
11696
11696
  "filename": "src/runner.ts",
11697
- "line": 178
11697
+ "line": 179
11698
11698
  },
11699
11699
  "name": "logGroupName",
11700
11700
  "optional": true,
@@ -11713,7 +11713,7 @@
11713
11713
  "immutable": true,
11714
11714
  "locationInModule": {
11715
11715
  "filename": "src/runner.ts",
11716
- "line": 201
11716
+ "line": 202
11717
11717
  },
11718
11718
  "name": "logRetention",
11719
11719
  "optional": true,
@@ -14310,6 +14310,6 @@
14310
14310
  "symbolId": "src/image-builders/aws-image-builder/deprecated/windows-components:WindowsComponents"
14311
14311
  }
14312
14312
  },
14313
- "version": "0.14.9",
14314
- "fingerprint": "VyMDMYlRN7iPG1XXNQpOV9RjxOJciYeli5ro3vm5Dj4="
14313
+ "version": "0.14.11",
14314
+ "fingerprint": "pPb2DkhlcCfnSgM5rfNKmErW9ttbyZayQH4/SKTZizI="
14315
14315
  }
@@ -13200,6 +13200,7 @@ __export(delete_failed_runner_lambda_exports, {
13200
13200
  module.exports = __toCommonJS(delete_failed_runner_lambda_exports);
13201
13201
 
13202
13202
  // src/lambda-github.ts
13203
+ var import_crypto = require("crypto");
13203
13204
  var import_auth_app = __toESM(require_dist_node12());
13204
13205
  var import_rest = __toESM(require_dist_node19());
13205
13206
 
@@ -13227,26 +13228,33 @@ function baseUrlFromDomain(domain) {
13227
13228
  }
13228
13229
  return `https://${domain}/api/v3`;
13229
13230
  }
13230
- var octokitCache = {};
13231
+ var octokitCache = /* @__PURE__ */ new Map();
13231
13232
  async function getOctokit(installationId) {
13232
13233
  if (!process.env.GITHUB_SECRET_ARN || !process.env.GITHUB_PRIVATE_KEY_SECRET_ARN) {
13233
13234
  throw new Error("Missing environment variables");
13234
13235
  }
13235
13236
  const githubSecrets = await getSecretJsonValue(process.env.GITHUB_SECRET_ARN);
13236
- if (octokitCache.octokit && octokitCache.installationId == installationId && octokitCache.secrets && octokitCache.secrets.domain == githubSecrets.domain && octokitCache.secrets.appId == githubSecrets.appId && octokitCache.secrets.personalAuthToken == githubSecrets.personalAuthToken) {
13237
+ const cacheKey = (0, import_crypto.createHash)("sha256").update(`${installationId || "no-install"}-${githubSecrets.domain}-${githubSecrets.appId}-${githubSecrets.personalAuthToken}`).digest("hex");
13238
+ const cached = octokitCache.get(cacheKey);
13239
+ if (cached) {
13237
13240
  try {
13238
- await octokitCache.octokit.rest.meta.getOctocat();
13239
- console.log("Using cached octokit");
13241
+ await cached.rest.meta.getOctocat();
13242
+ console.log({
13243
+ notice: "Using cached octokit"
13244
+ });
13240
13245
  return {
13241
- octokit: octokitCache.octokit,
13242
- githubSecrets: octokitCache.secrets
13246
+ octokit: cached,
13247
+ githubSecrets
13243
13248
  };
13244
13249
  } catch (e) {
13245
- console.log("Octokit cache is invalid", e);
13246
- octokitCache.octokit = void 0;
13250
+ console.log({
13251
+ notice: "Octokit cache is invalid",
13252
+ error: e
13253
+ });
13254
+ octokitCache.delete(cacheKey);
13247
13255
  }
13248
13256
  }
13249
- let baseUrl = baseUrlFromDomain(githubSecrets.domain);
13257
+ const baseUrl = baseUrlFromDomain(githubSecrets.domain);
13250
13258
  let token;
13251
13259
  if (githubSecrets.personalAuthToken) {
13252
13260
  token = githubSecrets.personalAuthToken;
@@ -13269,9 +13277,7 @@ async function getOctokit(installationId) {
13269
13277
  baseUrl,
13270
13278
  auth: token
13271
13279
  });
13272
- octokitCache.octokit = octokit;
13273
- octokitCache.installationId = installationId;
13274
- octokitCache.secrets = githubSecrets;
13280
+ octokitCache.set(cacheKey, octokit);
13275
13281
  return {
13276
13282
  octokit,
13277
13283
  githubSecrets
@@ -13201,6 +13201,7 @@ module.exports = __toCommonJS(idle_runner_repear_lambda_exports);
13201
13201
  var import_client_sfn = require("@aws-sdk/client-sfn");
13202
13202
 
13203
13203
  // src/lambda-github.ts
13204
+ var import_crypto = require("crypto");
13204
13205
  var import_auth_app = __toESM(require_dist_node12());
13205
13206
  var import_rest = __toESM(require_dist_node19());
13206
13207
 
@@ -13228,26 +13229,33 @@ function baseUrlFromDomain(domain) {
13228
13229
  }
13229
13230
  return `https://${domain}/api/v3`;
13230
13231
  }
13231
- var octokitCache = {};
13232
+ var octokitCache = /* @__PURE__ */ new Map();
13232
13233
  async function getOctokit(installationId) {
13233
13234
  if (!process.env.GITHUB_SECRET_ARN || !process.env.GITHUB_PRIVATE_KEY_SECRET_ARN) {
13234
13235
  throw new Error("Missing environment variables");
13235
13236
  }
13236
13237
  const githubSecrets = await getSecretJsonValue(process.env.GITHUB_SECRET_ARN);
13237
- if (octokitCache.octokit && octokitCache.installationId == installationId && octokitCache.secrets && octokitCache.secrets.domain == githubSecrets.domain && octokitCache.secrets.appId == githubSecrets.appId && octokitCache.secrets.personalAuthToken == githubSecrets.personalAuthToken) {
13238
+ const cacheKey = (0, import_crypto.createHash)("sha256").update(`${installationId || "no-install"}-${githubSecrets.domain}-${githubSecrets.appId}-${githubSecrets.personalAuthToken}`).digest("hex");
13239
+ const cached = octokitCache.get(cacheKey);
13240
+ if (cached) {
13238
13241
  try {
13239
- await octokitCache.octokit.rest.meta.getOctocat();
13240
- console.log("Using cached octokit");
13242
+ await cached.rest.meta.getOctocat();
13243
+ console.log({
13244
+ notice: "Using cached octokit"
13245
+ });
13241
13246
  return {
13242
- octokit: octokitCache.octokit,
13243
- githubSecrets: octokitCache.secrets
13247
+ octokit: cached,
13248
+ githubSecrets
13244
13249
  };
13245
13250
  } catch (e) {
13246
- console.log("Octokit cache is invalid", e);
13247
- octokitCache.octokit = void 0;
13251
+ console.log({
13252
+ notice: "Octokit cache is invalid",
13253
+ error: e
13254
+ });
13255
+ octokitCache.delete(cacheKey);
13248
13256
  }
13249
13257
  }
13250
- let baseUrl = baseUrlFromDomain(githubSecrets.domain);
13258
+ const baseUrl = baseUrlFromDomain(githubSecrets.domain);
13251
13259
  let token;
13252
13260
  if (githubSecrets.personalAuthToken) {
13253
13261
  token = githubSecrets.personalAuthToken;
@@ -13270,9 +13278,7 @@ async function getOctokit(installationId) {
13270
13278
  baseUrl,
13271
13279
  auth: token
13272
13280
  });
13273
- octokitCache.octokit = octokit;
13274
- octokitCache.installationId = installationId;
13275
- octokitCache.secrets = githubSecrets;
13281
+ octokitCache.set(cacheKey, octokit);
13276
13282
  return {
13277
13283
  octokit,
13278
13284
  githubSecrets
@@ -13324,8 +13330,7 @@ async function deleteRunner(octokit, runnerLevel, owner, repo, runnerId) {
13324
13330
  var sfn = new import_client_sfn.SFNClient();
13325
13331
  async function handler(event) {
13326
13332
  const result = { batchItemFailures: [] };
13327
- let octokitCache2;
13328
- let runnerLevel;
13333
+ const octokitCache2 = /* @__PURE__ */ new Map();
13329
13334
  for (const record of event.Records) {
13330
13335
  const input = JSON.parse(record.body);
13331
13336
  console.log({
@@ -13341,12 +13346,19 @@ async function handler(event) {
13341
13346
  });
13342
13347
  continue;
13343
13348
  }
13344
- if (!octokitCache2) {
13345
- const { octokit, githubSecrets } = await getOctokit(input.installationId);
13346
- octokitCache2 = octokit;
13347
- runnerLevel = githubSecrets.runnerLevel;
13349
+ let octokit;
13350
+ let secrets;
13351
+ const cached = octokitCache2.get(input.installationId);
13352
+ if (cached) {
13353
+ octokit = cached.octokit;
13354
+ secrets = cached.secrets;
13355
+ } else {
13356
+ const { octokit: newOctokit, githubSecrets: newSecrets } = await getOctokit(input.installationId);
13357
+ octokit = newOctokit;
13358
+ secrets = newSecrets;
13359
+ octokitCache2.set(input.installationId, { octokit, secrets });
13348
13360
  }
13349
- const runner = await getRunner(octokitCache2, runnerLevel, input.owner, input.repo, input.runnerName);
13361
+ const runner = await getRunner(octokit, secrets.runnerLevel, input.owner, input.repo, input.runnerName);
13350
13362
  if (!runner) {
13351
13363
  console.log({
13352
13364
  notice: "Runner not running yet",
@@ -13402,7 +13414,7 @@ async function handler(event) {
13402
13414
  notice: `Deleting runner ${runner.id}...`,
13403
13415
  input
13404
13416
  });
13405
- await deleteRunner(octokitCache2, runnerLevel, input.owner, input.repo, runner.id);
13417
+ await deleteRunner(octokit, secrets.runnerLevel, input.owner, input.repo, runner.id);
13406
13418
  } catch (e) {
13407
13419
  console.error({
13408
13420
  notice: `Failed to delete runner ${runner.id}: ${e}`,