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 7c12886 commit e344aff
Showing 1 changed file with 5 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -109,48 +107,24 @@ 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,
binaryName: props.package,
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),
Expand Down

0 comments on commit e344aff

Please sign in to comment.