Skip to content

Commit

Permalink
chore(db): split DATABASE_URL into component env vars
Browse files Browse the repository at this point in the history
Signed-off-by: Thuan Vo <thuan.votann@gmail.com>
  • Loading branch information
tthvo committed Feb 13, 2024
1 parent 350cdaa commit e0cd9f1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
13 changes: 11 additions & 2 deletions app/web/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ PORT ?= 8080
LOG_FILE ?= privacypal-run.log
PRIVACYPAL_AUTH_MANAGER ?= cognito
PRIVACYPAL_DEBUG ?= true
DATABASE_URL = postgresql://privacypal:password@localhost:5432/privacypal
PRIVACYPAL_LAMBDA_NAME ?= processVideoContainer

PRIVACYPAL_TMP_BUCKET ?= privacypal-input
PRIVACYPAL_OUTPUT_BUCKET ?= privacypal-output

DATABASE ?= privacypal
DATABASE_USER ?= privacypal
DATABASE_PASSWORD ?= password
DATABASE_HOSTNAME ?= localhost
DATABASE_PORT ?= 5432

.PHONY: run
run: ## Run the web server as a standalone container.
$(IMAGE_BUILDER) run --name "$(CONTAINER_NAME)" \
Expand All @@ -63,7 +68,11 @@ run: ## Run the web server as a standalone container.
-e PRIVACYPAL_DEBUG="$(PRIVACYPAL_DEBUG)" \
-e PRIVACYPAL_AUTH_SECRET="$$(openssl rand -base64 32)" \
-e PRIVACYPAL_COOKIE_NAME="privacypal" \
-e DATABASE_URL="$(DATABASE_URL)" \
-e PRIVACYPAL_POSTGRES_USERNAME=$(DATABASE_USER) \
-e PRIVACYPAL_POSTGRES_PASSWORD=$(DATABASE_PASSWORD) \
-e PRIVACYPAL_POSTGRES_HOST=$(DATABASE_HOSTNAME) \
-e PRIVACYPAL_POSTGRES_PORT=$(DATABASE_PORT) \
-e PRIVACYPAL_POSTGRES_DATABASE=$(DATABASE) \
-e PRIVACYPAL_LAMBDA_NAME="$(PRIVACYPAL_LAMBDA_NAME)" \
-e PRIVACYPAL_OUTPUT_BUCKET="$(PRIVACYPAL_OUTPUT_BUCKET)" \
-e PRIVACYPAL_TMP_BUCKET="$(PRIVACYPAL_TMP_BUCKET)" \
Expand Down
6 changes: 5 additions & 1 deletion app/web/env.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ PRIVACYPAL_AUTH_MANAGER=cognito
PRIVACYPAL_DEBUG=true
PRIVACYPAL_AUTH_SECRET="0Fa2BOJrd3958qaZUa7pf1jEREoo6tU5rsx430bUp/k="
PRIVACYPAL_COOKIE_NAME="privacypal"
DATABASE_URL=postgresql://privacypal:password@localhost:5432/privacypal
PRIVACYPAL_POSTGRES_USERNAME=privacypal
PRIVACYPAL_POSTGRES_PASSWORD=password
PRIVACYPAL_POSTGRES_HOST=localhost
PRIVACYPAL_POSTGRES_PORT=5432
PRIVACYPAL_POSTGRES_DATABASE=privacypal
PRIVACYPAL_LAMBDA_NAME=processVideoContainer
PRIVACYPAL_OUTPUT_BUCKET=privacypal-output
PRIVACYPAL_TMP_BUCKET=privacypal-input
Expand Down
14 changes: 13 additions & 1 deletion app/web/src/lib/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@ import { PrismaClient } from "@prisma/client";
import { IS_PRODUCTION } from "./config";

const prismaClientSingleton = () => {
return new PrismaClient();
const userName = process.env.PRIVACYPAL_POSTGRES_USERNAME;
const host = process.env.PRIVACYPAL_POSTGRES_HOST;
const port = process.env.PRIVACYPAL_POSTGRES_PORT;
const database = process.env.PRIVACYPAL_POSTGRES_DATABASE;
const password = process.env.PRIVACYPAL_POSTGRES_PASSWORD;

return new PrismaClient({
datasources: {
db: {
url: `postgresql://${userName}:${password}@${host}:${port}/${database}`
}
}
});
};

type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;
Expand Down

0 comments on commit e0cd9f1

Please sign in to comment.