email-classifier / Dockerfile
mrqadeer's picture
Initial project commit with code and figures
f6ea7de
Raw History Blame Contribute Delete
2.17 kB
FROM python:3.12-slim
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV STREAMLIT_SERVER_PORT=8501
ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0
WORKDIR /app
# Install system dependencies including curl for healthcheck and supervisor
RUN apt-get update && apt-get install -y \
build-essential \
wget \
curl \
supervisor \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user to run the application
RUN useradd -m -u 1000 appuser
# Copy the entire project directory
# .dockerignore should exclude .venv and other unnecessary files
COPY . .
# Install uv and dependencies
RUN pip install --no-cache-dir --upgrade pip && \
pip install uv && \
uv venv /app/.venv && \
. /app/.venv/bin/activate && \
uv pip install . && \
uv sync
# Set environment variable to use the venv
ENV PATH="/app/.venv/bin:$PATH"
# Create supervisor configuration
RUN mkdir -p /etc/supervisor/conf.d
COPY <<EOF /etc/supervisor/conf.d/supervisord.conf
[supervisord]
nodaemon=true
user=root
pidfile=/tmp/supervisord.pid
[program:fastapi]
command=/app/.venv/bin/uvicorn api.main:app --host 0.0.0.0 --port 8000
directory=/app
user=appuser
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:streamlit]
command=/app/.venv/bin/streamlit run app/main.py --server.port=8501 --server.address=0.0.0.0
directory=/app
user=appuser
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
EOF
# Create and set permissions for directories that need write access
RUN mkdir -p /.local && \
chown -R appuser:appuser /.local && \
mkdir -p /home/appuser/.cache && \
chown -R appuser:appuser /home/appuser && \
chown -R appuser:appuser /app && \
mkdir -p /tmp && \
chmod 777 /tmp
# Expose both ports
EXPOSE 8501 8000
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health && curl --fail http://localhost:8000/health
# Command to run both applications (stay as root for supervisor)
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]