Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Codebuild UnitTest #132

Merged
merged 23 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
385f13b
Update postgres-manager-stack.ts
williamputraintan Mar 4, 2024
002bc27
update
williamputraintan Mar 4, 2024
5c93030
test
williamputraintan Mar 4, 2024
fc90121
Update Makefile
williamputraintan Mar 4, 2024
ca8e630
comment out stg and prod
williamputraintan Mar 4, 2024
9deb79a
Update orcabus-stateless-pipeline-stack.ts
williamputraintan Mar 4, 2024
1ab4995
Update postgres-manager-stack.ts
williamputraintan Mar 4, 2024
016c095
reenabled
williamputraintan Mar 4, 2024
ce9e299
Update orcabus-stateless-pipeline-stack.ts
williamputraintan Mar 4, 2024
a2934f2
Merge branch 'main' into fix(postgres-manager)/codebuild-unit-test
williamputraintan Mar 4, 2024
84a1498
Update orcabus-stateless-pipeline-stack.ts
williamputraintan Mar 4, 2024
36751aa
Merge remote-tracking branch 'origin/fix/sqlx-queries' into fix(postg…
williamputraintan Mar 5, 2024
c228e00
Update stateless-pipeline.test.ts
williamputraintan Mar 5, 2024
f89e244
update
williamputraintan Mar 5, 2024
6b9575c
Update postgres-manager-stack.ts
williamputraintan Mar 5, 2024
1973b90
lock file
williamputraintan Mar 5, 2024
c9eb401
introduce layer dep
williamputraintan Mar 5, 2024
7fb9e96
Update stateless-pipeline.test.ts
williamputraintan Mar 5, 2024
f38103e
cargo install cargo-lambda
williamputraintan Mar 5, 2024
07692e2
update
williamputraintan Mar 5, 2024
e5c9498
Update orcabus-stateless-pipeline-stack.ts
williamputraintan Mar 5, 2024
88dfb4a
switch back branch name
williamputraintan Mar 5, 2024
4442392
Merge branch 'main' into fix(postgres-manager)/codebuild-unit-test
williamputraintan Mar 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/pipeline/orcabus-stateful-pipeline-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class StatefulPipelineStack extends cdk.Stack {
});

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

const synthAction = new pipelines.CodeBuildStep('Synth', {
commands: ['yarn install --frozen-lockfile', 'yarn run cdk-stateful-pipeline synth'],
commands: ['yarn install --immutable', 'yarn run cdk-stateful-pipeline synth'],
input: unitTest,
primaryOutputDirectory: 'cdk.out',
rolePolicyStatements: [
Expand Down
74 changes: 45 additions & 29 deletions lib/pipeline/orcabus-stateless-pipeline-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ export class StatelessPipelineStack extends cdk.Stack {
});

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

const synthAction = new pipelines.CodeBuildStep('Synth', {
commands: ['yarn install --frozen-lockfile', 'yarn run cdk-stateless-pipeline synth'],
installCommands: [
// RUST installation
`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y`,
`source $HOME/.cargo/env`,
`pip3 install cargo-lambda`,
],
commands: ['yarn install --immutable', 'yarn run cdk-stateless-pipeline synth'],
input: unitTest,
primaryOutputDirectory: 'cdk.out',
rolePolicyStatements: [
Expand Down Expand Up @@ -89,34 +101,38 @@ export class StatelessPipelineStack extends cdk.Stack {
})
);

/**
* Deployment to Gamma (Staging) account
*/
const gammaConfig = getEnvironmentConfig('gamma');
if (!gammaConfig) throw new Error(`No 'Gamma' account configuration`);
pipeline.addStage(
new OrcaBusStatelessDeploymentStage(
this,
'GammaStatelessDeployment',
gammaConfig.stackProps,
{
account: gammaConfig.accountId,
}
),
{ pre: [new pipelines.ManualApprovalStep('PromoteToGamma')] }
);
// Since the stateless stack might need to reference the stateful resources (e.g. db, sg), we might comment this out
// to prevent cdk from looking up for non existence resource. Currently the stateful resource is only deployed in
// dev

/**
* Deployment to Prod account
*/
const prodConfig = getEnvironmentConfig('prod');
if (!prodConfig) throw new Error(`No 'Prod' account configuration`);
pipeline.addStage(
new OrcaBusStatelessDeploymentStage(this, 'ProdStatelessDeployment', prodConfig.stackProps, {
account: gammaConfig?.accountId,
}),
{ pre: [new pipelines.ManualApprovalStep('PromoteToProd')] }
);
// /**
// * Deployment to Gamma (Staging) account
// */
// const gammaConfig = getEnvironmentConfig('gamma');
// if (!gammaConfig) throw new Error(`No 'Gamma' account configuration`);
// pipeline.addStage(
// new OrcaBusStatelessDeploymentStage(
// this,
// 'GammaStatelessDeployment',
// gammaConfig.stackProps,
// {
// account: gammaConfig.accountId,
// }
// ),
// { pre: [new pipelines.ManualApprovalStep('PromoteToGamma')] }
// );

// /**
// * Deployment to Prod account
// */
// const prodConfig = getEnvironmentConfig('prod');
// if (!prodConfig) throw new Error(`No 'Prod' account configuration`);
// pipeline.addStage(
// new OrcaBusStatelessDeploymentStage(this, 'ProdStatelessDeployment', prodConfig.stackProps, {
// account: gammaConfig?.accountId,
// }),
// { pre: [new pipelines.ManualApprovalStep('PromoteToProd')] }
// );
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This image will generate the node_modules needed for lambda and let
# the layer reference the output from this image

FROM public.ecr.aws/docker/library/node:20-alpine

WORKDIR /home/node/app

COPY package.json package.json
COPY yarn.lock yarn.lock
RUN yarn install --immutable

# making nodejs folder where as guided in the AWS lambda layer docs
RUN mkdir -p output/nodejs

# copy node_modules to that folder
RUN cp -r node_modules output/nodejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as iam from 'aws-cdk-lib/aws-iam';
import * as rds from 'aws-cdk-lib/aws-rds';
import * as ssm from 'aws-cdk-lib/aws-ssm';
import { MicroserviceConfig, DbAuthType } from '../function/type';
import package_json from '../package.json';

export type PostgresManagerConfig = {
masterSecretName: string;
Expand Down Expand Up @@ -38,9 +39,21 @@ export class PostgresManagerStack extends Stack {
props.clusterResourceIdParameterName
);

const rdsLambdaProps : nodejs.NodejsFunctionProps = {
const dependencyLayer = new lambda.LayerVersion(this, 'DependenciesLayer', {
code: lambda.Code.fromDockerBuild(__dirname + '/../', {
cacheDisabled: true,
file: 'deploy/construct/layer/node_module.Dockerfile',
imagePath: 'home/node/app/output',
}),
compatibleArchitectures: [lambda.Architecture.ARM_64],
compatibleRuntimes: [lambda.Runtime.NODEJS_20_X],
});

const runtimeDependencies = Object.keys(package_json.dependencies);
const rdsLambdaProps: nodejs.NodejsFunctionProps = {
layers: [dependencyLayer],
bundling: { externalModules: runtimeDependencies },
timeout: Duration.minutes(5),
depsLockFilePath: __dirname + '/../yarn.lock',
handler: 'handler',
runtime: lambda.Runtime.NODEJS_20_X,
architecture: lambda.Architecture.ARM_64,
Expand Down Expand Up @@ -98,9 +111,7 @@ export class PostgresManagerStack extends Stack {
new iam.PolicyStatement({
actions: ['secretsmanager:CreateSecret', 'secretsmanager:TagResource'],
effect: iam.Effect.ALLOW,
resources: [
`arn:aws:secretsmanager:ap-southeast-2:${process.env.CDK_DEFAULT_ACCOUNT}:secret:*`,
],
resources: [`arn:aws:secretsmanager:ap-southeast-2:*:secret:*`],
}),
new iam.PolicyStatement({
actions: ['secretsmanager:GetRandomPassword'],
Expand Down
24 changes: 12 additions & 12 deletions lib/workload/stateless/postgres_manager/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1042,18 +1042,6 @@ __metadata:
languageName: node
linkType: hard

"lambda-with-rds@workspace:.":
version: 0.0.0-use.local
resolution: "lambda-with-rds@workspace:."
dependencies:
"@aws-sdk/client-secrets-manager": ^3.515.0
"@types/aws-lambda": ^8.10.134
"@types/pg": ^8
pg: ^8.11.3
typescript: ^5.3.3
languageName: unknown
linkType: soft

"obuf@npm:~1.1.2":
version: 1.1.2
resolution: "obuf@npm:1.1.2"
Expand Down Expand Up @@ -1233,6 +1221,18 @@ __metadata:
languageName: node
linkType: hard

"postgres-manager@workspace:.":
version: 0.0.0-use.local
resolution: "postgres-manager@workspace:."
dependencies:
"@aws-sdk/client-secrets-manager": ^3.515.0
"@types/aws-lambda": ^8.10.134
"@types/pg": ^8
pg: ^8.11.3
typescript: ^5.3.3
languageName: unknown
linkType: soft

"postgres-range@npm:^1.1.1":
version: 1.1.4
resolution: "postgres-range@npm:1.1.4"
Expand Down
Loading