Skip to content

Commit

Permalink
fix: Java bundling stopped working (#82)
Browse files Browse the repository at this point in the history
Upgrading to Amazon Linux 2023 for CodeBuild changed the package name we need to install for Java. The upgrade was required for Node 18 support.
  • Loading branch information
kichik authored Oct 17, 2023
1 parent b380a6a commit 825fded
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class BaseDependencyPackager extends Construct implements iam.IGrantable,
subnetSelection: internalProps.props?.subnetSelection,
environment: {
buildImage: this.architecture == lambda.Architecture.X86_64 ?
codebuild.LinuxBuildImage.AMAZON_LINUX_2_5 : codebuild.LinuxArmBuildImage.AMAZON_LINUX_2_STANDARD_2_0,
codebuild.LinuxBuildImage.AMAZON_LINUX_2_5 : codebuild.LinuxArmBuildImage.AMAZON_LINUX_2_STANDARD_3_0,
},
logging: {
cloudWatch: {
Expand Down Expand Up @@ -197,7 +197,7 @@ export class BaseDependencyPackager extends Construct implements iam.IGrantable,
],
logRetention: RetentionDays.ONE_MONTH,
});
this.provider.node.addDependency(this.project);
this.provider.node.addDependency(this.project);
this.packagesBucket.grantDelete(this.provider);
} else if (this.type == DependencyPackagerType.LAMBDA) {
const lambdaProps = {
Expand Down
21 changes: 16 additions & 5 deletions src/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BaseDependencyPackager, DependencyPackagerProps, LayerProps } from './b
* Packager for creating Lambda layers for Java dependencies in AWS. Nothing is done locally so this doesn't require Docker and doesn't upload huge files to S3.
*/
export class JavaDependencyPackager extends BaseDependencyPackager {
private static runtimePackage(props?: DependencyPackagerProps) {
private static basePackage(props?: DependencyPackagerProps) {
switch (props?.runtime ?? lambda.Runtime.JAVA_11) {
case lambda.Runtime.JAVA_8:
case lambda.Runtime.JAVA_8_CORRETTO:
Expand All @@ -20,16 +20,27 @@ export class JavaDependencyPackager extends BaseDependencyPackager {
}
}

private static packageArch(props?: DependencyPackagerProps) {
switch (props?.architecture ?? lambda.Architecture.X86_64) {
case lambda.Architecture.X86_64:
return 'x86_64';
case lambda.Architecture.ARM_64:
return 'aarch64';
default:
throw new Error(`We do not support ${props?.architecture?.name} yet`);
}
}

constructor(scope: Construct, id: string, props?: DependencyPackagerProps) {
super(scope, id, {
props,
runtimeFamily: lambda.RuntimeFamily.JAVA,
defaultRuntime: lambda.Runtime.JAVA_11,
codeBuildRuntimeInstallCommands: [
`echo Installing ${JavaDependencyPackager.runtimePackage(props)}`,
`yum install -y ${JavaDependencyPackager.runtimePackage(props)}`,
`alternatives --set java /usr/lib/jvm/${JavaDependencyPackager.runtimePackage(props)}.*/bin/java`,
`alternatives --set javac /usr/lib/jvm/${JavaDependencyPackager.runtimePackage(props)}.*/bin/javac`,
`echo Installing ${JavaDependencyPackager.basePackage(props)}`,
`yum install -y ${JavaDependencyPackager.basePackage(props)}-devel.${JavaDependencyPackager.packageArch(props)} ${JavaDependencyPackager.basePackage(props)}-headless.${JavaDependencyPackager.packageArch(props)}`,
`alternatives --set java $(rpm -ql ${JavaDependencyPackager.basePackage(props)}-headless.${JavaDependencyPackager.packageArch(props)} | grep bin/java$ | head -n 1)`,
`alternatives --set javac $(rpm -ql ${JavaDependencyPackager.basePackage(props)}-devel.${JavaDependencyPackager.packageArch(props)} | grep bin/javac$ | head -n 1)`,
],
targetDirectory: 'java',
});
Expand Down
4 changes: 2 additions & 2 deletions test/default.integ.snapshot/Turbo-Layer-Test.assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@
}
}
},
"3a503d4db4e69346c332bfe77fce8ce0c794379d3af40b21131b92e270d6c489": {
"ca58bd87cb799fc28d4ab0ad7e68f27535125e8e95625d6a331bc473d09c7ae8": {
"source": {
"path": "Turbo-Layer-Test.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "3a503d4db4e69346c332bfe77fce8ce0c794379d3af40b21131b92e270d6c489.json",
"objectKey": "ca58bd87cb799fc28d4ab0ad7e68f27535125e8e95625d6a331bc473d09c7ae8.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/default.integ.snapshot/Turbo-Layer-Test.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -7919,9 +7919,9 @@
},
"CodeBuildInstallCommands": [
"echo Installing java-11-amazon-corretto",
"yum install -y java-11-amazon-corretto",
"alternatives --set java /usr/lib/jvm/java-11-amazon-corretto.*/bin/java",
"alternatives --set javac /usr/lib/jvm/java-11-amazon-corretto.*/bin/javac"
"yum install -y java-11-amazon-corretto-devel.x86_64 java-11-amazon-corretto-headless.x86_64",
"alternatives --set java $(rpm -ql java-11-amazon-corretto-headless.x86_64 | grep bin/java$ | head -n 1)",
"alternatives --set javac $(rpm -ql java-11-amazon-corretto-devel.x86_64 | grep bin/javac$ | head -n 1)"
],
"PreinstallCommands": [],
"Commands": [
Expand Down
2 changes: 1 addition & 1 deletion test/default.integ.snapshot/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/3a503d4db4e69346c332bfe77fce8ce0c794379d3af40b21131b92e270d6c489.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/ca58bd87cb799fc28d4ab0ad7e68f27535125e8e95625d6a331bc473d09c7ae8.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down

0 comments on commit 825fded

Please sign in to comment.