From e344aff5c73f893869fe3cb302cb4c588fd1e679 Mon Sep 17 00:00:00 2001 From: Marko Malenic Date: Wed, 27 Mar 2024 09:48:17 +1100 Subject: [PATCH] refactor(filemanager): manifest and workspace path --- .../deploy/constructs/functions/function.ts | 36 +++---------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/lib/workload/stateless/filemanager/deploy/constructs/functions/function.ts b/lib/workload/stateless/filemanager/deploy/constructs/functions/function.ts index 6fc5827d3..a1611e4de 100644 --- a/lib/workload/stateless/filemanager/deploy/constructs/functions/function.ts +++ b/lib/workload/stateless/filemanager/deploy/constructs/functions/function.ts @@ -1,5 +1,5 @@ import { Construct } from 'constructs'; -import { AssetStaging, BundlingFileAccess, Duration } from 'aws-cdk-lib'; +import { Duration } from 'aws-cdk-lib'; import { ISecurityGroup, IVpc, SecurityGroup, SubnetType } from 'aws-cdk-lib/aws-ec2'; import { Architecture, Version } from 'aws-cdk-lib/aws-lambda'; import { ManagedPolicy, PolicyStatement, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam'; @@ -9,7 +9,6 @@ import path from 'path'; import { exec } from 'cargo-lambda-cdk/lib/util'; import { randomUUID } from 'node:crypto'; import { print } from 'aws-cdk/lib/logging'; -import * as fs from 'fs'; /** * Properties for the database. @@ -100,7 +99,6 @@ export class Function extends Construct { const manifestPath = path.join(workspacePath, props.package, 'Cargo.toml'); const uuid = randomUUID(); - print(`running filemanager docker-run with project name: ${uuid}`); // 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. @@ -109,13 +107,12 @@ export class Function extends Construct { ['-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}`); - console.log(JSON.stringify(address)); - const a = output.stdout.toString().trim(); - console.log(JSON.stringify(a)); this._function = new RustFunction(this, 'RustFunction', { manifestPath: manifestPath, @@ -123,34 +120,11 @@ export class Function extends Construct { bundling: { environment: { ...props.buildEnvironment, - // // Avoid permission issues by creating another target directory. - // CARGO_TARGET_DIR: "target-cdk-docker-bundling", + // 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: localDatabaseUrl, }, - commandHooks: { - beforeBundling(inputDir: string, outputDir: string): string[] { - return []; - }, - afterBundling(inputDir: string, outputDir: string): string[] { - console.log(manifestPath); - console.log(`input: ${inputDir}`); - console.log(`output: ${outputDir}`); - - // console.log(AssetStaging.BUNDLING_OUTPUT_DIR); - fs.readdirSync('/tmp').forEach(file => { - if (fs.existsSync(file) && fs.lstatSync(file).isDirectory()) { - fs.readdirSync(file).forEach(inner => { - console.log(inner); - }) - } - console.log(file); - }); - - console.log(`dir: ${__dirname}`); - return []; - } - } }, memorySize: 128, timeout: Duration.seconds(28),