Skip to content

Commit 76a9fa4

Browse files
Fix: Codebuild UnitTest (#132)
1 parent 0540957 commit 76a9fa4

File tree

5 files changed

+91
-48
lines changed

5 files changed

+91
-48
lines changed

lib/pipeline/orcabus-stateful-pipeline-stack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class StatefulPipelineStack extends cdk.Stack {
1818
});
1919

2020
const unitTest = new pipelines.CodeBuildStep('UnitTest', {
21-
commands: ['yarn install --frozen-lockfile', 'make test-stateful'],
21+
commands: ['yarn install --immutable', 'make test-stateful'],
2222
input: sourceFile,
2323
primaryOutputDirectory: '.',
2424
buildEnvironment: {
@@ -43,7 +43,7 @@ export class StatefulPipelineStack extends cdk.Stack {
4343
});
4444

4545
const synthAction = new pipelines.CodeBuildStep('Synth', {
46-
commands: ['yarn install --frozen-lockfile', 'yarn run cdk-stateful-pipeline synth'],
46+
commands: ['yarn install --immutable', 'yarn run cdk-stateful-pipeline synth'],
4747
input: unitTest,
4848
primaryOutputDirectory: 'cdk.out',
4949
rolePolicyStatements: [

lib/pipeline/orcabus-stateless-pipeline-stack.ts

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ export class StatelessPipelineStack extends cdk.Stack {
1818
});
1919

2020
const unitTest = new pipelines.CodeBuildStep('UnitTest', {
21-
commands: ['yarn install --frozen-lockfile', 'make suite'],
21+
installCommands: [
22+
// RUST installation
23+
`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y`,
24+
`source $HOME/.cargo/env`,
25+
`pip3 install cargo-lambda`,
26+
],
27+
commands: ['yarn install --immutable', 'make suite'],
2228
input: sourceFile,
2329
primaryOutputDirectory: '.',
2430
buildEnvironment: {
@@ -47,7 +53,13 @@ export class StatelessPipelineStack extends cdk.Stack {
4753
});
4854

4955
const synthAction = new pipelines.CodeBuildStep('Synth', {
50-
commands: ['yarn install --frozen-lockfile', 'yarn run cdk-stateless-pipeline synth'],
56+
installCommands: [
57+
// RUST installation
58+
`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y`,
59+
`source $HOME/.cargo/env`,
60+
`pip3 install cargo-lambda`,
61+
],
62+
commands: ['yarn install --immutable', 'yarn run cdk-stateless-pipeline synth'],
5163
input: unitTest,
5264
primaryOutputDirectory: 'cdk.out',
5365
rolePolicyStatements: [
@@ -89,34 +101,38 @@ export class StatelessPipelineStack extends cdk.Stack {
89101
})
90102
);
91103

92-
/**
93-
* Deployment to Gamma (Staging) account
94-
*/
95-
const gammaConfig = getEnvironmentConfig('gamma');
96-
if (!gammaConfig) throw new Error(`No 'Gamma' account configuration`);
97-
pipeline.addStage(
98-
new OrcaBusStatelessDeploymentStage(
99-
this,
100-
'GammaStatelessDeployment',
101-
gammaConfig.stackProps,
102-
{
103-
account: gammaConfig.accountId,
104-
}
105-
),
106-
{ pre: [new pipelines.ManualApprovalStep('PromoteToGamma')] }
107-
);
104+
// Since the stateless stack might need to reference the stateful resources (e.g. db, sg), we might comment this out
105+
// to prevent cdk from looking up for non existence resource. Currently the stateful resource is only deployed in
106+
// dev
108107

109-
/**
110-
* Deployment to Prod account
111-
*/
112-
const prodConfig = getEnvironmentConfig('prod');
113-
if (!prodConfig) throw new Error(`No 'Prod' account configuration`);
114-
pipeline.addStage(
115-
new OrcaBusStatelessDeploymentStage(this, 'ProdStatelessDeployment', prodConfig.stackProps, {
116-
account: gammaConfig?.accountId,
117-
}),
118-
{ pre: [new pipelines.ManualApprovalStep('PromoteToProd')] }
119-
);
108+
// /**
109+
// * Deployment to Gamma (Staging) account
110+
// */
111+
// const gammaConfig = getEnvironmentConfig('gamma');
112+
// if (!gammaConfig) throw new Error(`No 'Gamma' account configuration`);
113+
// pipeline.addStage(
114+
// new OrcaBusStatelessDeploymentStage(
115+
// this,
116+
// 'GammaStatelessDeployment',
117+
// gammaConfig.stackProps,
118+
// {
119+
// account: gammaConfig.accountId,
120+
// }
121+
// ),
122+
// { pre: [new pipelines.ManualApprovalStep('PromoteToGamma')] }
123+
// );
124+
125+
// /**
126+
// * Deployment to Prod account
127+
// */
128+
// const prodConfig = getEnvironmentConfig('prod');
129+
// if (!prodConfig) throw new Error(`No 'Prod' account configuration`);
130+
// pipeline.addStage(
131+
// new OrcaBusStatelessDeploymentStage(this, 'ProdStatelessDeployment', prodConfig.stackProps, {
132+
// account: gammaConfig?.accountId,
133+
// }),
134+
// { pre: [new pipelines.ManualApprovalStep('PromoteToProd')] }
135+
// );
120136
}
121137
}
122138

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This image will generate the node_modules needed for lambda and let
2+
# the layer reference the output from this image
3+
4+
FROM public.ecr.aws/docker/library/node:20-alpine
5+
6+
WORKDIR /home/node/app
7+
8+
COPY package.json package.json
9+
COPY yarn.lock yarn.lock
10+
RUN yarn install --immutable
11+
12+
# making nodejs folder where as guided in the AWS lambda layer docs
13+
RUN mkdir -p output/nodejs
14+
15+
# copy node_modules to that folder
16+
RUN cp -r node_modules output/nodejs

lib/workload/stateless/postgres_manager/deploy/postgres-manager-stack.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as iam from 'aws-cdk-lib/aws-iam';
88
import * as rds from 'aws-cdk-lib/aws-rds';
99
import * as ssm from 'aws-cdk-lib/aws-ssm';
1010
import { MicroserviceConfig, DbAuthType } from '../function/type';
11+
import package_json from '../package.json';
1112

1213
export type PostgresManagerConfig = {
1314
masterSecretName: string;
@@ -38,9 +39,21 @@ export class PostgresManagerStack extends Stack {
3839
props.clusterResourceIdParameterName
3940
);
4041

41-
const rdsLambdaProps : nodejs.NodejsFunctionProps = {
42+
const dependencyLayer = new lambda.LayerVersion(this, 'DependenciesLayer', {
43+
code: lambda.Code.fromDockerBuild(__dirname + '/../', {
44+
cacheDisabled: true,
45+
file: 'deploy/construct/layer/node_module.Dockerfile',
46+
imagePath: 'home/node/app/output',
47+
}),
48+
compatibleArchitectures: [lambda.Architecture.ARM_64],
49+
compatibleRuntimes: [lambda.Runtime.NODEJS_20_X],
50+
});
51+
52+
const runtimeDependencies = Object.keys(package_json.dependencies);
53+
const rdsLambdaProps: nodejs.NodejsFunctionProps = {
54+
layers: [dependencyLayer],
55+
bundling: { externalModules: runtimeDependencies },
4256
timeout: Duration.minutes(5),
43-
depsLockFilePath: __dirname + '/../yarn.lock',
4457
handler: 'handler',
4558
runtime: lambda.Runtime.NODEJS_20_X,
4659
architecture: lambda.Architecture.ARM_64,
@@ -98,9 +111,7 @@ export class PostgresManagerStack extends Stack {
98111
new iam.PolicyStatement({
99112
actions: ['secretsmanager:CreateSecret', 'secretsmanager:TagResource'],
100113
effect: iam.Effect.ALLOW,
101-
resources: [
102-
`arn:aws:secretsmanager:ap-southeast-2:${process.env.CDK_DEFAULT_ACCOUNT}:secret:*`,
103-
],
114+
resources: [`arn:aws:secretsmanager:ap-southeast-2:*:secret:*`],
104115
}),
105116
new iam.PolicyStatement({
106117
actions: ['secretsmanager:GetRandomPassword'],

lib/workload/stateless/postgres_manager/yarn.lock

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,18 +1042,6 @@ __metadata:
10421042
languageName: node
10431043
linkType: hard
10441044

1045-
"lambda-with-rds@workspace:.":
1046-
version: 0.0.0-use.local
1047-
resolution: "lambda-with-rds@workspace:."
1048-
dependencies:
1049-
"@aws-sdk/client-secrets-manager": ^3.515.0
1050-
"@types/aws-lambda": ^8.10.134
1051-
"@types/pg": ^8
1052-
pg: ^8.11.3
1053-
typescript: ^5.3.3
1054-
languageName: unknown
1055-
linkType: soft
1056-
10571045
"obuf@npm:~1.1.2":
10581046
version: 1.1.2
10591047
resolution: "obuf@npm:1.1.2"
@@ -1233,6 +1221,18 @@ __metadata:
12331221
languageName: node
12341222
linkType: hard
12351223

1224+
"postgres-manager@workspace:.":
1225+
version: 0.0.0-use.local
1226+
resolution: "postgres-manager@workspace:."
1227+
dependencies:
1228+
"@aws-sdk/client-secrets-manager": ^3.515.0
1229+
"@types/aws-lambda": ^8.10.134
1230+
"@types/pg": ^8
1231+
pg: ^8.11.3
1232+
typescript: ^5.3.3
1233+
languageName: unknown
1234+
linkType: soft
1235+
12361236
"postgres-range@npm:^1.1.1":
12371237
version: 1.1.4
12381238
resolution: "postgres-range@npm:1.1.4"

0 commit comments

Comments
 (0)