Skip to content

Commit

Permalink
fix: Amazon Linux 2/2023 support (#532)
Browse files Browse the repository at this point in the history
- Fix EC2 provider support for Amazon Linux 2 and 2023 (missing CloudWatch agent)
- Add missing support for Amazon Linux 2023 all around
- Upgrade ECS cluster nodes to Amazon Linux 2023

Fix #530
Fix #531
  • Loading branch information
kichik authored Apr 10, 2024
1 parent 91a3ced commit 2927297
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 25 deletions.
2 changes: 1 addition & 1 deletion API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/image-builders/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export abstract class RunnerImageBuilder extends RunnerImageBuilderBase {
}

const os = props?.os ?? Os.LINUX_UBUNTU;
if (os.is(Os.LINUX_UBUNTU) || os.is(Os.LINUX_AMAZON_2) || os.is(Os.LINUX_AMAZON_2023)) {
if (os.isIn(Os._ALL_LINUX_VERSIONS)) {
return new CodeBuildRunnerImageBuilder(scope, id, props);
} else if (os.is(Os.WINDOWS)) {
return new AwsImageBuilderRunnerImageBuilder(scope, id, props);
Expand Down
9 changes: 9 additions & 0 deletions src/image-builders/aws-image-builder/ami.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ export function defaultBaseAmi(scope: Construct, os: Os, architecture: Architect
});
}

if (os.is(Os.LINUX_AMAZON_2023)) {
return stack.formatArn({
service: 'imagebuilder',
resource: 'image',
account: 'aws',
resourceName: `amazon-linux-2023-${arch}/x.x.x`,
});
}

if (os.is(Os.WINDOWS)) {
return stack.formatArn({
service: 'imagebuilder',
Expand Down
2 changes: 1 addition & 1 deletion src/image-builders/aws-image-builder/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export class AwsImageBuilderRunnerImageBuilder extends RunnerImageBuilderBase {
if (this.os.is(Os.WINDOWS)) {
return 'Windows';
}
if (this.os.is(Os.LINUX_AMAZON_2) || this.os.is(Os.LINUX_UBUNTU)) {
if (this.os.isIn(Os._ALL_LINUX_VERSIONS)) {
return 'Linux';
}
throw new Error(`OS ${this.os.name} is not supported by AWS Image Builder`);
Expand Down
2 changes: 2 additions & 0 deletions src/image-builders/aws-image-builder/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export function defaultBaseDockerImage(os: Os) {
return 'public.ecr.aws/lts/ubuntu:22.04';
} else if (os.is(Os.LINUX_AMAZON_2)) {
return 'public.ecr.aws/amazonlinux/amazonlinux:2';
} else if (os.is(Os.LINUX_AMAZON_2023)) {
return 'public.ecr.aws/amazonlinux/amazonlinux:2023';
} else {
throw new Error(`OS ${os.name} not supported for Docker runner image`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/image-builders/aws-image-builder/deprecated/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export abstract class ImageBuilderBase extends Construct implements IRunnerImage
// platform
if (this.os.is(Os.WINDOWS)) {
this.platform = 'Windows';
} else if (this.os.is(Os.LINUX) || this.os.is(Os.LINUX_UBUNTU) || this.os.is(Os.LINUX_UBUNTU)) {
} else if (this.os.isIn(Os._ALL_LINUX_VERSIONS)) {
this.platform = 'Linux';
} else {
throw new Error(`Unsupported OS: ${this.os.name}.`);
Expand Down
2 changes: 1 addition & 1 deletion src/image-builders/codebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class CodeBuildRunnerImageBuilder extends RunnerImageBuilderBase {
}

private getDefaultBuildImage(): codebuild.IBuildImage {
if (this.os.is(Os.LINUX_UBUNTU) || this.os.is(Os.LINUX_AMAZON_2) || this.os.is(Os.LINUX_AMAZON_2023) || this.os.is(Os.LINUX)) {
if (this.os.isIn(Os._ALL_LINUX_VERSIONS)) {
// CodeBuild just runs `docker build` so its OS doesn't really matter
if (this.architecture.is(Architecture.X86_64)) {
return codebuild.LinuxBuildImage.AMAZON_LINUX_2_5;
Expand Down
12 changes: 10 additions & 2 deletions src/image-builders/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ export abstract class RunnerImageComponent {
} else if (os.is(Os.LINUX_AMAZON_2)) {
return [
'yum update -y',
'yum install -y jq tar gzip bzip2 which binutils zip unzip sudo shadow-utils',
'yum install -y jq tar gzip bzip2 which binutils zip unzip sudo shadow-utils amazon-cloudwatch-agent',
];
} else if (os.is(Os.LINUX_AMAZON_2023)) {
return [
'dnf upgrade -y',
'dnf install -y jq tar gzip bzip2 which binutils zip unzip sudo shadow-utils findutils',
'dnf install -y jq tar gzip bzip2 which binutils zip unzip sudo shadow-utils findutils amazon-cloudwatch-agent',
];
} else if (os.is(Os.WINDOWS)) {
return [
Expand Down Expand Up @@ -371,10 +371,18 @@ export abstract class RunnerImageComponent {
} else if (os.is(Os.LINUX_AMAZON_2)) {
return [
'yum install -y docker',
'sudo usermod -a -G docker runner',
'curl -sfLo /usr/bin/docker-compose https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s | tr \'[:upper:]\' \'[:lower:]\')-$(uname -m)',
'chmod +x /usr/bin/docker-compose',
'ln -s /usr/bin/docker-compose /usr/libexec/docker/cli-plugins/docker-compose',
];
} else if (os.is(Os.LINUX_AMAZON_2023)) {
return [
'dnf install -y docker',
'sudo usermod -a -G docker runner',
'curl -sfLo /usr/bin/docker-compose https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s | tr \'[:upper:]\' \'[:lower:]\')-$(uname -m)',
'chmod +x /usr/bin/docker-compose',
'ln -s /usr/bin/docker-compose /usr/libexec/docker/cli-plugins/docker-compose',
];
} else if (os.is(Os.WINDOWS)) {
return [
Expand Down
2 changes: 1 addition & 1 deletion src/providers/codebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export class CodeBuildRunnerProvider extends BaseProvider implements IRunnerProv

// choose build image
let buildImage: codebuild.IBuildImage | undefined;
if (image.os.is(Os.LINUX) || image.os.is(Os.LINUX_UBUNTU) || image.os.is(Os.LINUX_AMAZON_2)) {
if (image.os.isIn(Os._ALL_LINUX_VERSIONS)) {
if (image.architecture.is(Architecture.X86_64)) {
buildImage = codebuild.LinuxBuildImage.fromEcrRepository(image.imageRepository, image.imageTag);
} else if (image.architecture.is(Architecture.ARM64)) {
Expand Down
7 changes: 6 additions & 1 deletion src/providers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class Os {
/**
* Linux
*
* @deprecated use {@link LINUX_UBUNTU} or {@link LINUX_AMAZON_2}
* @deprecated use {@link LINUX_UBUNTU} or {@link LINUX_AMAZON_2} or {@link LINUX_AMAZON_2023}
*/
public static readonly LINUX = Os.of('Linux');

Expand All @@ -133,6 +133,11 @@ export class Os {
*/
public static readonly LINUX_AMAZON_2023 = Os.of('Amazon Linux 2023');

/**
* @internal
*/
public static readonly _ALL_LINUX_VERSIONS = [Os.LINUX, Os.LINUX_UBUNTU, Os.LINUX_AMAZON_2, Os.LINUX_AMAZON_2023];

/**
* Windows
*/
Expand Down
8 changes: 4 additions & 4 deletions src/providers/ecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,15 +459,15 @@ export class EcsRunnerProvider extends BaseProvider implements IRunnerProvider {
let ssmPath: string;
let found = false;

if (this.image.os.is(Os.LINUX) || this.image.os.is(Os.LINUX_UBUNTU) || this.image.os.is(Os.LINUX_AMAZON_2)) {
if (this.image.os.isIn(Os._ALL_LINUX_VERSIONS)) {
if (this.image.architecture.is(Architecture.X86_64)) {
baseImage = ecs.EcsOptimizedImage.amazonLinux2(ecs.AmiHardwareType.STANDARD);
ssmPath = '/aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id';
ssmPath = '/aws/service/ecs/optimized-ami/amazon-linux-2023/recommended/image_id';
found = true;
}
if (this.image.architecture.is(Architecture.ARM64)) {
baseImage = ecs.EcsOptimizedImage.amazonLinux2(ecs.AmiHardwareType.ARM);
ssmPath = '/aws/service/ecs/optimized-ami/amazon-linux-2/arm64/recommended/image_id';
ssmPath = '/aws/service/ecs/optimized-ami/amazon-linux-2023/arm64/recommended/image_id';
found = true;
}
}
Expand Down Expand Up @@ -547,7 +547,7 @@ export class EcsRunnerProvider extends BaseProvider implements IRunnerProvider {
cluster: this.cluster,
launchTarget: new EcsEc2LaunchTarget({
capacityProvider: this.capacityProvider.capacityProviderName,
enableExecute: this.image.os.is(Os.LINUX) || this.image.os.is(Os.LINUX_UBUNTU) || this.image.os.is(Os.LINUX_AMAZON_2),
enableExecute: this.image.os.isIn(Os._ALL_LINUX_VERSIONS),
}),
assignPublicIp: this.assignPublicIp,
containerOverrides: [
Expand Down
6 changes: 3 additions & 3 deletions src/providers/fargate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class EcsFargateLaunchTarget implements stepfunctions_tasks.IEcsLaunchTarget {
* @internal
*/
export function ecsRunCommand(os: Os, dind: boolean): string[] {
if (os.is(Os.LINUX) || os.is(Os.LINUX_UBUNTU) || os.is(Os.LINUX_AMAZON_2)) {
if (os.isIn(Os._ALL_LINUX_VERSIONS)) {
let dindCommand = '';
if (dind) {
dindCommand = 'nohup sudo dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay2 & ' +
Expand Down Expand Up @@ -399,7 +399,7 @@ export class FargateRunnerProvider extends BaseProvider implements IRunnerProvid
}

let os: ecs.OperatingSystemFamily;
if (image.os.is(Os.LINUX) || image.os.is(Os.LINUX_UBUNTU) || image.os.is(Os.LINUX_AMAZON_2)) {
if (image.os.isIn(Os._ALL_LINUX_VERSIONS)) {
os = ecs.OperatingSystemFamily.LINUX;
} else if (image.os.is(Os.WINDOWS)) {
os = ecs.OperatingSystemFamily.WINDOWS_SERVER_2019_CORE;
Expand Down Expand Up @@ -464,7 +464,7 @@ export class FargateRunnerProvider extends BaseProvider implements IRunnerProvid
cluster: this.cluster,
launchTarget: new EcsFargateLaunchTarget({
spot: this.spot,
enableExecute: this.image.os.is(Os.LINUX) || this.image.os.is(Os.LINUX_UBUNTU) || this.image.os.is(Os.LINUX_AMAZON_2),
enableExecute: this.image.os.isIn(Os._ALL_LINUX_VERSIONS),
}),
subnets: this.subnetSelection,
assignPublicIp: this.assignPublicIp,
Expand Down
2 changes: 1 addition & 1 deletion src/providers/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export class LambdaRunnerProvider extends BaseProvider implements IRunnerProvide
const image = this.image = imageBuilder.bindDockerImage();

let architecture: lambda.Architecture | undefined;
if (image.os.is(Os.LINUX_AMAZON_2) || image.os.is(Os.LINUX_AMAZON_2023) || image.os.is(Os.LINUX_UBUNTU)) {
if (image.os.isIn(Os._ALL_LINUX_VERSIONS)) {
if (image.architecture.is(Architecture.X86_64)) {
architecture = lambda.Architecture.X86_64;
}
Expand Down
4 changes: 2 additions & 2 deletions test/default.integ.snapshot/github-runners-test.assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@
}
}
},
"c778a1355556a7931c74bf18556e58cfff5dd5111b4157913931d869afcf4877": {
"e0a2b1d424418d59ce339e3fc6ec13297efe609e1c74984a369f871a521ac8ad": {
"source": {
"path": "github-runners-test.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "c778a1355556a7931c74bf18556e58cfff5dd5111b4157913931d869afcf4877.json",
"objectKey": "e0a2b1d424418d59ce339e3fc6ec13297efe609e1c74984a369f871a521ac8ad.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Loading

0 comments on commit 2927297

Please sign in to comment.