From a30370c8276f7bdbb9c61e25ed1819373c1f2f5f Mon Sep 17 00:00:00 2001 From: Farhan Khan Date: Fri, 24 Jan 2025 21:30:25 +0000 Subject: [PATCH] Updating postgres variables --- docker-compose.yml | 20 +++++++++++++------- restapi/db.go | 3 ++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 92ea803..2e95952 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,11 @@ services: fedilogue: - build: fedilogger/ + build: fedilogue/ + environment: + POSTGRES_USER: $POSTGRES_USER + POSTGRES_PASSWORD: $POSTGRES_PASSWORD + POSTGRES_HOSTNAME: $POSTGRES_HOSTNAME + POSTGRES_DB: $POSTGRES_DB depends_on: - db ports: @@ -10,16 +15,17 @@ services: ports: - "127.0.0.1:6431:6432" environment: - POSTGRES_USER: $PGUSER - POSTGRES_PASSWORD: $PGPASS - POSTGRES_DB: $PGDATABASE + POSTGRES_USER: $POSTGRES_USER + POSTGRES_PASSWORD: $POSTGRES_PASSWORD + POSTGRES_HOSTNAME: $POSTGRES_HOSTNAME + POSTGRES_DB: $POSTGRES_DB depends_on: - db db: image: postgres:alpine environment: - POSTGRES_USER: $PGUSER - POSTGRES_PASSWORD: $PGPASS - POSTGRES_DB: $PGDATABASE + POSTGRES_USER: $POSTGRES_USER + POSTGRES_PASSWORD: $POSTGRES_PASSWORD + POSTGRES_DB: $POSTGRES_DB volumes: - ./postgres-data:/var/lib/postgresql diff --git a/restapi/db.go b/restapi/db.go index 7d4e54f..5de9979 100644 --- a/restapi/db.go +++ b/restapi/db.go @@ -11,7 +11,8 @@ var pool *pgxpool.Pool func getDbPool() *pgxpool.Pool { // Setup Database - pool, err := pgxpool.Connect(context.Background(), os.Getenv("DATABASE_URL")) + dburl := "postgres://" + os.Getenv("POSTGRES_USER") + ":" +u os.Getenv("POSTGRES_PASSWORD") + "@" + os.Getenv("POSTGRES_HOSTNAME") + "/" + os.Getenv("POSTGRES_DB") + pool, err := pgxpool.Connect(context.Background(), dburl) if err != nil { log.Fatal("Unable to connect to database:", err) }