Skip to content

Commit

Permalink
refactor(filemanager): push uuid creation to CDK code
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalenic committed Mar 26, 2024
1 parent 4da0a4e commit 99256ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
21 changes: 11 additions & 10 deletions lib/workload/stateless/filemanager/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
.EXPORT_ALL_VARIABLES:

## Database host ip address
FILEMANAGER_DATABASE_HOST ?= 0.0.0.0
## Database port
FILEMANAGER_DATABASE_PORT ?= 4321
## Database connection url
DATABASE_URL ?= postgresql://filemanager:filemanager@${FILEMANAGER_DATABASE_HOST}:${FILEMANAGER_DATABASE_PORT}/filemanager #pragma: allowlist secret
## Override the default project name
DOCKER_PROJECT_NAME ?= filemanager

## Default target
default: help
Expand All @@ -12,18 +17,18 @@ all: build

## Docker related targets
up:
@docker compose up --wait -d
@docker compose -p "$(DOCKER_PROJECT_NAME)" up --wait -d
down:
@docker compose down
@docker compose -p "$(DOCKER_PROJECT_NAME)" down
docker-postgres:
@docker compose up --wait -d postgres
@docker compose -p "$(DOCKER_PROJECT_NAME)" up --wait -d postgres
docker-clean:
@docker compose down --volumes
@docker compose -p "$(DOCKER_PROJECT_NAME)" down --volumes
docker-build:
@docker compose build
@docker compose -p "$(DOCKER_PROJECT_NAME)" build
docker-run: docker-build
@FILEMANAGER_DATABASE_HOST=0.0.0.0 FILEMANAGER_DATABASE_PORT=0 \
docker compose -p "$($(MAKE) -s uuid)" run -d --service-ports postgres | xargs -I {} docker port {} 4321
docker compose -p "$(DOCKER_PROJECT_NAME)" run -d --service-ports postgres | xargs -I {} docker port {} 4321

## Build related commands
build: docker-postgres
Expand Down Expand Up @@ -51,10 +56,6 @@ clean: docker-clean
psql:
@docker compose exec postgres psql filemanager -U filemanager

## Generate a uuid
uuid:
@python -c "import uuid; print(uuid.uuid4())"

## Help text
help:
@printf "The filemanager Makefile.\n\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ISecret } from 'aws-cdk-lib/aws-secretsmanager';
import { RustFunction } from 'cargo-lambda-cdk';
import path from 'path';
import { exec } from 'cargo-lambda-cdk/lib/util';
import { randomUUID } from 'node:crypto';

/**
* Properties for the database.
Expand Down Expand Up @@ -97,7 +98,11 @@ 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.
const output = exec('make', ['-s', 'docker-run'], { cwd: manifestPath, shell: true });
const output = exec(
'make',
['-s', 'docker-run', `DOCKER_PROJECT_NAME=${randomUUID()}`],
{ cwd: manifestPath, shell: true }
);
// Grab the last line only in case there are other outputs.
const address = output.stdout.toString().trim().match('.*$')?.pop();

Expand Down

0 comments on commit 99256ff

Please sign in to comment.