71 lines
1.6 KiB
Docker
71 lines
1.6 KiB
Docker
# QR Code Generator - Dockerfile
|
|
# Multi-stage build for optimized container size
|
|
|
|
FROM python:3.11-slim as builder
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Install system dependencies for Pillow and cairosvg
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
gcc \
|
|
libjpeg-dev \
|
|
zlib1g-dev \
|
|
libcairo2-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy requirements file
|
|
COPY requirements.txt .
|
|
|
|
# Install Python dependencies
|
|
RUN pip install --no-cache-dir --user -r requirements.txt
|
|
|
|
|
|
# Final stage
|
|
FROM python:3.11-slim
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Install runtime dependencies
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
libcairo2 \
|
|
libjpeg62-turbo \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy Python dependencies from builder
|
|
COPY --from=builder /root/.local /root/.local
|
|
|
|
# Copy application code
|
|
COPY app.py .
|
|
COPY utils/ ./utils/
|
|
|
|
# Create directory for Streamlit config
|
|
RUN mkdir -p /root/.streamlit
|
|
|
|
# Configure Streamlit
|
|
RUN echo '\
|
|
[server]\n\
|
|
headless = true\n\
|
|
address = "0.0.0.0"\n\
|
|
port = 8501\n\
|
|
enableCORS = false\n\
|
|
enableXsrfProtection = true\n\
|
|
\n\
|
|
[browser]\n\
|
|
gatherUsageStats = false\n\
|
|
' > /root/.streamlit/config.toml
|
|
|
|
# Update PATH to include local Python packages
|
|
ENV PATH=/root/.local/bin:$PATH
|
|
|
|
# Expose Streamlit port
|
|
EXPOSE 8501
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD python -c "import requests; requests.get('http://localhost:8501/_stcore/health')"
|
|
|
|
# Run the application
|
|
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501"]
|