Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(filemanager): use docker run to get unique containers #184

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading