James McCool commited on
Commit ·
3be2b97
1
Parent(s): ed8db46
updating python package and database process
Browse files- .streamlit/secrets.toml +3 -0
- Dockerfile +13 -6
- requirements.txt +2 -4
- src/database.py +13 -0
- src/streamlit_app.py +1 -12
.streamlit/secrets.toml
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
mongo_uri = "mongodb+srv://multichem:Xr1q5wZdXPbxdUmJ@testcluster.lgwtp5i.mongodb.net/?retryWrites=true&w=majority&appName=TestCluster"
|
| 2 |
+
private_key_id = "1005124050c80d085e2c5b344345715978dd9cc9"
|
| 3 |
+
client_email = "gspread-connection@sheets-api-connect-378620.iam.gserviceaccount.com"
|
Dockerfile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
FROM python:3.
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
|
@@ -11,14 +11,21 @@ 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 |
|
| 24 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
|
|
|
| 1 |
+
FROM python:3.13.5-slim
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
|
|
|
| 11 |
|
| 12 |
COPY requirements.txt ./
|
| 13 |
COPY src/ ./src/
|
| 14 |
+
COPY .streamlit/ ./.streamlit/
|
| 15 |
+
|
| 16 |
+
ENV MONGO_URI="mongodb+srv://multichem:Xr1q5wZdXPbxdUmJ@testcluster.lgwtp5i.mongodb.net/?retryWrites=true&w=majority&appName=TestCluster"
|
| 17 |
+
ENV PRIVATE_KEY_ID="1005124050c80d085e2c5b344345715978dd9cc9"
|
| 18 |
+
ENV CLIENT_EMAIL="gspread-connection@sheets-api-connect-378620.iam.gserviceaccount.com"
|
| 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 |
|
| 31 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
requirements.txt
CHANGED
|
@@ -1,11 +1,9 @@
|
|
| 1 |
-
altair
|
| 2 |
-
pandas
|
| 3 |
streamlit
|
| 4 |
gspread
|
| 5 |
openpyxl
|
| 6 |
matplotlib
|
| 7 |
-
pymongo
|
| 8 |
pulp
|
| 9 |
docker
|
| 10 |
plotly
|
| 11 |
-
scipy
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
streamlit
|
| 2 |
gspread
|
| 3 |
openpyxl
|
| 4 |
matplotlib
|
|
|
|
| 5 |
pulp
|
| 6 |
docker
|
| 7 |
plotly
|
| 8 |
+
scipy
|
| 9 |
+
pymongo
|
src/database.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pymongo
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
@st.cache_resource
|
| 6 |
+
def init_conn():
|
| 7 |
+
uri = os.getenv('mongo_uri')
|
| 8 |
+
client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000)
|
| 9 |
+
db = client["MLB_Database"]
|
| 10 |
+
|
| 11 |
+
return db
|
| 12 |
+
|
| 13 |
+
db = init_conn()
|
src/streamlit_app.py
CHANGED
|
@@ -1,22 +1,11 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import numpy as np
|
| 3 |
import pandas as pd
|
| 4 |
-
import pymongo
|
| 5 |
-
import os
|
| 6 |
import time
|
|
|
|
| 7 |
|
| 8 |
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["MLB_Database"]
|
| 15 |
-
|
| 16 |
-
return db
|
| 17 |
-
|
| 18 |
-
db = init_conn()
|
| 19 |
-
|
| 20 |
st.markdown("""
|
| 21 |
<style>
|
| 22 |
/* Tab styling */
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import numpy as np
|
| 3 |
import pandas as pd
|
|
|
|
|
|
|
| 4 |
import time
|
| 5 |
+
from database import db
|
| 6 |
|
| 7 |
st.set_page_config(layout="wide")
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
st.markdown("""
|
| 10 |
<style>
|
| 11 |
/* Tab styling */
|