CodeBuildRunnerProvider Construct
GitHub Actions runner provider using CodeBuild to execute jobs.
Creates a project that gets started for each job.
This construct is not meant to be used by itself. It should be passed in the GitHubRunnersProps.providers property for GitHubRunners.
Implements: IRunnerProvider, IConstruct
Initializer
import { CodeBuildRunnerProvider } from '@cloudsnorkel/cdk-github-runners'
new CodeBuildRunnerProvider(scope: Construct, id: string, props?: CodeBuildRunnerProviderProps)scope:Constructid:stringprops?:CodeBuildRunnerProviderProps
import cloudsnorkel.cdk_github_runners
cloudsnorkel.cdk_github_runners.CodeBuildRunnerProvider(
scope: Construct,
id: str,
default_labels: bool = None,
log_retention: RetentionDays = None,
compute_type: ComputeType = None,
docker_in_docker: bool = None,
gpu: bool = None,
group: str = None,
image_builder: IRunnerImageBuilder = None,
labels: typing.List[str] = None,
security_groups: typing.List[ISecurityGroup] = None,
subnet_selection: SubnetSelection = None,
timeout: Duration = None,
vpc: IVpc = None
)scope:Constructid:strdefault_labels?:boolAdd default labels based on OS and architecture of the runner.
This will tell GitHub Runner to add default labels like
self-hosted,linux,x64, andarm64.Default: true
log_retention?:RetentionDaysThe number of days log events are kept in CloudWatch Logs.
When updating this property, unsetting it doesn't remove the log retention policy. To remove the retention policy, set the value to
INFINITE.Default: logs.RetentionDays.ONE_MONTH
compute_type?:ComputeTypeThe type of compute to use for this build. See the
ComputeTypeenum for the possible values.The compute type determines CPU, memory, and disk space:
- SMALL: 2 vCPU, 3 GB RAM, 64 GB disk
- MEDIUM: 4 vCPU, 7 GB RAM, 128 GB disk
- LARGE: 8 vCPU, 15 GB RAM, 128 GB disk
- X2_LARGE: 72 vCPU, 145 GB RAM, 256 GB disk (Linux) or 824 GB disk (Windows)
Use a larger compute type when you need more disk space for building larger Docker images.
For more details, see https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-compute-types.html#environment.types
Default:
ComputeType#SMALLdocker_in_docker?:boolSupport building and running Docker images by enabling Docker-in-Docker (dind) and the required CodeBuild privileged mode.
Disabling this can speed up provisioning of CodeBuild runners. If you don't intend on running or building Docker images, disable this for faster start-up times.
Default: true
gpu?:boolUse GPU compute for builds.
When enabled, the default compute type is BUILD_GENERAL1_SMALL (4 vCPU, 16 GB RAM, 1 NVIDIA A10G GPU).
You can override the compute type using the
computeTypeproperty (for example, to use BUILD_GENERAL1_LARGE for more resources), subject to the supported GPU compute types.When using GPU compute, ensure your runner image includes any required GPU libraries (for example, CUDA) either by using a base image that has them preinstalled (such as an appropriate nvidia/cuda image) or by adding image components that install them. The default image builder does not automatically switch to a CUDA-enabled base image when GPU is enabled.
GPU compute is only available for Linux x64 images. Not supported on Windows or ARM.
Default: false
group?:strGitHub Actions runner group name.
If specified, the runner will be registered with this group name. Setting a runner group can help managing access to self-hosted runners. It requires a paid GitHub account and organization level runner registration.
The group must exist or the runner will not start.
Users will still be able to trigger this runner with the correct labels. But the runner will only be able to run jobs from repos allowed to use the group.
Default: undefined
image_builder?:IRunnerImageBuilderRunner image builder used to build Docker images containing GitHub Runner and all requirements.
The image builder must contain the
RunnerImageComponent.docker()component unlessdockerInDockeris set to false.The image builder determines the OS and architecture of the runner.
Default: CodeBuildRunnerProvider.imageBuilder()
labels?:typing.List[str]GitHub Actions labels used for this provider.
These labels are used to identify which provider should spawn a new on-demand runner. Every job sends a webhook with the labels it's looking for based on runs-on. We match the labels from the webhook with the labels specified here. If all the labels specified here are present in the job's labels, this provider will be chosen and spawn a new runner.
Default: ['codebuild']
security_groups?:typing.List[ISecurityGroup]Security groups to assign to this instance.
Default: a new security group, if
CodeBuildRunnerProviderProps.vpcis usedsubnet_selection?:SubnetSelectionWhere to place the network interfaces within the VPC.
Default: no subnet
timeout?:DurationThe number of minutes after which AWS CodeBuild stops the build if it's not complete.
For valid values, see the timeoutInMinutes field in the AWS CodeBuild User Guide.
Default: Duration.hours(1)
vpc?:IVpcVPC to launch the runners in.
Default: no VPC
import com.cloudsnorkel.cdk.github.runners.CodeBuildRunnerProvider;
CodeBuildRunnerProvider.Builder.create(Construct scope, java.lang.String id)
// .defaultLabels(java.lang.Boolean)
// .logRetention(RetentionDays)
// .computeType(ComputeType)
// .dockerInDocker(java.lang.Boolean)
// .gpu(java.lang.Boolean)
// .group(java.lang.String)
// .imageBuilder(IRunnerImageBuilder)
// .labels(java.util.List<java.lang.String>)
// .securityGroups(java.util.List<ISecurityGroup>)
// .subnetSelection(SubnetSelection)
// .timeout(Duration)
// .vpc(IVpc)
.build();scope:Constructid:java.lang.StringdefaultLabels?:java.lang.BooleanAdd default labels based on OS and architecture of the runner.
This will tell GitHub Runner to add default labels like
self-hosted,linux,x64, andarm64.Default: true
logRetention?:RetentionDaysThe number of days log events are kept in CloudWatch Logs.
When updating this property, unsetting it doesn't remove the log retention policy. To remove the retention policy, set the value to
INFINITE.Default: logs.RetentionDays.ONE_MONTH
computeType?:ComputeTypeThe type of compute to use for this build. See the
ComputeTypeenum for the possible values.The compute type determines CPU, memory, and disk space:
- SMALL: 2 vCPU, 3 GB RAM, 64 GB disk
- MEDIUM: 4 vCPU, 7 GB RAM, 128 GB disk
- LARGE: 8 vCPU, 15 GB RAM, 128 GB disk
- X2_LARGE: 72 vCPU, 145 GB RAM, 256 GB disk (Linux) or 824 GB disk (Windows)
Use a larger compute type when you need more disk space for building larger Docker images.
For more details, see https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-compute-types.html#environment.types
Default:
ComputeType#SMALLdockerInDocker?:java.lang.BooleanSupport building and running Docker images by enabling Docker-in-Docker (dind) and the required CodeBuild privileged mode.
Disabling this can speed up provisioning of CodeBuild runners. If you don't intend on running or building Docker images, disable this for faster start-up times.
Default: true
gpu?:java.lang.BooleanUse GPU compute for builds.
When enabled, the default compute type is BUILD_GENERAL1_SMALL (4 vCPU, 16 GB RAM, 1 NVIDIA A10G GPU).
You can override the compute type using the
computeTypeproperty (for example, to use BUILD_GENERAL1_LARGE for more resources), subject to the supported GPU compute types.When using GPU compute, ensure your runner image includes any required GPU libraries (for example, CUDA) either by using a base image that has them preinstalled (such as an appropriate nvidia/cuda image) or by adding image components that install them. The default image builder does not automatically switch to a CUDA-enabled base image when GPU is enabled.
GPU compute is only available for Linux x64 images. Not supported on Windows or ARM.
Default: false
group?:java.lang.StringGitHub Actions runner group name.
If specified, the runner will be registered with this group name. Setting a runner group can help managing access to self-hosted runners. It requires a paid GitHub account and organization level runner registration.
The group must exist or the runner will not start.
Users will still be able to trigger this runner with the correct labels. But the runner will only be able to run jobs from repos allowed to use the group.
Default: undefined
imageBuilder?:IRunnerImageBuilderRunner image builder used to build Docker images containing GitHub Runner and all requirements.
The image builder must contain the
RunnerImageComponent.docker()component unlessdockerInDockeris set to false.The image builder determines the OS and architecture of the runner.
Default: CodeBuildRunnerProvider.imageBuilder()
labels?:java.util.List<java.lang.String>GitHub Actions labels used for this provider.
These labels are used to identify which provider should spawn a new on-demand runner. Every job sends a webhook with the labels it's looking for based on runs-on. We match the labels from the webhook with the labels specified here. If all the labels specified here are present in the job's labels, this provider will be chosen and spawn a new runner.
Default: ['codebuild']
securityGroups?:java.util.List<ISecurityGroup>Security groups to assign to this instance.
Default: a new security group, if
CodeBuildRunnerProviderProps.vpcis usedsubnetSelection?:SubnetSelectionWhere to place the network interfaces within the VPC.
Default: no subnet
timeout?:DurationThe number of minutes after which AWS CodeBuild stops the build if it's not complete.
For valid values, see the timeoutInMinutes field in the AWS CodeBuild User Guide.
Default: Duration.hours(1)
vpc?:IVpcVPC to launch the runners in.
Default: no VPC
using CloudSnorkel;
new CodeBuildRunnerProvider(Construct Scope, string Id, CodeBuildRunnerProviderProps Props = null);Scope:ConstructId:stringProps?:CodeBuildRunnerProviderProps
import "github.com/CloudSnorkel/cdk-github-runners-go/cloudsnorkelcdkgithubrunners"
cloudsnorkelcdkgithubrunners.NewCodeBuildRunnerProvider(scope Construct, id *string, props CodeBuildRunnerProviderProps) CodeBuildRunnerProviderscope:Constructid:*stringprops?:CodeBuildRunnerProviderProps
Methods
toString()to_string()toString()ToString()ToString()
Returns a string representation of this construct.
public toString(): stringdef to_string() -> strpublic java.lang.String toString()private string ToString()func ToString() *stringwith()with()with()With()With()
Applies one or more mixins to this construct.
Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.
public with(mixins: ...IMixin[]): IConstructmixins:...IMixin[]The mixins to apply.
def with(
mixins: *IMixin
) -> IConstructmixins:*IMixinThe mixins to apply.
public IConstruct with(IMixin... mixins)mixins:IMixin...The mixins to apply.
private IConstruct With(params IMixin[] Mixins)Mixins:params IMixin[]The mixins to apply.
func With(mixins ...IMixin) IConstructmixins:...IMixinThe mixins to apply.
Static Functions
isConstruct()is_construct()isConstruct()IsConstruct()IsConstruct()
Checks if x is a construct.
Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.
import { CodeBuildRunnerProvider } from '@cloudsnorkel/cdk-github-runners'
CodeBuildRunnerProvider.isConstruct(x: any)x:anyAny object.
import cloudsnorkel.cdk_github_runners
cloudsnorkel.cdk_github_runners.CodeBuildRunnerProvider.is_construct(
x: typing.Any
)x:typing.AnyAny object.
import com.cloudsnorkel.cdk.github.runners.CodeBuildRunnerProvider;
CodeBuildRunnerProvider.isConstruct(java.lang.Object x)x:java.lang.ObjectAny object.
using CloudSnorkel;
CodeBuildRunnerProvider.IsConstruct(object X);X:objectAny object.
import "github.com/CloudSnorkel/cdk-github-runners-go/cloudsnorkelcdkgithubrunners"
cloudsnorkelcdkgithubrunners.CodeBuildRunnerProvider_IsConstruct(x interface{}) *boolx:interface{}Any object.
imageBuilder()image_builder()imageBuilder()ImageBuilder()ImageBuilder()
Create new image builder that builds CodeBuild specific runner images.
You can customize the OS, architecture, VPC, subnet, security groups, etc. by passing in props.
You can add components to the image builder by calling IConfigurableRunnerImageBuilder.addComponent().
The default OS is Ubuntu running on x64 architecture.
Included components:
RunnerImageComponent.requiredPackages()RunnerImageComponent.runnerUser()RunnerImageComponent.git()RunnerImageComponent.githubCli()RunnerImageComponent.awsCli()RunnerImageComponent.docker()RunnerImageComponent.githubRunner()
import { CodeBuildRunnerProvider } from '@cloudsnorkel/cdk-github-runners'
CodeBuildRunnerProvider.imageBuilder(scope: Construct, id: string, props?: RunnerImageBuilderProps)scope:Constructid:stringprops?:RunnerImageBuilderProps
import cloudsnorkel.cdk_github_runners
cloudsnorkel.cdk_github_runners.CodeBuildRunnerProvider.image_builder(
scope: Construct,
id: str,
architecture: Architecture = None,
aws_image_builder_options: AwsImageBuilderRunnerImageBuilderProps = None,
base_ami: BaseImage = None,
base_docker_image: BaseContainerImage = None,
builder_type: RunnerImageBuilderType = None,
code_build_options: CodeBuildRunnerImageBuilderProps = None,
components: typing.List[RunnerImageComponent] = None,
docker_setup_commands: typing.List[str] = None,
log_removal_policy: RemovalPolicy = None,
log_retention: RetentionDays = None,
os: Os = None,
rebuild_interval: Duration = None,
runner_version: RunnerVersion = None,
security_groups: typing.List[ISecurityGroup] = None,
subnet_selection: SubnetSelection = None,
vpc: IVpc = None,
wait_on_deploy: bool = None
)scope:Constructid:strarchitecture?:ArchitectureImage architecture.
Default:
Architecture.X86_64aws_image_builder_options?:AwsImageBuilderRunnerImageBuilderPropsOptions specific to AWS Image Builder.
Only used when
RunnerImageBuilderProps.builderTypeisRunnerImageBuilderType.AWS_IMAGE_BUILDER.base_ami?:BaseImageBase AMI from which runner AMIs will be built.
This can be a
BaseImageinstance created using static factory methods:BaseImage.fromAmiId(): use an AMI ID, likeBaseImage.fromAmiId('ami-12345')BaseImage.fromString(): use any string (ARN, AMI ID, etc.), likeBaseImage.fromString('arn:aws:imagebuilder:...')BaseImage.fromSsmParameter(): use an SSM parameter object, likeBaseImage.fromSsmParameter(parameter)BaseImage.fromSsmParameterName(): use an SSM parameter by name, likeBaseImage.fromSsmParameterName('/aws/service/ami/...')BaseImage.fromMarketplaceProductId(): use a Marketplace product ID, likeBaseImage.fromMarketplaceProductId('product-id')BaseImage.fromImageBuilder(): use an AWS-provided Image Builder image, likeBaseImage.fromImageBuilder(scope, 'ubuntu-server-22-lts-x86')
For example
BaseImage.fromImageBuilder(scope, 'ubuntu-server-22-lts-x86')would always use the latest version of Ubuntu 22.04 in each build. If you want a specific version, you can pass the version as the third parameter.Default: latest Ubuntu 22.04 AMI for
Os.LINUX_UBUNTUandOs.LINUX_UBUNTU_2204, Ubuntu 24.04 AMI forOs.LINUX_UBUNTU_2404, latest Amazon Linux 2 AMI forOs.LINUX_AMAZON_2, latest Windows Server 2022 AMI forOs.WINDOWSbase_docker_image?:BaseContainerImageBase image from which Docker runner images will be built.
This can be a
BaseContainerImageinstance created using static factory methods:BaseContainerImage.fromDockerHub(): use DockerHub, likeBaseContainerImage.fromDockerHub('ubuntu', '22.04')BaseContainerImage.fromEcr(): use ECR (automatically grants permissions with CodeBuild), likeBaseContainerImage.fromEcr(repo, 'latest')BaseContainerImage.fromEcrPublic(): use ECR Public, likeBaseContainerImage.fromEcrPublic('lts', 'ubuntu', '22.04')BaseContainerImage.fromString(): use any string, likeBaseContainerImage.fromString('public.ecr.aws/lts/ubuntu:22.04')
When using private images from a different account or not on ECR, you may need to include additional setup commands with
RunnerImageBuilderProps.dockerSetupCommands.Default: public.ecr.aws/lts/ubuntu:22.04 for
Os.LINUX_UBUNTUandOs.LINUX_UBUNTU_2204, public.ecr.aws/lts/ubuntu:24.04 forOs.LINUX_UBUNTU_2404, public.ecr.aws/amazonlinux/amazonlinux:2 forOs.LINUX_AMAZON_2, mcr.microsoft.com/windows/servercore:ltsc2019-amd64 forOs.WINDOWSbuilder_type?:RunnerImageBuilderTypeDefault: CodeBuild for Linux Docker image, AWS Image Builder for Windows Docker image and any AMI
code_build_options?:CodeBuildRunnerImageBuilderPropsOptions specific to CodeBuild image builder.
Only used when
RunnerImageBuilderProps.builderTypeisRunnerImageBuilderType.CODE_BUILD.components?:typing.List[RunnerImageComponent]Components to install on the image.
Default: none
docker_setup_commands?:typing.List[str]Additional commands to run on the build host before starting the Docker runner image build.
Use this to execute commands such as
docker loginoraws ecr get-login-passwordto pull private base images.Default: []
log_removal_policy?:RemovalPolicyRemoval 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.We try to not leave anything behind when removed. But sometimes a log staying behind is useful.
Default: RemovalPolicy.DESTROY
log_retention?:RetentionDaysThe number of days log events are kept in CloudWatch Logs.
When updating this property, unsetting it doesn't remove the log retention policy. To remove the retention policy, set the value to
INFINITE.Default: logs.RetentionDays.ONE_MONTH
os?:OsImage OS.
Default: OS.LINUX_UBUNTU
rebuild_interval?:DurationSchedule 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.
Set to zero to disable.
Default: Duration.days(7)
runner_version?:RunnerVersionVersion of GitHub Runners to install.
Default: latest version available
security_groups?:typing.List[ISecurityGroup]Security Groups to assign to this instance.
subnet_selection?:SubnetSelectionWhere to place the network interfaces within the VPC.
Default: no subnet
vpc?:IVpcVPC to build the image in.
Default: no VPC
wait_on_deploy?:boolWait for image to finish building during deployment.
It's usually best to leave this enabled to ensure everything is ready once deployment is done. However, it can be disabled to speed up deployment in case where you have a lot of image components that can take a long time to build.
Disabling this option means a finished deployment is not ready to be used. You will have to wait for the image to finish building before the system can be used.
Disabling this option may also mean any changes to settings or components can take up to a week (default rebuild interval) to take effect.
Default: true
import com.cloudsnorkel.cdk.github.runners.CodeBuildRunnerProvider;
CodeBuildRunnerProvider.imageBuilder(Construct scope, java.lang.String id),CodeBuildRunnerProvider.imageBuilder(Construct scope, java.lang.String id, RunnerImageBuilderProps props)scope:Constructid:java.lang.Stringprops?:RunnerImageBuilderProps
using CloudSnorkel;
CodeBuildRunnerProvider.ImageBuilder(Construct Scope, string Id, RunnerImageBuilderProps Props = null);Scope:ConstructId:stringProps?:RunnerImageBuilderProps
import "github.com/CloudSnorkel/cdk-github-runners-go/cloudsnorkelcdkgithubrunners"
cloudsnorkelcdkgithubrunners.CodeBuildRunnerProvider_ImageBuilder(scope Construct, id *string, props RunnerImageBuilderProps) IConfigurableRunnerImageBuilderscope:Constructid:*stringprops?:RunnerImageBuilderProps
Properties
nodenodenodeNodeNode
node: Node
node: Node
node: Node
Node: Node
Node: Node
The tree node.
connectionsconnectionsconnectionsConnectionsConnections
connections: Connections
connections: Connections
connections: Connections
Connections: Connections
Connections: Connections
The network connections associated with this resource.
grantPrincipalgrant_principalgrantPrincipalGrantPrincipalGrantPrincipal
grantPrincipal: IPrincipal
grant_principal: IPrincipal
grantPrincipal: IPrincipal
GrantPrincipal: IPrincipal
GrantPrincipal: IPrincipal
Grant principal used to add permissions to the runner role.
labelslabelslabelsLabelsLabels
labels: string[]
labels: typing.List[str]
labels: java.util.List<java.lang.String>
Labels: string[]
Labels: *[]*string
Labels associated with this provider.
logGrouplog_grouplogGroupLogGroupLogGroup
logGroup: ILogGroup
log_group: ILogGroup
logGroup: ILogGroup
LogGroup: ILogGroup
LogGroup: ILogGroup
Log group where provided runners will save their logs.
Note that this is not the job log, but the runner itself. It will not contain output from the GitHub Action but only metadata on its execution.
projectprojectprojectProjectProject
project: Project
project: Project
project: Project
Project: Project
Project: Project
CodeBuild project hosting the runner.