James McCool commited on
Commit
6c387a5
·
1 Parent(s): 9a655f5

Enhance Dockerfile and Streamlit app configuration by adding user management and environment variable handling for MongoDB connection. Introduce secrets management for sensitive data and update requirements installation process. New secrets.toml file created for storing MongoDB URI.

Browse files
Files changed (3) hide show
  1. .streamlit/secrets.toml +1 -0
  2. Dockerfile +12 -5
  3. src/streamlit_app.py +4 -1
.streamlit/secrets.toml ADDED
@@ -0,0 +1 @@
 
 
1
+ mongo_uri = "mongodb+srv://multichem:[email protected]/?retryWrites=true&w=majority&appName=TestCluster"
Dockerfile CHANGED
@@ -11,13 +11,20 @@ RUN apt-get update && apt-get install -y \
11
 
12
  COPY requirements.txt ./
13
  COPY src/ ./src/
 
 
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
 
 
11
 
12
  COPY requirements.txt ./
13
  COPY src/ ./src/
14
+ COPY .streamlit/ ./.streamlit/
15
+
16
 
 
17
 
18
+ ENV MONGO_URI="mongodb+srv://multichem:[email protected]/?retryWrites=true&w=majority&appName=TestCluster"
19
+ RUN useradd -m -u 1000 user
20
+ USER user
21
+ ENV HOME=/home/user\
22
+ PATH=/home/user/.local/bin:$PATH
23
+ WORKDIR $HOME/app
24
+ RUN pip install --no-cache-dir --upgrade pip
25
+ COPY --chown=user . $HOME/app
26
+
27
+ RUN pip3 install -r requirements.txt
28
 
29
  EXPOSE 8501
30
 
src/streamlit_app.py CHANGED
@@ -9,7 +9,10 @@ st.set_page_config(layout="wide")
9
 
10
  @st.cache_resource
11
  def init_conn():
12
- uri = os.getenv('mongo_uri')
 
 
 
13
  client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000)
14
  db = client["PGA_Database"]
15
 
 
9
 
10
  @st.cache_resource
11
  def init_conn():
12
+ # Try to get from environment variable first, fall back to secrets
13
+ uri = os.getenv('MONGO_URI')
14
+ if not uri:
15
+ uri = st.secrets['mongo_uri']
16
  client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000)
17
  db = client["PGA_Database"]
18