Skip to content

Commit

Permalink
fix(filemanager): use docker run to get unique containers with arbitr…
Browse files Browse the repository at this point in the history
…ary ports
  • Loading branch information
mmalenic committed Mar 25, 2024
1 parent f0c8890 commit 510480a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/workload/stateless/filemanager/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Example env file which sets the DATABASE_URL to a local postgres instance.
DATABASE_URL=postgresql://filemanager:filemanager@localhost:4321/filemanager #pragma: allowlist secret
FILEMANAGER_DATABASE_HOST=0.0.0.0
FILEMANAGER_DATABASE_PORT=4321
DATABASE_URL=postgresql://filemanager:filemanager@${FILEMANAGER_DATABASE_HOST}:${FILEMANAGER_DATABASE_PORT}/filemanager #pragma: allowlist secret
7 changes: 6 additions & 1 deletion lib/workload/stateless/filemanager/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
POSTGRES_DATABASE_URL ?= postgresql://filemanager:filemanager@localhost:4321/filemanager #pragma: allowlist secret
FILEMANAGER_DATABASE_HOST ?= localhost
FILEMANAGER_DATABASE_PORT ?= 4321
POSTGRES_DATABASE_URL ?= postgresql://filemanager:filemanager@${FILEMANAGER_DATABASE_HOST}:${FILEMANAGER_DATABASE_PORT}/filemanager #pragma: allowlist secret

export DATABASE_URL=$(POSTGRES_DATABASE_URL)

Expand All @@ -17,6 +19,9 @@ docker-postgres:
@docker compose up --wait -d postgres
docker-clean:
@docker compose down --volumes
docker-run:
@FILEMANAGER_DATABASE_HOST=0.0.0.0 FILEMANAGER_DATABASE_PORT=0 docker compose run -d --service-ports postgres | \
xargs -I {} docker port {} $(FILEMANAGER_DATABASE_PORT)

## Build related commands
build: docker-postgres
Expand Down
2 changes: 1 addition & 1 deletion lib/workload/stateless/filemanager/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ services:
- POSTGRES_PASSWORD=filemanager
- PGPORT=4321
ports:
- "4321:4321"
- "${FILEMANAGER_DATABASE_HOST}:${FILEMANAGER_DATABASE_PORT}:4321"
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export class Function extends Construct {
// 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.
exec('make', ['docker-postgres'], { cwd: manifestPath, shell: true });
const output = exec('make', ['docker-run'], { cwd: manifestPath, shell: true });
const address = output.stdout.toString().trim();

this._function = new RustFunction(this, 'RustFunction', {
manifestPath,
Expand All @@ -108,7 +109,7 @@ 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@localhost:4321/filemanager", // pragma: allowlist secret
DATABASE_URL: `postgresql://filemanager:filemanager@${address}/filemanager`, // pragma: allowlist secret
}
},
memorySize: 128,
Expand Down

0 comments on commit 510480a

Please sign in to comment.