Skip to content

RunnerImageBuilder Construct ​

GitHub Runner image builder. Builds a Docker image or AMI with GitHub Runner and other requirements installed.

Images can be customized before passed into the provider by adding or removing components to be installed.

Images are rebuilt every week by default to ensure that the latest security patches are applied.

Implements: IConfigurableRunnerImageBuilder

Initializer ​

ts
import { RunnerImageBuilder } from '@cloudsnorkel/cdk-github-runners'

new RunnerImageBuilder(scope: Construct, id: string, props?: RunnerImageBuilderProps)
python
import cloudsnorkel.cdk_github_runners

cloudsnorkel.cdk_github_runners.RunnerImageBuilder(
  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: Construct

  • id: str

  • architecture?: Architecture

    Image architecture.

    Default: Architecture.X86_64

  • aws_image_builder_options?: AwsImageBuilderRunnerImageBuilderProps

    Options specific to AWS Image Builder.

    Only used when RunnerImageBuilderProps.builderType is RunnerImageBuilderType.AWS_IMAGE_BUILDER.

  • base_ami?: BaseImage

    Base AMI from which runner AMIs will be built.

    This can be a BaseImage instance created using static factory methods:

    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_UBUNTU and Os.LINUX_UBUNTU_2204, Ubuntu 24.04 AMI for Os.LINUX_UBUNTU_2404, latest Amazon Linux 2 AMI for Os.LINUX_AMAZON_2, latest Windows Server 2022 AMI for Os.WINDOWS

  • base_docker_image?: BaseContainerImage

    Base image from which Docker runner images will be built.

    This can be a BaseContainerImage instance created using static factory methods:

    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_UBUNTU and Os.LINUX_UBUNTU_2204, public.ecr.aws/lts/ubuntu:24.04 for Os.LINUX_UBUNTU_2404, public.ecr.aws/amazonlinux/amazonlinux:2 for Os.LINUX_AMAZON_2, mcr.microsoft.com/windows/servercore:ltsc2019-amd64 for Os.WINDOWS

  • builder_type?: RunnerImageBuilderType

    Default: CodeBuild for Linux Docker image, AWS Image Builder for Windows Docker image and any AMI

  • code_build_options?: CodeBuildRunnerImageBuilderProps

    Options specific to CodeBuild image builder.

    Only used when RunnerImageBuilderProps.builderType is RunnerImageBuilderType.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 login or aws ecr get-login-password to pull private base images.

    Default: []

  • log_removal_policy?: RemovalPolicy

    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.

    We try to not leave anything behind when removed. But sometimes a log staying behind is useful.

    Default: RemovalPolicy.DESTROY

  • log_retention?: RetentionDays

    The 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?: Os

    Image OS.

    Default: OS.LINUX_UBUNTU

  • rebuild_interval?: Duration

    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.

    Set to zero to disable.

    Default: Duration.days(7)

  • runner_version?: RunnerVersion

    Version of GitHub Runners to install.

    Default: latest version available

  • security_groups?: typing.List[ISecurityGroup]

    Security Groups to assign to this instance.

  • subnet_selection?: SubnetSelection

    Where to place the network interfaces within the VPC.

    Default: no subnet

  • vpc?: IVpc

    VPC to build the image in.

    Default: no VPC

  • wait_on_deploy?: bool

    Wait 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

java
import com.cloudsnorkel.cdk.github.runners.RunnerImageBuilder;

RunnerImageBuilder.Builder.create(Construct scope, java.lang.String id)
//  .architecture(Architecture)
//  .awsImageBuilderOptions(AwsImageBuilderRunnerImageBuilderProps)
//  .baseAmi(BaseImage)
//  .baseDockerImage(BaseContainerImage)
//  .builderType(RunnerImageBuilderType)
//  .codeBuildOptions(CodeBuildRunnerImageBuilderProps)
//  .components(java.util.List<RunnerImageComponent>)
//  .dockerSetupCommands(java.util.List<java.lang.String>)
//  .logRemovalPolicy(RemovalPolicy)
//  .logRetention(RetentionDays)
//  .os(Os)
//  .rebuildInterval(Duration)
//  .runnerVersion(RunnerVersion)
//  .securityGroups(java.util.List<ISecurityGroup>)
//  .subnetSelection(SubnetSelection)
//  .vpc(IVpc)
//  .waitOnDeploy(java.lang.Boolean)
    .build();
  • scope: Construct

  • id: java.lang.String

  • architecture?: Architecture

    Image architecture.

    Default: Architecture.X86_64

  • awsImageBuilderOptions?: AwsImageBuilderRunnerImageBuilderProps

    Options specific to AWS Image Builder.

    Only used when RunnerImageBuilderProps.builderType is RunnerImageBuilderType.AWS_IMAGE_BUILDER.

  • baseAmi?: BaseImage

    Base AMI from which runner AMIs will be built.

    This can be a BaseImage instance created using static factory methods:

    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_UBUNTU and Os.LINUX_UBUNTU_2204, Ubuntu 24.04 AMI for Os.LINUX_UBUNTU_2404, latest Amazon Linux 2 AMI for Os.LINUX_AMAZON_2, latest Windows Server 2022 AMI for Os.WINDOWS

  • baseDockerImage?: BaseContainerImage

    Base image from which Docker runner images will be built.

    This can be a BaseContainerImage instance created using static factory methods:

    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_UBUNTU and Os.LINUX_UBUNTU_2204, public.ecr.aws/lts/ubuntu:24.04 for Os.LINUX_UBUNTU_2404, public.ecr.aws/amazonlinux/amazonlinux:2 for Os.LINUX_AMAZON_2, mcr.microsoft.com/windows/servercore:ltsc2019-amd64 for Os.WINDOWS

  • builderType?: RunnerImageBuilderType

    Default: CodeBuild for Linux Docker image, AWS Image Builder for Windows Docker image and any AMI

  • codeBuildOptions?: CodeBuildRunnerImageBuilderProps

    Options specific to CodeBuild image builder.

    Only used when RunnerImageBuilderProps.builderType is RunnerImageBuilderType.CODE_BUILD.

  • components?: java.util.List<RunnerImageComponent>

    Components to install on the image.

    Default: none

  • dockerSetupCommands?: java.util.List<java.lang.String>

    Additional commands to run on the build host before starting the Docker runner image build.

    Use this to execute commands such as docker login or aws ecr get-login-password to pull private base images.

    Default: []

  • logRemovalPolicy?: RemovalPolicy

    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.

    We try to not leave anything behind when removed. But sometimes a log staying behind is useful.

    Default: RemovalPolicy.DESTROY

  • logRetention?: RetentionDays

    The 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?: Os

    Image OS.

    Default: OS.LINUX_UBUNTU

  • rebuildInterval?: Duration

    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.

    Set to zero to disable.

    Default: Duration.days(7)

  • runnerVersion?: RunnerVersion

    Version of GitHub Runners to install.

    Default: latest version available

  • securityGroups?: java.util.List<ISecurityGroup>

    Security Groups to assign to this instance.

  • subnetSelection?: SubnetSelection

    Where to place the network interfaces within the VPC.

    Default: no subnet

  • vpc?: IVpc

    VPC to build the image in.

    Default: no VPC

  • waitOnDeploy?: java.lang.Boolean

    Wait 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

csharp
using CloudSnorkel;

new RunnerImageBuilder(Construct Scope, string Id, RunnerImageBuilderProps Props = null);
go
import "github.com/CloudSnorkel/cdk-github-runners-go/cloudsnorkelcdkgithubrunners"

cloudsnorkelcdkgithubrunners.NewRunnerImageBuilder(scope Construct, id *string, props RunnerImageBuilderProps) RunnerImageBuilder

Methods ​

toString()to_string()toString()ToString()ToString() ​

Returns a string representation of this construct.

ts
public toString(): string
python
def to_string() -> str
java
public java.lang.String toString()
csharp
private string ToString()
go
func ToString() *string

with()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.

ts
public with(mixins: ...IMixin[]): IConstruct
  • mixins: ...IMixin[]

    The mixins to apply.

python
def with(
  mixins: *IMixin
) -> IConstruct
  • mixins: *IMixin

    The mixins to apply.

java
public IConstruct with(IMixin... mixins)
  • mixins: IMixin...

    The mixins to apply.

csharp
private IConstruct With(params IMixin[] Mixins)
  • Mixins: params IMixin[]

    The mixins to apply.

go
func With(mixins ...IMixin) IConstruct
  • mixins: ...IMixin

    The mixins to apply.

addComponent()add_component()addComponent()AddComponent()AddComponent() ​

Add a component to the image builder.

The component will be added to the end of the list of components.

ts
public addComponent(component: RunnerImageComponent): void
python
def add_component(
  component: RunnerImageComponent
) -> None
java
public void addComponent(RunnerImageComponent component)
csharp
private void AddComponent(RunnerImageComponent Component)
go
func AddComponent(component RunnerImageComponent)

bindAmi()bind_ami()bindAmi()BindAmi()BindAmi() ​

Build and return an AMI with GitHub Runner installed in it.

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.

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.

ts
public bindAmi(): RunnerAmi
python
def bind_ami() -> RunnerAmi
java
public RunnerAmi bindAmi()
csharp
private RunnerAmi BindAmi()
go
func BindAmi() RunnerAmi

bindDockerImage()bind_docker_image()bindDockerImage()BindDockerImage()BindDockerImage() ​

Build and return a Docker image with GitHub Runner installed in it.

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.

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.

The image can be further updated over time manually or using a schedule as long as it is always written to the same tag.

ts
public bindDockerImage(): RunnerImage
python
def bind_docker_image() -> RunnerImage
java
public RunnerImage bindDockerImage()
csharp
private RunnerImage BindDockerImage()
go
func BindDockerImage() RunnerImage

removeComponent()remove_component()removeComponent()RemoveComponent()RemoveComponent() ​

Remove a component from the image builder.

Removal is done by component name. Multiple components with the same name will all be removed.

ts
public removeComponent(component: RunnerImageComponent): void
python
def remove_component(
  component: RunnerImageComponent
) -> None
java
public void removeComponent(RunnerImageComponent component)
csharp
private void RemoveComponent(RunnerImageComponent Component)
go
func RemoveComponent(component RunnerImageComponent)

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.

ts
import { RunnerImageBuilder } from '@cloudsnorkel/cdk-github-runners'

RunnerImageBuilder.isConstruct(x: any)
  • x: any

    Any object.

python
import cloudsnorkel.cdk_github_runners

cloudsnorkel.cdk_github_runners.RunnerImageBuilder.is_construct(
  x: typing.Any
)
  • x: typing.Any

    Any object.

java
import com.cloudsnorkel.cdk.github.runners.RunnerImageBuilder;

RunnerImageBuilder.isConstruct(java.lang.Object x)
  • x: java.lang.Object

    Any object.

csharp
using CloudSnorkel;

RunnerImageBuilder.IsConstruct(object X);
  • X: object

    Any object.

go
import "github.com/CloudSnorkel/cdk-github-runners-go/cloudsnorkelcdkgithubrunners"

cloudsnorkelcdkgithubrunners.RunnerImageBuilder_IsConstruct(x interface{}) *bool
  • x: interface{}

    Any object.

new()new()new()New()New() ​

Create a new image builder based on the provided properties.

The implementation will differ based on the OS, architecture, and requested builder type.

ts
import { RunnerImageBuilder } from '@cloudsnorkel/cdk-github-runners'

RunnerImageBuilder.new(scope: Construct, id: string, props?: RunnerImageBuilderProps)
python
import cloudsnorkel.cdk_github_runners

cloudsnorkel.cdk_github_runners.RunnerImageBuilder.new(
  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: Construct

  • id: str

  • architecture?: Architecture

    Image architecture.

    Default: Architecture.X86_64

  • aws_image_builder_options?: AwsImageBuilderRunnerImageBuilderProps

    Options specific to AWS Image Builder.

    Only used when RunnerImageBuilderProps.builderType is RunnerImageBuilderType.AWS_IMAGE_BUILDER.

  • base_ami?: BaseImage

    Base AMI from which runner AMIs will be built.

    This can be a BaseImage instance created using static factory methods:

    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_UBUNTU and Os.LINUX_UBUNTU_2204, Ubuntu 24.04 AMI for Os.LINUX_UBUNTU_2404, latest Amazon Linux 2 AMI for Os.LINUX_AMAZON_2, latest Windows Server 2022 AMI for Os.WINDOWS

  • base_docker_image?: BaseContainerImage

    Base image from which Docker runner images will be built.

    This can be a BaseContainerImage instance created using static factory methods:

    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_UBUNTU and Os.LINUX_UBUNTU_2204, public.ecr.aws/lts/ubuntu:24.04 for Os.LINUX_UBUNTU_2404, public.ecr.aws/amazonlinux/amazonlinux:2 for Os.LINUX_AMAZON_2, mcr.microsoft.com/windows/servercore:ltsc2019-amd64 for Os.WINDOWS

  • builder_type?: RunnerImageBuilderType

    Default: CodeBuild for Linux Docker image, AWS Image Builder for Windows Docker image and any AMI

  • code_build_options?: CodeBuildRunnerImageBuilderProps

    Options specific to CodeBuild image builder.

    Only used when RunnerImageBuilderProps.builderType is RunnerImageBuilderType.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 login or aws ecr get-login-password to pull private base images.

    Default: []

  • log_removal_policy?: RemovalPolicy

    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.

    We try to not leave anything behind when removed. But sometimes a log staying behind is useful.

    Default: RemovalPolicy.DESTROY

  • log_retention?: RetentionDays

    The 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?: Os

    Image OS.

    Default: OS.LINUX_UBUNTU

  • rebuild_interval?: Duration

    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.

    Set to zero to disable.

    Default: Duration.days(7)

  • runner_version?: RunnerVersion

    Version of GitHub Runners to install.

    Default: latest version available

  • security_groups?: typing.List[ISecurityGroup]

    Security Groups to assign to this instance.

  • subnet_selection?: SubnetSelection

    Where to place the network interfaces within the VPC.

    Default: no subnet

  • vpc?: IVpc

    VPC to build the image in.

    Default: no VPC

  • wait_on_deploy?: bool

    Wait 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

java
import com.cloudsnorkel.cdk.github.runners.RunnerImageBuilder;

RunnerImageBuilder.new(Construct scope, java.lang.String id),RunnerImageBuilder.new(Construct scope, java.lang.String id, RunnerImageBuilderProps props)
csharp
using CloudSnorkel;

RunnerImageBuilder.New(Construct Scope, string Id, RunnerImageBuilderProps Props = null);
go
import "github.com/CloudSnorkel/cdk-github-runners-go/cloudsnorkelcdkgithubrunners"

cloudsnorkelcdkgithubrunners.RunnerImageBuilder_New(scope Construct, id *string, props RunnerImageBuilderProps) IConfigurableRunnerImageBuilder

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

The principal to grant permissions to.

Released under the Apache-2.0 License.