Skip to content

Commit 7b331b3

Browse files
bennosteinhubyrod
authored andcommitted
Pass postgres connection details/creds to web service through environment
1 parent 01b4b73 commit 7b331b3

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

examples/hackernews/kubernetes/web.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ spec:
3737
- name: SKIP_CONTROL_URL
3838
value:
3939
"http://haproxy-kubernetes-ingress.default.svc.cluster.local/control"
40+
- name: PG_HOST
41+
value: "rhn-pg.default.svc.cluster.local"

examples/hackernews/web_service/app.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,29 @@
66
import time
77
import os
88

9+
SKIP_CONTROL_URL = os.environ.get("SKIP_CONTROL_URL")
10+
11+
PG_HOST = os.environ.get("PG_HOST", "db")
12+
PG_PORT = int(os.environ.get("PG_PORT", 5432))
13+
PG_DATABASE = os.environ.get("PG_DATABASE", "postgres")
14+
PG_USER = os.environ.get("PG_USER", "postgres")
15+
PG_PASSWORD = os.environ.get("PG_PASSWORD", "change_me")
16+
917

1018
def get_db():
1119
conn = psycopg2.connect(
12-
host="db",
13-
user="postgres",
14-
password="change_me",
20+
host=PG_HOST,
21+
port=PG_PORT,
22+
user=PG_USER,
23+
password=PG_PASSWORD,
24+
dbname=PG_DATABASE,
1525
)
16-
1726
return conn
1827

1928

2029
app = Flask(__name__)
21-
2230
app.secret_key = b"53cr37_changeme"
2331

24-
SKIP_CONTROL_URL = os.environ.get("SKIP_CONTROL_URL")
25-
2632

2733
@app.before_request
2834
def ensure_session_cookie():

0 commit comments

Comments
 (0)