@cloudsnorkel/cdk-github-runners 0.8.3 → 0.9.0

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 (87) hide show
  1. package/.jsii +2257 -744
  2. package/API.md +2005 -558
  3. package/README.md +32 -34
  4. package/assets/docker-images/codebuild/linux-arm64/Dockerfile +2 -0
  5. package/assets/docker-images/codebuild/linux-x64/Dockerfile +2 -0
  6. package/assets/docker-images/fargate/linux-arm64/Dockerfile +2 -0
  7. package/assets/docker-images/fargate/linux-x64/Dockerfile +2 -0
  8. package/assets/docker-images/lambda/linux-arm64/Dockerfile +3 -1
  9. package/assets/docker-images/lambda/linux-arm64/runner.sh +1 -1
  10. package/assets/docker-images/lambda/linux-x64/Dockerfile +3 -1
  11. package/assets/docker-images/lambda/linux-x64/runner.sh +1 -1
  12. package/assets/lambdas/aws-image-builder-versioner.lambda/index.js +42 -27
  13. package/assets/lambdas/setup.lambda/index.html +12 -12
  14. package/lib/index.js +7 -3
  15. package/lib/lambdas/aws-image-builder-versioner-function.js +2 -2
  16. package/lib/lambdas/aws-image-builder-versioner.lambda.js +43 -27
  17. package/lib/lambdas/build-image-function.js +2 -2
  18. package/lib/lambdas/build-image.lambda.js +4 -4
  19. package/lib/lambdas/delete-ami-function.js +2 -2
  20. package/lib/lambdas/delete-ami.lambda.js +4 -4
  21. package/lib/lambdas/delete-runner-function.js +2 -2
  22. package/lib/lambdas/delete-runner.lambda.js +2 -2
  23. package/lib/lambdas/github.js +3 -3
  24. package/lib/lambdas/setup-function.js +2 -2
  25. package/lib/lambdas/setup.lambda.js +16 -16
  26. package/lib/lambdas/status-function.js +2 -2
  27. package/lib/lambdas/status.lambda.js +5 -5
  28. package/lib/lambdas/token-retriever-function.js +2 -2
  29. package/lib/lambdas/token-retriever.lambda.js +2 -2
  30. package/lib/lambdas/update-lambda-function.js +2 -2
  31. package/lib/lambdas/webhook-handler-function.js +2 -2
  32. package/lib/lambdas/webhook-handler.lambda.js +2 -2
  33. package/lib/providers/codebuild.d.ts +24 -4
  34. package/lib/providers/codebuild.js +43 -13
  35. package/lib/providers/common.d.ts +17 -39
  36. package/lib/providers/common.js +26 -16
  37. package/lib/providers/ec2.d.ts +23 -5
  38. package/lib/providers/ec2.js +43 -12
  39. package/lib/providers/fargate.d.ts +21 -4
  40. package/lib/providers/fargate.js +50 -20
  41. package/lib/providers/image-builders/api.d.ts +15 -0
  42. package/lib/providers/image-builders/api.js +47 -0
  43. package/lib/providers/image-builders/aws-image-builder/ami.d.ts +43 -0
  44. package/lib/providers/image-builders/aws-image-builder/ami.js +81 -0
  45. package/lib/providers/image-builders/aws-image-builder/builder.d.ts +133 -0
  46. package/lib/providers/image-builders/aws-image-builder/builder.js +488 -0
  47. package/lib/providers/image-builders/aws-image-builder/common.d.ts +10 -0
  48. package/lib/providers/image-builders/aws-image-builder/common.js +46 -0
  49. package/lib/providers/image-builders/aws-image-builder/container.d.ts +58 -0
  50. package/lib/providers/image-builders/aws-image-builder/container.js +63 -0
  51. package/lib/providers/image-builders/{ami.d.ts → aws-image-builder/deprecated/ami.d.ts} +8 -4
  52. package/lib/providers/image-builders/aws-image-builder/deprecated/ami.js +239 -0
  53. package/lib/providers/image-builders/aws-image-builder/deprecated/common.d.ts +34 -0
  54. package/lib/providers/image-builders/aws-image-builder/deprecated/common.js +139 -0
  55. package/lib/providers/image-builders/{container.d.ts → aws-image-builder/deprecated/container.d.ts} +8 -4
  56. package/lib/providers/image-builders/aws-image-builder/deprecated/container.js +222 -0
  57. package/lib/providers/image-builders/aws-image-builder/deprecated/index.d.ts +5 -0
  58. package/lib/providers/image-builders/aws-image-builder/deprecated/index.js +22 -0
  59. package/lib/providers/image-builders/{linux-components.d.ts → aws-image-builder/deprecated/linux-components.d.ts} +4 -2
  60. package/lib/providers/image-builders/aws-image-builder/deprecated/linux-components.js +180 -0
  61. package/lib/providers/image-builders/{windows-components.d.ts → aws-image-builder/deprecated/windows-components.d.ts} +4 -2
  62. package/lib/providers/image-builders/aws-image-builder/deprecated/windows-components.js +142 -0
  63. package/lib/providers/image-builders/aws-image-builder/index.d.ts +5 -0
  64. package/lib/providers/image-builders/aws-image-builder/index.js +22 -0
  65. package/lib/providers/image-builders/codebuild-deprecated.d.ts +195 -0
  66. package/lib/providers/image-builders/codebuild-deprecated.js +373 -0
  67. package/lib/providers/image-builders/codebuild.d.ts +26 -157
  68. package/lib/providers/image-builders/codebuild.js +119 -211
  69. package/lib/providers/image-builders/common.d.ts +164 -107
  70. package/lib/providers/image-builders/common.js +30 -272
  71. package/lib/providers/image-builders/components.d.ts +114 -0
  72. package/lib/providers/image-builders/components.js +534 -0
  73. package/lib/providers/image-builders/index.d.ts +6 -4
  74. package/lib/providers/image-builders/index.js +13 -7
  75. package/lib/providers/image-builders/static.d.ts +4 -3
  76. package/lib/providers/image-builders/static.js +10 -10
  77. package/lib/providers/index.js +7 -3
  78. package/lib/providers/lambda.d.ts +25 -6
  79. package/lib/providers/lambda.js +50 -13
  80. package/lib/runner.d.ts +3 -5
  81. package/lib/runner.js +3 -3
  82. package/lib/secrets.js +3 -3
  83. package/package.json +12 -16
  84. package/lib/providers/image-builders/ami.js +0 -280
  85. package/lib/providers/image-builders/container.js +0 -247
  86. package/lib/providers/image-builders/linux-components.js +0 -177
  87. package/lib/providers/image-builders/windows-components.js +0 -139
@@ -1,7 +1,9 @@
1
- import * as cdk from 'aws-cdk-lib';
2
- import { aws_ec2 as ec2, aws_iam as iam, aws_imagebuilder as imagebuilder, aws_logs as logs, aws_s3_assets as s3_assets, Duration, RemovalPolicy } from 'aws-cdk-lib';
1
+ import { aws_ec2 as ec2, aws_iam as iam, aws_logs as logs, Duration, RemovalPolicy } from 'aws-cdk-lib';
3
2
  import { Construct } from 'constructs';
4
- import { Architecture, Os, RunnerVersion } from '../common';
3
+ import { AwsImageBuilderRunnerImageBuilderProps } from './aws-image-builder';
4
+ import { CodeBuildRunnerImageBuilderProps } from './codebuild';
5
+ import { RunnerImageComponent } from './components';
6
+ import { Architecture, Os, RunnerAmi, RunnerImage, RunnerVersion } from '../common';
5
7
  /**
6
8
  * @internal
7
9
  */
@@ -9,100 +11,106 @@ export declare function uniqueImageBuilderName(scope: Construct): string;
9
11
  /**
10
12
  * @internal
11
13
  */
12
- export declare abstract class ImageBuilderObjectBase extends cdk.Resource {
13
- protected constructor(scope: Construct, id: string);
14
- protected version(type: 'Component' | 'ImageRecipe' | 'ContainerRecipe', name: string, data: any): string;
15
- private versionFunction;
16
- }
17
- /**
18
- * An asset including file or directory to place inside the built image.
19
- */
20
- export interface ImageBuilderAsset {
14
+ export interface ImageBuilderBaseProps {
21
15
  /**
22
- * Path to place asset in the image.
16
+ * Image architecture.
17
+ *
18
+ * @default Architecture.X86_64
23
19
  */
24
- readonly path: string;
20
+ readonly architecture?: Architecture;
25
21
  /**
26
- * Asset to place in the image.
22
+ * List of supported architectures to be checked against {@link architecture}.
27
23
  */
28
- readonly asset: s3_assets.Asset;
29
- }
30
- /**
31
- * Properties for ImageBuilderComponent construct.
32
- */
33
- export interface ImageBuilderComponentProperties {
24
+ readonly supportedArchitectures: Architecture[];
34
25
  /**
35
- * Component platform. Must match the builder platform.
26
+ * Image OS.
27
+ *
28
+ * @default OS.LINUX
36
29
  */
37
- readonly platform: 'Linux' | 'Windows';
30
+ readonly os?: Os;
38
31
  /**
39
- * Component display name.
32
+ * List of supported OS to be checked against {@link os}.
40
33
  */
41
- readonly displayName: string;
34
+ readonly supportedOs: Os[];
42
35
  /**
43
- * Component description.
36
+ * Version of GitHub Runners to install.
37
+ *
38
+ * @default latest version available
44
39
  */
45
- readonly description: string;
40
+ readonly runnerVersion?: RunnerVersion;
46
41
  /**
47
- * Shell commands to run when adding this component to the image.
42
+ * Schedule the AMI to be rebuilt every given interval. Useful for keeping the AMI up-do-date with the latest GitHub runner version and latest OS updates.
43
+ *
44
+ * Set to zero to disable.
48
45
  *
49
- * On Linux, these are bash commands. On Windows, there are PowerShell commands.
46
+ * @default Duration.days(7)
50
47
  */
51
- readonly commands: string[];
48
+ readonly rebuildInterval?: Duration;
52
49
  /**
53
- * Optional assets to add to the built image.
50
+ * VPC where builder instances will be launched.
51
+ *
52
+ * @default default account VPC
54
53
  */
55
- readonly assets?: ImageBuilderAsset[];
56
- }
57
- /**
58
- * Components are a set of commands to run and optional files to add to an image. Components are the building blocks of images built by Image Builder.
59
- *
60
- * Example:
61
- *
62
- * ```
63
- * new ImageBuilderComponent(this, 'AWS CLI', {
64
- * platform: 'Windows',
65
- * displayName: 'AWS CLI',
66
- * description: 'Install latest version of AWS CLI',
67
- * commands: [
68
- * '$ErrorActionPreference = \'Stop\'',
69
- * 'Start-Process msiexec.exe -Wait -ArgumentList \'/i https://awscli.amazonaws.com/AWSCLIV2.msi /qn\'',
70
- * ],
71
- * }
72
- * ```
73
- */
74
- export declare class ImageBuilderComponent extends ImageBuilderObjectBase {
54
+ readonly vpc?: ec2.IVpc;
75
55
  /**
76
- * Component ARN.
56
+ * Security groups to assign to launched builder instances.
57
+ *
58
+ * @default new security group
77
59
  */
78
- readonly arn: string;
60
+ readonly securityGroups?: ec2.ISecurityGroup[];
79
61
  /**
80
- * Supported platform for the component.
62
+ * Where to place the network interfaces within the VPC.
63
+ *
64
+ * @default default VPC subnet
81
65
  */
82
- readonly platform: 'Windows' | 'Linux';
83
- private readonly assets;
84
- constructor(scope: Construct, id: string, props: ImageBuilderComponentProperties);
66
+ readonly subnetSelection?: ec2.SubnetSelection;
85
67
  /**
86
- * Grants read permissions to the principal on the assets buckets.
68
+ * The instance type used to build the image.
87
69
  *
88
- * @param grantee
70
+ * @default m5.large
71
+ */
72
+ readonly instanceType?: ec2.InstanceType;
73
+ /**
74
+ * The number of days log events are kept in CloudWatch Logs. When updating
75
+ * this property, unsetting it doesn't remove the log retention policy. To
76
+ * remove the retention policy, set the value to `INFINITE`.
77
+ *
78
+ * @default logs.RetentionDays.ONE_MONTH
79
+ */
80
+ readonly logRetention?: logs.RetentionDays;
81
+ /**
82
+ * Removal policy for logs of image builds. If deployment fails on the custom resource, try setting this to `RemovalPolicy.RETAIN`. This way the logs can still be viewed, and you can see why the build failed.
83
+ *
84
+ * We try to not leave anything behind when removed. But sometimes a log staying behind is useful.
85
+ *
86
+ * @default RemovalPolicy.DESTROY
87
+ */
88
+ readonly logRemovalPolicy?: RemovalPolicy;
89
+ /**
90
+ * Pipeline and infrastructure description.
89
91
  */
90
- grantAssetsRead(grantee: iam.IGrantable): void;
92
+ readonly imageTypeName: string;
91
93
  }
92
94
  /**
93
- * @internal
95
+ * Asset to copy into a built image.
94
96
  */
95
- export interface ImageBuilderBaseProps {
97
+ export interface RunnerImageAsset {
98
+ /**
99
+ * Path on local system to copy into the image. Can be a file or a directory.
100
+ */
101
+ readonly source: string;
102
+ /**
103
+ * Target path in the built image.
104
+ */
105
+ readonly target: string;
106
+ }
107
+ export interface RunnerImageBuilderProps {
96
108
  /**
97
109
  * Image architecture.
98
110
  *
99
111
  * @default Architecture.X86_64
100
112
  */
101
113
  readonly architecture?: Architecture;
102
- /**
103
- * List of supported architectures to be checked against {@link architecture}.
104
- */
105
- readonly supportedArchitectures: Architecture[];
106
114
  /**
107
115
  * Image OS.
108
116
  *
@@ -110,9 +118,17 @@ export interface ImageBuilderBaseProps {
110
118
  */
111
119
  readonly os?: Os;
112
120
  /**
113
- * List of supported OS to be checked against {@link os}.
121
+ * Base image from which Docker runner images will be built.
122
+ *
123
+ * @default public.ecr.aws/lts/ubuntu:22.04 for Os.LINUX_UBUNTU, public.ecr.aws/amazonlinux/amazonlinux:2 for Os.LINUX_AMAZON_2, mcr.microsoft.com/windows/servercore:ltsc2019-amd64 for Os.WINDOWS
114
124
  */
115
- readonly supportedOs: Os[];
125
+ readonly baseDockerImage?: string;
126
+ /**
127
+ * Base AMI from which runner AMIs will be built.
128
+ *
129
+ * @default latest Ubuntu 20.04 AMI for Os.LINUX_UBUNTU, latest Amazon Linux 2 AMI for Os.LINUX_AMAZON_2, latest Windows Server 2022 AMI for Os.WINDOWS
130
+ */
131
+ readonly baseAmi?: string;
116
132
  /**
117
133
  * Version of GitHub Runners to install.
118
134
  *
@@ -120,7 +136,13 @@ export interface ImageBuilderBaseProps {
120
136
  */
121
137
  readonly runnerVersion?: RunnerVersion;
122
138
  /**
123
- * Schedule the AMI to be rebuilt every given interval. Useful for keeping the AMI up-do-date with the latest GitHub runner version and latest OS updates.
139
+ * Components to install on the image.
140
+ *
141
+ * @default none
142
+ */
143
+ readonly components?: RunnerImageComponent[];
144
+ /**
145
+ * Schedule the image to be rebuilt every given interval. Useful for keeping the image up-do-date with the latest GitHub runner version and latest OS updates.
124
146
  *
125
147
  * Set to zero to disable.
126
148
  *
@@ -128,29 +150,21 @@ export interface ImageBuilderBaseProps {
128
150
  */
129
151
  readonly rebuildInterval?: Duration;
130
152
  /**
131
- * VPC where builder instances will be launched.
153
+ * VPC to build the image in.
132
154
  *
133
- * @default default account VPC
155
+ * @default no VPC
134
156
  */
135
157
  readonly vpc?: ec2.IVpc;
136
158
  /**
137
- * Security groups to assign to launched builder instances.
138
- *
139
- * @default new security group
159
+ * Security Groups to assign to this instance.
140
160
  */
141
161
  readonly securityGroups?: ec2.ISecurityGroup[];
142
162
  /**
143
163
  * Where to place the network interfaces within the VPC.
144
164
  *
145
- * @default default VPC subnet
165
+ * @default no subnet
146
166
  */
147
167
  readonly subnetSelection?: ec2.SubnetSelection;
148
- /**
149
- * The instance type used to build the image.
150
- *
151
- * @default m5.large
152
- */
153
- readonly instanceType?: ec2.InstanceType;
154
168
  /**
155
169
  * The number of days log events are kept in CloudWatch Logs. When updating
156
170
  * this property, unsetting it doesn't remove the log retention policy. To
@@ -160,7 +174,7 @@ export interface ImageBuilderBaseProps {
160
174
  */
161
175
  readonly logRetention?: logs.RetentionDays;
162
176
  /**
163
- * Removal policy for logs of image builds. If deployment fails on the custom resource, try setting this to `RemovalPolicy.RETAIN`. This way the logs can still be viewed, and you can see why the build failed.
177
+ * Removal policy for logs of image builds. If deployment fails on the custom resource, try setting this to `RemovalPolicy.RETAIN`. This way the CodeBuild logs can still be viewed, and you can see why the build failed.
164
178
  *
165
179
  * We try to not leave anything behind when removed. But sometimes a log staying behind is useful.
166
180
  *
@@ -168,34 +182,77 @@ export interface ImageBuilderBaseProps {
168
182
  */
169
183
  readonly logRemovalPolicy?: RemovalPolicy;
170
184
  /**
171
- * Pipeline and infrastructure description.
185
+ * @default CodeBuild for Linux Docker image, AWS Image Builder for Windows Docker image and any AMI
172
186
  */
173
- readonly imageTypeName: string;
187
+ readonly builderType?: RunnerImageBuilderType;
188
+ /**
189
+ * Options specific to CodeBuild image builder. Only used when builderType is RunnerImageBuilderType.CODE_BUILD.
190
+ */
191
+ readonly codeBuildOptions?: CodeBuildRunnerImageBuilderProps;
192
+ /**
193
+ * Options specific to AWS Image Builder. Only used when builderType is RunnerImageBuilderType.AWS_IMAGE_BUILDER.
194
+ */
195
+ readonly awsImageBuilderOptions?: AwsImageBuilderRunnerImageBuilderProps;
196
+ }
197
+ export declare enum RunnerImageBuilderType {
198
+ /**
199
+ * Build runner images using AWS CodeBuild.
200
+ *
201
+ * Faster than AWS Image Builder, but can only be used to build Linux Docker images.
202
+ */
203
+ CODE_BUILD = "CodeBuild",
204
+ /**
205
+ * Build runner images using AWS Image Builder.
206
+ *
207
+ * Slower than CodeBuild, but can be used to build any type of image including AMIs and Windows images.
208
+ */
209
+ AWS_IMAGE_BUILDER = "AwsImageBuilder"
210
+ }
211
+ /**
212
+ * Interface for constructs that build an image that can be used in {@link IRunnerProvider}.
213
+ *
214
+ * An image can be a Docker image or AMI.
215
+ */
216
+ export interface IRunnerImageBuilder {
217
+ /**
218
+ * Build and return a Docker image with GitHub Runner installed in it.
219
+ *
220
+ * Anything that ends up with an ECR repository containing a Docker image that runs GitHub self-hosted runners can be used. A simple implementation could even point to an existing image and nothing else.
221
+ *
222
+ * It's important that the specified image tag be available at the time the repository is available. Providers usually assume the image is ready and will fail if it's not.
223
+ *
224
+ * The image can be further updated over time manually or using a schedule as long as it is always written to the same tag.
225
+ */
226
+ bindDockerImage(): RunnerImage;
227
+ /**
228
+ * Build and return an AMI with GitHub Runner installed in it.
229
+ *
230
+ * Anything that ends up with a launch template pointing to an AMI that runs GitHub self-hosted runners can be used. A simple implementation could even point to an existing AMI and nothing else.
231
+ *
232
+ * The AMI can be further updated over time manually or using a schedule as long as it is always written to the same launch template.
233
+ */
234
+ bindAmi(): RunnerAmi;
174
235
  }
175
236
  /**
176
237
  * @internal
177
238
  */
178
- export declare abstract class ImageBuilderBase extends Construct implements ec2.IConnectable {
179
- protected readonly architecture: Architecture;
180
- protected readonly os: Os;
181
- protected readonly platform: 'Windows' | 'Linux';
182
- protected readonly description: string;
183
- protected readonly runnerVersion: RunnerVersion;
184
- protected components: ImageBuilderComponent[];
185
- private readonly vpc;
186
- private readonly subnetId;
187
- private readonly securityGroups;
188
- private readonly instanceType;
189
- private readonly rebuildInterval;
190
- private readonly logRetention;
191
- private readonly logRemovalPolicy;
192
- protected constructor(scope: Construct, id: string, props: ImageBuilderBaseProps);
193
- protected createLog(recipeName: string): logs.LogGroup;
194
- protected createInfrastructure(managedPolicies: iam.IManagedPolicy[]): imagebuilder.CfnInfrastructureConfiguration;
195
- protected createImage(infra: imagebuilder.CfnInfrastructureConfiguration, dist: imagebuilder.CfnDistributionConfiguration, log: logs.LogGroup, imageRecipeArn?: string, containerRecipeArn?: string): imagebuilder.CfnImage;
196
- protected createPipeline(infra: imagebuilder.CfnInfrastructureConfiguration, dist: imagebuilder.CfnDistributionConfiguration, log: logs.LogGroup, imageRecipeArn?: string, containerRecipeArn?: string): imagebuilder.CfnImagePipeline;
197
- /**
198
- * The network connections associated with this resource.
199
- */
200
- get connections(): ec2.Connections;
239
+ export declare abstract class RunnerImageBuilderBase extends Construct implements ec2.IConnectable, iam.IGrantable, IRunnerImageBuilder {
240
+ protected components: RunnerImageComponent[];
241
+ protected constructor(scope: Construct, id: string, props?: RunnerImageBuilderProps);
242
+ abstract bindDockerImage(): RunnerImage;
243
+ abstract bindAmi(): RunnerAmi;
244
+ abstract get connections(): ec2.Connections;
245
+ abstract get grantPrincipal(): iam.IPrincipal;
246
+ /**
247
+ * Add a component to the image builder. The component will be added to the end of the list of components.
248
+ *
249
+ * @param component component to add
250
+ */
251
+ addComponent(component: RunnerImageComponent): void;
252
+ /**
253
+ * Remove a component from the image builder. Removal is done by component name. Multiple components with the same name will all be removed.
254
+ *
255
+ * @param component component to remove
256
+ */
257
+ removeComponent(component: RunnerImageComponent): void;
201
258
  }