diff --git a/lib/workload/stateless/filemanager/deploy/constructs/functions/function.ts b/lib/workload/stateless/filemanager/deploy/constructs/functions/function.ts index eb245bcb1..a1611e4de 100644 --- a/lib/workload/stateless/filemanager/deploy/constructs/functions/function.ts +++ b/lib/workload/stateless/filemanager/deploy/constructs/functions/function.ts @@ -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. @@ -94,20 +95,27 @@ 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: { @@ -115,8 +123,8 @@ export class Function extends Construct { // 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), diff --git a/package.json b/package.json index f0e68761a..97747432e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/yarn.lock b/yarn.lock index 3d25bd61e..948a0e147 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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 @@ -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