James McCool
commited on
Commit
·
51c1a0b
1
Parent(s):
e8db091
Enhance Dockerfile and Streamlit app for secret management and environment variable usage
Browse files- Added support for secret management in Dockerfile to expose the mongo_uri at build time and set it as the git remote URL.
- Updated Streamlit app to retrieve the MongoDB URI from environment variables instead of directly from secrets, improving flexibility in deployment.
- Dockerfile +5 -0
- src/streamlit_app.py +2 -1
Dockerfile
CHANGED
@@ -14,6 +14,11 @@ COPY src/ ./src/
|
|
14 |
|
15 |
RUN pip3 install -r requirements.txt
|
16 |
|
|
|
|
|
|
|
|
|
|
|
17 |
EXPOSE 8501
|
18 |
|
19 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
|
|
14 |
|
15 |
RUN pip3 install -r requirements.txt
|
16 |
|
17 |
+
# Expose the secret SECRET_EXAMPLE at buildtime and use its value as git remote URL
|
18 |
+
RUN --mount=type=secret,id=mongo_uri,mode=0444,required=true \
|
19 |
+
git init && \
|
20 |
+
git remote add origin $(cat /run/secrets/mongo_uri)
|
21 |
+
|
22 |
EXPOSE 8501
|
23 |
|
24 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
src/streamlit_app.py
CHANGED
@@ -2,12 +2,13 @@ import streamlit as st
|
|
2 |
import numpy as np
|
3 |
import pandas as pd
|
4 |
import pymongo
|
|
|
5 |
|
6 |
st.set_page_config(layout="wide")
|
7 |
|
8 |
@st.cache_resource
|
9 |
def init_conn():
|
10 |
-
uri =
|
11 |
client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000)
|
12 |
db = client["MLB_Database"]
|
13 |
|
|
|
2 |
import numpy as np
|
3 |
import pandas as pd
|
4 |
import pymongo
|
5 |
+
import os
|
6 |
|
7 |
st.set_page_config(layout="wide")
|
8 |
|
9 |
@st.cache_resource
|
10 |
def init_conn():
|
11 |
+
uri = os.getenv('mongo_uri')
|
12 |
client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000)
|
13 |
db = client["MLB_Database"]
|
14 |
|