cloudsnorkel.cdk-github-runners 0.13.0__tar.gz → 0.14.19__tar.gz

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 (19) hide show
  1. {cloudsnorkel.cdk-github-runners-0.13.0/src/cloudsnorkel.cdk_github_runners.egg-info → cloudsnorkel_cdk_github_runners-0.14.19}/PKG-INFO +271 -17
  2. {cloudsnorkel.cdk-github-runners-0.13.0 → cloudsnorkel_cdk_github_runners-0.14.19}/README.md +263 -13
  3. {cloudsnorkel.cdk-github-runners-0.13.0 → cloudsnorkel_cdk_github_runners-0.14.19}/pyproject.toml +2 -2
  4. {cloudsnorkel.cdk-github-runners-0.13.0 → cloudsnorkel_cdk_github_runners-0.14.19}/setup.py +7 -8
  5. {cloudsnorkel.cdk-github-runners-0.13.0 → cloudsnorkel_cdk_github_runners-0.14.19}/src/cloudsnorkel/cdk_github_runners/__init__.py +3054 -1118
  6. cloudsnorkel_cdk_github_runners-0.14.19/src/cloudsnorkel/cdk_github_runners/_jsii/__init__.py +45 -0
  7. cloudsnorkel_cdk_github_runners-0.14.19/src/cloudsnorkel/cdk_github_runners/_jsii/cdk-github-runners@0.14.19.jsii.tgz +0 -0
  8. {cloudsnorkel.cdk-github-runners-0.13.0 → cloudsnorkel_cdk_github_runners-0.14.19/src/cloudsnorkel.cdk_github_runners.egg-info}/PKG-INFO +271 -17
  9. {cloudsnorkel.cdk-github-runners-0.13.0 → cloudsnorkel_cdk_github_runners-0.14.19}/src/cloudsnorkel.cdk_github_runners.egg-info/SOURCES.txt +1 -1
  10. cloudsnorkel_cdk_github_runners-0.14.19/src/cloudsnorkel.cdk_github_runners.egg-info/requires.txt +5 -0
  11. cloudsnorkel.cdk-github-runners-0.13.0/src/cloudsnorkel/cdk_github_runners/_jsii/__init__.py +0 -30
  12. cloudsnorkel.cdk-github-runners-0.13.0/src/cloudsnorkel/cdk_github_runners/_jsii/cdk-github-runners@0.13.0.jsii.tgz +0 -0
  13. cloudsnorkel.cdk-github-runners-0.13.0/src/cloudsnorkel.cdk_github_runners.egg-info/requires.txt +0 -5
  14. {cloudsnorkel.cdk-github-runners-0.13.0 → cloudsnorkel_cdk_github_runners-0.14.19}/LICENSE +0 -0
  15. {cloudsnorkel.cdk-github-runners-0.13.0 → cloudsnorkel_cdk_github_runners-0.14.19}/MANIFEST.in +0 -0
  16. {cloudsnorkel.cdk-github-runners-0.13.0 → cloudsnorkel_cdk_github_runners-0.14.19}/setup.cfg +0 -0
  17. {cloudsnorkel.cdk-github-runners-0.13.0 → cloudsnorkel_cdk_github_runners-0.14.19}/src/cloudsnorkel/cdk_github_runners/py.typed +0 -0
  18. {cloudsnorkel.cdk-github-runners-0.13.0 → cloudsnorkel_cdk_github_runners-0.14.19}/src/cloudsnorkel.cdk_github_runners.egg-info/dependency_links.txt +0 -0
  19. {cloudsnorkel.cdk-github-runners-0.13.0 → cloudsnorkel_cdk_github_runners-0.14.19}/src/cloudsnorkel.cdk_github_runners.egg-info/top_level.txt +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cloudsnorkel.cdk-github-runners
3
- Version: 0.13.0
4
- Summary: CDK construct to create GitHub Actions self-hosted runners. A webhook listens to events and creates ephemeral runners on the fly.
3
+ Version: 0.14.19
4
+ Summary: CDK construct to create GitHub Actions self-hosted runners. Creates ephemeral runners on demand. Easy to deploy and highly customizable.
5
5
  Home-page: https://github.com/CloudSnorkel/cdk-github-runners.git
6
6
  Author: Amir Szekely<amir@cloudsnorkel.com>
7
7
  License: Apache-2.0
@@ -10,16 +10,20 @@ Classifier: Intended Audience :: Developers
10
10
  Classifier: Operating System :: OS Independent
11
11
  Classifier: Programming Language :: JavaScript
12
12
  Classifier: Programming Language :: Python :: 3 :: Only
13
- Classifier: Programming Language :: Python :: 3.8
14
13
  Classifier: Programming Language :: Python :: 3.9
15
14
  Classifier: Programming Language :: Python :: 3.10
16
15
  Classifier: Programming Language :: Python :: 3.11
17
16
  Classifier: Typing :: Typed
18
17
  Classifier: Development Status :: 4 - Beta
19
18
  Classifier: License :: OSI Approved
20
- Requires-Python: ~=3.8
19
+ Requires-Python: ~=3.9
21
20
  Description-Content-Type: text/markdown
22
21
  License-File: LICENSE
22
+ Requires-Dist: aws-cdk-lib<3.0.0,>=2.155.0
23
+ Requires-Dist: constructs<11.0.0,>=10.0.5
24
+ Requires-Dist: jsii<2.0.0,>=1.124.0
25
+ Requires-Dist: publication>=0.0.3
26
+ Requires-Dist: typeguard==2.13.3
23
27
 
24
28
  # GitHub Self-Hosted Runners CDK Constructs
25
29
 
@@ -33,17 +37,17 @@ License-File: LICENSE
33
37
 
34
38
  Use this CDK construct to create ephemeral [self-hosted GitHub runners](https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners) on-demand inside your AWS account.
35
39
 
36
- * Easy to configure GitHub integration with a web-based interface
37
- * Customizable runners with decent defaults
38
- * Multiple runner configurations controlled by labels
39
- * Everything fully hosted in your account
40
- * Automatically updated build environment with latest runner version
40
+ * 🧩 Easy to configure GitHub integration with a web-based interface
41
+ * 🧠 Customizable runners with decent defaults
42
+ * 🏃🏻 Multiple runner configurations controlled by labels
43
+ * 🔐 Everything fully hosted in your account
44
+ * 🔃 Automatically updated build environment with latest runner version
41
45
 
42
46
  Self-hosted runners in AWS are useful when:
43
47
 
44
48
  * You need easy access to internal resources in your actions
45
49
  * You want to pre-install some software for your actions
46
- * You want to provide some basic AWS API access (but [aws-actions/configure-aws-credentials](https://github.com/marketplace/actions/configure-aws-credentials-for-github-actions) has more security controls)
50
+ * You want to provide some basic AWS API access (but [aws-actions/configure-aws-credentials](https://github.com/marketplace/actions/configure-aws-credentials-action-for-github-actions) has more security controls)
47
51
  * You are using GitHub Enterprise Server
48
52
 
49
53
  Ephemeral (or on-demand) runners are the [recommended way by GitHub](https://docs.github.com/en/actions/hosting-your-own-runners/autoscaling-with-self-hosted-runners#using-ephemeral-runners-for-autoscaling) for auto-scaling, and they make sure all jobs run with a clean image. Runners are started on-demand. You don't pay unless a job is running.
@@ -93,9 +97,14 @@ You can also create your own provider by implementing `IRunnerProvider`.
93
97
  ### Use
94
98
 
95
99
  ```python
100
+ from aws_cdk import App, Stack
96
101
  from cloudsnorkel.cdk_github_runners import GitHubRunners
97
102
 
98
- GitHubRunners(self, "runners")
103
+ app = App()
104
+ stack = Stack(app, "github-runners")
105
+ GitHubRunners(stack, "runners")
106
+
107
+ app.synth()
99
108
  ```
100
109
 
101
110
  </details>
@@ -112,9 +121,14 @@ You can also create your own provider by implementing `IRunnerProvider`.
112
121
  ### Use
113
122
 
114
123
  ```python
124
+ import { App, Stack } from 'aws-cdk-lib';
115
125
  import { GitHubRunners } from '@cloudsnorkel/cdk-github-runners';
116
126
 
117
- new GitHubRunners(this, "runners");
127
+ const app = new App();
128
+ const stack = new Stack(app, 'github-runners');
129
+ new GitHubRunners(stack, 'runners');
130
+
131
+ app.synth();
118
132
  ```
119
133
 
120
134
  </details>
@@ -134,9 +148,19 @@ You can also create your own provider by implementing `IRunnerProvider`.
134
148
  ### Use
135
149
 
136
150
  ```java
151
+ import software.amazon.awscdk.App;
152
+ import software.amazon.awscdk.Stack;
137
153
  import com.cloudsnorkel.cdk.github.runners.GitHubRunners;
138
154
 
139
- GitHubRunners.Builder.create(this, "runners").build();
155
+ public class Example {
156
+ public static void main(String[] args){
157
+ App app = new App();
158
+ Stack stack = new Stack(app, "github-runners");
159
+ GitHubRunners.Builder.create(stack, "runners").build();
160
+
161
+ app.synth();
162
+ }
163
+ }
140
164
  ```
141
165
 
142
166
  </details>
@@ -153,9 +177,21 @@ You can also create your own provider by implementing `IRunnerProvider`.
153
177
  ### Use
154
178
 
155
179
  ```go
156
- import "github.com/CloudSnorkel/cdk-github-runners-go/cloudsnorkelcdkgithubrunners"
180
+ package main
181
+
182
+ import (
183
+ "github.com/CloudSnorkel/cdk-github-runners-go/cloudsnorkelcdkgithubrunners"
184
+ "github.com/aws/aws-cdk-go/awscdk/v2"
185
+ "github.com/aws/jsii-runtime-go"
186
+ )
187
+
188
+ func main() {
189
+ app := awscdk.NewApp(nil)
190
+ stack := awscdk.NewStack(app, jsii.String("github-runners"), &awscdk.StackProps{})
191
+ cloudsnorkelcdkgithubrunners.NewGitHubRunners(stack, jsii.String("runners"), &cloudsnorkelcdkgithubrunners.GitHubRunnersProps{})
157
192
 
158
- NewGitHubRunners(this, jsii.String("runners"))
193
+ app.Synth(nil)
194
+ }
159
195
  ```
160
196
 
161
197
  </details>
@@ -172,9 +208,22 @@ You can also create your own provider by implementing `IRunnerProvider`.
172
208
  ### Use
173
209
 
174
210
  ```csharp
211
+ using Amazon.CDK;
175
212
  using CloudSnorkel;
176
213
 
177
- new GitHubRunners(this, "runners");
214
+ namespace Example
215
+ {
216
+ sealed class Program
217
+ {
218
+ public static void Main(string[] args)
219
+ {
220
+ var app = new App();
221
+ var stack = new Stack(app, "github-runners");
222
+ new GitHubRunners(stack, "runners");
223
+ app.Synth();
224
+ }
225
+ }
226
+ }
178
227
  ```
179
228
 
180
229
  </details>
@@ -193,7 +242,7 @@ You can also create your own provider by implementing `IRunnerProvider`.
193
242
  5. Execute the status command (you may need to specify `--profile` too) and open the resulting `status.json` file
194
243
  6. Open the URL in `github.setup.url` from `status.json` or [manually setup GitHub](SETUP_GITHUB.md) integration as an app or with personal access token
195
244
  7. Run status command again to confirm `github.auth.status` and `github.webhook.status` are OK
196
- 8. Trigger a GitHub action that has a `self-hosted` label with `runs-on: [self-hosted, linux, codebuild]` or similar
245
+ 8. Trigger a GitHub action that has a `self-hosted` label with `runs-on: [self-hosted, codebuild]` (or non-default labels you set in step 2)
197
246
  9. If the action is not successful, see [troubleshooting](#Troubleshooting)
198
247
 
199
248
  [![Demo](demo-thumbnail.jpg)](https://youtu.be/wlyv_3V8lIw)
@@ -301,6 +350,197 @@ new GitHubRunners(this, 'runners', {
301
350
  });
302
351
  ```
303
352
 
353
+ ### Composite Providers
354
+
355
+ Composite providers allow you to combine multiple runner providers with different strategies. There are two types:
356
+
357
+ **Fallback Strategy**: Try providers in order until one succeeds. Useful for trying spot instances first, then falling back to on-demand if spot capacity is unavailable.
358
+
359
+ ```python
360
+ // Try spot instances first, fall back to on-demand if spot is unavailable
361
+ const ecsFallback = CompositeProvider.fallback(this, 'ECS Fallback', [
362
+ new EcsRunnerProvider(this, 'ECS Spot', {
363
+ labels: ['ecs', 'linux', 'x64'],
364
+ spot: true,
365
+ // ... other config
366
+ }),
367
+ new EcsRunnerProvider(this, 'ECS On-Demand', {
368
+ labels: ['ecs', 'linux', 'x64'],
369
+ spot: false,
370
+ // ... other config
371
+ }),
372
+ ]);
373
+
374
+ new GitHubRunners(this, 'runners', {
375
+ providers: [ecsFallback],
376
+ });
377
+ ```
378
+
379
+ **Weighted Distribution Strategy**: Randomly select a provider based on weights. Useful for distributing load across multiple availability zones or instance types.
380
+
381
+ ```python
382
+ // Distribute 60% of traffic to AZ-1, 40% to AZ-2
383
+ const distributedProvider = CompositeProvider.distribute(this, 'Fargate Distribution', [
384
+ {
385
+ weight: 3, // 3/(3+2) = 60%
386
+ provider: new FargateRunnerProvider(this, 'Fargate AZ-1', {
387
+ labels: ['fargate', 'linux', 'x64'],
388
+ subnetSelection: vpc.selectSubnets({
389
+ availabilityZones: [vpc.availabilityZones[0]],
390
+ }),
391
+ // ... other config
392
+ }),
393
+ },
394
+ {
395
+ weight: 2, // 2/(3+2) = 40%
396
+ provider: new FargateRunnerProvider(this, 'Fargate AZ-2', {
397
+ labels: ['fargate', 'linux', 'x64'],
398
+ subnetSelection: vpc.selectSubnets({
399
+ availabilityZones: [vpc.availabilityZones[1]],
400
+ }),
401
+ // ... other config
402
+ }),
403
+ },
404
+ ]);
405
+
406
+ new GitHubRunners(this, 'runners', {
407
+ providers: [distributedProvider],
408
+ });
409
+ ```
410
+
411
+ **Important**: All providers in a composite must have the exact same labels. This ensures any provisioned runner can match the labels requested by the GitHub workflow job.
412
+
413
+ ### Custom Provider Selection
414
+
415
+ By default, providers are selected based on label matching: the first provider that has all the labels requested by the job is selected. You can customize this behavior using a provider selector Lambda function to:
416
+
417
+ * Filter out certain jobs (prevent runner provisioning)
418
+ * Dynamically select a provider based on job characteristics (repository, branch, time of day, etc.)
419
+ * Customize labels for the runner (add, remove, or modify labels dynamically)
420
+
421
+ The selector function receives the full GitHub webhook payload, a map of all available providers and their labels, and the default provider/labels that would have been selected. It returns the provider to use (or `undefined` to skip runner creation) and the labels to assign to the runner.
422
+
423
+ **Example: Route jobs to different providers based on repository**
424
+
425
+ ```python
426
+ import { ComputeType } from 'aws-cdk-lib/aws-codebuild';
427
+ import { Function, Code, Runtime } from 'aws-cdk-lib/aws-lambda';
428
+ import { GitHubRunners, CodeBuildRunnerProvider } from '@cloudsnorkel/cdk-github-runners';
429
+
430
+ const defaultProvider = new CodeBuildRunnerProvider(this, 'default', {
431
+ labels: ['custom-runner', 'default'],
432
+ });
433
+ const productionProvider = new CodeBuildRunnerProvider(this, 'production', {
434
+ labels: ['custom-runner', 'production'],
435
+ computeType: ComputeType.LARGE,
436
+ });
437
+
438
+ const providerSelector = new Function(this, 'provider-selector', {
439
+ runtime: Runtime.NODEJS_LATEST,
440
+ handler: 'index.handler',
441
+ code: Code.fromInline(`
442
+ exports.handler = async (event) => {
443
+ const { payload, providers, defaultProvider, defaultLabels } = event;
444
+
445
+ // Route production repos to dedicated provider
446
+ if (payload.repository.name.includes('prod')) {
447
+ return {
448
+ provider: '${productionProvider.node.path}',
449
+ labels: ['custom-runner', 'production', 'modified-via-selector'],
450
+ };
451
+ }
452
+
453
+ // Filter out draft PRs
454
+ if (payload.workflow_job.head_branch?.startsWith('draft/')) {
455
+ return { provider: undefined }; // Skip runner provisioning
456
+ }
457
+
458
+ // Use default for everything else
459
+ return {
460
+ provider: defaultProvider,
461
+ labels: defaultLabels,
462
+ };
463
+ };
464
+ `),
465
+ });
466
+
467
+ new GitHubRunners(this, 'runners', {
468
+ providers: [defaultProvider, productionProvider],
469
+ providerSelector: providerSelector,
470
+ });
471
+ ```
472
+
473
+ **Example: Add dynamic labels based on job metadata**
474
+
475
+ ```python
476
+ const providerSelector = new Function(this, 'provider-selector', {
477
+ runtime: Runtime.NODEJS_LATEST,
478
+ handler: 'index.handler',
479
+ code: Code.fromInline(`
480
+ exports.handler = async (event) => {
481
+ const { payload, defaultProvider, defaultLabels } = event;
482
+
483
+ // Add branch name as a label
484
+ const branch = payload.workflow_job.head_branch || 'unknown';
485
+ const labels = [...(defaultLabels || []), 'branch:' + branch];
486
+
487
+ return {
488
+ provider: defaultProvider,
489
+ labels: labels,
490
+ };
491
+ };
492
+ `),
493
+ });
494
+ ```
495
+
496
+ **Important considerations:**
497
+
498
+ * ⚠️ **Label matching responsibility**: You are responsible for ensuring the selected provider's labels match what the job requires. If labels don't match, the runner will be provisioned but GitHub Actions won't assign the job to it.
499
+ * ⚠️ **No guarantee of assignment**: Provider selection only determines which provider will provision a runner. GitHub Actions may still route the job to any available runner with matching labels. For reliable provider assignment, consider repo-level runner registration (the default).
500
+ * ⚡ **Performance**: The selector runs synchronously during webhook processing. Keep it fast and efficient—the webhook has a 30-second timeout total.
501
+
502
+ ## Examples
503
+
504
+ We provide comprehensive examples in the [`examples/`](examples/) folder to help you get started quickly:
505
+
506
+ ### Getting Started
507
+
508
+ * **[Simple CodeBuild](examples/typescript/simple-codebuild/)** - Basic setup with just a CodeBuild provider (also available in [Python](examples/python/simple-codebuild/))
509
+
510
+ ### Provider Configuration
511
+
512
+ * **[Composite Provider](examples/typescript/composite-provider/)** - Fallback and weighted distribution strategies (also available in [Python](examples/python/composite-provider/))
513
+ * **[Provider Selector](examples/typescript/provider-selector/)** - Custom provider selection with Lambda function (also available in [Python](examples/python/provider-selector/))
514
+ * **[EC2 Windows Provider](examples/typescript/ec2-windows-provider/)** - EC2 configuration for Windows runners (also available in [Python](examples/python/ec2-windows-provider/))
515
+
516
+ ### Compute & Performance
517
+
518
+ * **[Compute Options](examples/typescript/compute-options/)** - Configure CPU, memory, and instance types for different providers (also available in [Python](examples/python/compute-options/))
519
+ * **[Spot Instances](examples/typescript/spot-instances/)** - Use spot instances for cost savings across EC2, Fargate, and ECS (also available in [Python](examples/python/spot-instances/))
520
+ * **[Storage Options](examples/typescript/storage-options/)** - Custom EBS storage options for EC2 runners (also available in [Python](examples/python/storage-options/))
521
+ * **[ECS Scaling](examples/typescript/ecs-scaling/)** - Custom autoscaling group scaling policies for ECS providers (also available in [Python](examples/python/ecs-scaling/))
522
+
523
+ ### Security & Access
524
+
525
+ * **[IAM Permissions](examples/typescript/iam-permissions/)** - Grant AWS IAM permissions to runners (also available in [Python](examples/python/iam-permissions/))
526
+ * **[Network Access](examples/typescript/network-access/)** - Configure network access with VPCs and security groups (also available in [Python](examples/python/network-access/))
527
+ * **[Access Control](examples/typescript/access-control/)** - Configure access control for webhook and setup functions (also available in [Python](examples/python/access-control/))
528
+
529
+ ### Customization
530
+
531
+ * **[Add Software](examples/typescript/add-software/)** - Add custom software to runner images (also available in [Python](examples/python/add-software/))
532
+
533
+ ### Enterprise & Monitoring
534
+
535
+ * **[GHES](examples/typescript/ghes/)** - Configure runners for GitHub Enterprise Server (also available in [Python](examples/python/ghes/))
536
+ * **[Monitoring](examples/typescript/monitoring/)** - Set up CloudWatch alarms and SNS notifications (also available in [Python](examples/python/monitoring/))
537
+
538
+ Each example is self-contained with its own dependencies and README. Start with the simple examples and work your way up to more advanced configurations.
539
+
540
+ Another good and very full example is the [integration test](test/default.integ.ts).
541
+
542
+ If you have more to share, please open a PR adding examples to the `examples` folder.
543
+
304
544
  ## Architecture
305
545
 
306
546
  ![Architecture diagram](architecture.svg)
@@ -345,6 +585,20 @@ Other useful metrics to track:
345
585
  1. Use `GitHubRunners.metricJobCompleted()` to get a metric for the number of completed jobs broken down by labels and job success.
346
586
  2. Use `GitHubRunners.metricTime()` to get a metric for the total time a runner is running. This includes the overhead of starting the runner.
347
587
 
588
+ ## Contributing
589
+
590
+ If you use and love this project, please consider contributing.
591
+
592
+ 1. 🪳 If you see something, say something. [Issues](https://github.com/CloudSnorkel/cdk-github-runners/issues) help improve the quality of the project.
593
+
594
+ * Include relevant logs and package versions for bugs.
595
+ * When possible, describe the use-case behind feature requests.
596
+ 2. 🛠️ [Pull requests](https://github.com/CloudSnorkel/cdk-github-runners/pulls) are welcome.
597
+
598
+ * Run `npm run build` before submitting to make sure all tests pass.
599
+ * Allow edits from maintainers so small adjustments can be made easily.
600
+ 3. 💵 Consider [sponsoring](https://github.com/sponsors/CloudSnorkel) the project to show your support and optionally get your name listed below.
601
+
348
602
  ## Other Options
349
603
 
350
604
  1. [philips-labs/terraform-aws-github-runner](https://github.com/philips-labs/terraform-aws-github-runner) if you're using Terraform