Skip to content

Commit ecbf584

Browse files
committed
feat: load app variables from env variables and disable password auth
1 parent bb053a7 commit ecbf584

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

docker-compose.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ services:
1212
ports:
1313
- "3000:3000"
1414
environment:
15-
- name=postgres
16-
- password=secret
1715
- host=db
16+
- name=postgres
1817
- dbname=postgres
1918

2019
db:
@@ -23,7 +22,7 @@ services:
2322
environment:
2423
- POSTGRES_DB=postgres
2524
- POSTGRES_USER=postgres
26-
- POSTGRES_PASSWORD=secret
25+
- POSTGRES_HOST_AUTH_METHOD=trust
2726
volumes:
2827
- ./db/:/opt/
2928
- ./scripts/upload.sh:/opt/upload.sh

rates/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import os
12
DB = {
2-
"name": "postgres",
3-
"user": "postgres",
4-
"password": "secret",
5-
"host": "db"
3+
"name": str(os.getenv("name", "postgres")),
4+
"user": str(os.getenv("user", "postgres")),
5+
"host": str(os.getenv("host", "localhost"))
66
}

rates/rates.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
def get_db_conn(db_config):
1212
""" Create a database connection. """
1313
return psycopg2.connect(
14-
"dbname='{}' user='{}' password='{}' host='{}'".format(
14+
"dbname='{}' user='{}' host='{}'".format(
1515
db_config["name"],
1616
db_config["user"],
17-
db_config["password"],
1817
db_config["host"]
1918
)
2019
)

scripts/start.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#!/usr/bin/env bash
22
echo "** Starting the app and db"
33
docker compose up -d
4+
45
echo "** Sleeping for 10 sec to ensure db services are running before uploading dump data"
56
sleep 10
7+
68
echo "** Uploading dump data & then sleeping for 5 sec **"
79
docker compose exec db /bin/bash ./opt/upload.sh
810
sleep 5
9-
echo "Performing Health Check on the App"
11+
12+
echo "** Performing Health Check on the App **"
1013
curl "http://127.0.0.1:3000/"

0 commit comments

Comments
 (0)