Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker deployment test #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
__pycache__
*.pyc
*.pyo
*.pyd
.Python
env
pip-log.txt
pip-delete-this-directory.txt
.tox
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.log
.pytest_cache
.venv
.DS_Store
Thumbs.db
4 changes: 4 additions & 0 deletions .streamlit/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[server]
headless = true
enableCORS = false
enableXsrfProtection = false
69 changes: 69 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Use the RapidFort image as the base
FROM rapidfort/python-chromedriver:latest-arm64

# Set environment variables
ENV PYTHON_VERSION=3.11.6

# Install dependencies required to build Python from source
RUN apt-get update && apt-get install -y \
wget \
build-essential \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
libffi-dev \
libncursesw5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
liblzma-dev \
&& rm -rf /var/lib/apt/lists/*

# Download, extract, and compile Python 3.11
RUN wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz \
&& tar xzf Python-${PYTHON_VERSION}.tgz \
&& cd Python-${PYTHON_VERSION} \
&& ./configure --enable-optimizations \
&& make -j$(nproc) \
&& make altinstall \
&& cd .. \
&& rm -rf Python-${PYTHON_VERSION}*

# Set Python 3.11 as the default Python version
RUN update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.11 1

# Install pip for Python 3.11
RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11

# Copy requirements and install Python dependencies
COPY requirements.txt /app/requirements.txt
RUN python3.11 -m pip install --no-cache-dir -r /app/requirements.txt

# Set the working directory and copy the application code
WORKDIR /app
COPY . .

# Ensure that the necessary environment variables are set
ENV PYTHONUNBUFFERED=1
ENV DISPLAY=:99

# Create Streamlit configuration
RUN mkdir -p /root/.streamlit
RUN echo "\
[server]\n\
enableCORS = false\n\
enableXsrfProtection = false\n\
" > /root/.streamlit/config.toml

# Start Xvfb, Chromium, and Streamlit
COPY start.sh /app/start.sh
RUN chmod +x /app/start.sh

# Expose the port Streamlit runs on
EXPOSE 8501

# Set the entrypoint to the start script
CMD ["/app/start.sh"]
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.8'

services:
streamlit-app:
build: .
ports:
- "8501:8501"
volumes:
- ./data:/app/data
# Add volume for Chrome data if needed
- ~/.cache/selenium:/root/.cache/selenium
environment:
- PYTHONUNBUFFERED=1
- DISPLAY=:99
shm_size: '2gb' # Increased shared memory for Chrome
restart: unless-stopped
4 changes: 4 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
Xvfb :99 -screen 0 1920x1080x16 &
sleep 1
streamlit run main.py --server.address=0.0.0.0 --server.port=8501