Skip to content

Commit

Permalink
refactor(filemanager): manifest and workspace path
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalenic committed Mar 27, 2024
1 parent 99256ff commit 2d46997
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { RustFunction } from 'cargo-lambda-cdk';
import path from 'path';
import { exec } from 'cargo-lambda-cdk/lib/util';
import { randomUUID } from 'node:crypto';
import { print } from 'aws-cdk/lib/logging';

/**
* Properties for the database.
Expand Down Expand Up @@ -94,29 +95,36 @@ export class Function extends Construct {
`/` +
`${props.databaseSecret.secretValueFromJson('dbname').unsafeUnwrap()}`;

const manifestPath = path.join(__dirname, '..', '..', '..');
const workspacePath = path.join(__dirname, '..', '..', '..');
const manifestPath = path.join(workspacePath, props.package, 'Cargo.toml');
const uuid = randomUUID();

// This starts the container running postgres in order to compile queries using sqlx.
// It needs to be executed outside `beforeBundling`, because `beforeBundling` runs inside
// the container context, and docker compose needs to run outside of this context.
const output = exec(
'make',
['-s', 'docker-run', `DOCKER_PROJECT_NAME=${randomUUID()}`],
{ cwd: manifestPath, shell: true }
['-s', 'docker-run', `DOCKER_PROJECT_NAME=${uuid}`],
{ cwd: workspacePath, shell: true }
);
print(`running filemanager \`make -s docker-run DOCKER_PROJECT_NAME=${uuid}\``);

// Grab the last line only in case there are other outputs.
const address = output.stdout.toString().trim().match('.*$')?.pop();
const localDatabaseUrl = `postgresql://filemanager:filemanager@${address}/filemanager`; // pragma: allowlist secret
print(`the local filemanager database url is: ${localDatabaseUrl}`);

this._function = new RustFunction(this, 'RustFunction', {
manifestPath,
manifestPath: manifestPath,
binaryName: props.package,
bundling: {
environment: {
...props.buildEnvironment,
// Avoid permission issues by creating another target directory.
CARGO_TARGET_DIR: "target-cdk-docker-bundling",
// The bundling container needs to be able to connect to the container running postgres.
DATABASE_URL: `postgresql://filemanager:filemanager@${address}/filemanager`, // pragma: allowlist secret
}
DATABASE_URL: localDatabaseUrl,
},
},
memorySize: 128,
timeout: Duration.seconds(28),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"@aws-cdk/aws-lambda-python-alpha": "2.126.0-alpha.0",
"aws-cdk-lib": "^2.133.0",
"cargo-lambda-cdk": "^0.0.19",
"cargo-lambda-cdk": "^0.0.20",
"cdk-nag": "^2.28.27",
"constructs": "^10.2.69",
"dotenv": "^16.3.1",
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1680,15 +1680,15 @@ __metadata:
languageName: node
linkType: hard

"cargo-lambda-cdk@npm:^0.0.19":
version: 0.0.19
resolution: "cargo-lambda-cdk@npm:0.0.19"
"cargo-lambda-cdk@npm:^0.0.20":
version: 0.0.20
resolution: "cargo-lambda-cdk@npm:0.0.20"
dependencies:
js-toml: ^0.1.1
peerDependencies:
aws-cdk-lib: ^2.1.0
aws-cdk-lib: ^2.63.0
constructs: ^10.0.5
checksum: a2ad75973055b5b7ab3b4f7233643677befec10ea9b6a2e4a565dd61783c4247f383f6455b19986dd2ca8bf050c656bd0ebf89161ea46e7626e875585b9d606a
checksum: 407b3d9226dbee1b76a4a80c485a329da466eefaeb9afc71cd624bfedfe2f85adfeb107e4540d92ce16c4a799a15d622e3c6a48f3f879af63e564d892fb96fba
languageName: node
linkType: hard

Expand Down Expand Up @@ -3892,7 +3892,7 @@ __metadata:
"@typescript-eslint/parser": ^6.19.1
aws-cdk: ^2.133.0
aws-cdk-lib: ^2.133.0
cargo-lambda-cdk: ^0.0.19
cargo-lambda-cdk: ^0.0.20
cdk-nag: ^2.28.27
constructs: ^10.2.69
dotenv: ^16.3.1
Expand Down

0 comments on commit 2d46997

Please sign in to comment.