57 lines
1.4 KiB
Docker
57 lines
1.4 KiB
Docker
# Use Python 3.11 slim image
|
|
FROM python:3.11-slim-bookworm
|
|
|
|
# Set environment variables
|
|
ENV PYTHONUNBUFFERED=1
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
ENV FLASK_ENV=production
|
|
ENV FLASK_SECRET=production-secret-change-me
|
|
|
|
# Find location of apt sources list and change to a faster mirror
|
|
RUN [ -f /etc/apt/sources.list ] && \
|
|
echo "/etc/apt/sources.list exists, proceeding to modify it." \
|
|
&& sed -i 's|http://deb.debian.org/debian|https://mirror.init7.net/debian|g' /etc/apt/sources.list \
|
|
|| \
|
|
(echo "/etc/apt/sources.list does not exist, exiting.")
|
|
|
|
# Install system dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
gcc \
|
|
default-libmysqlclient-dev \
|
|
default-mysql-client \
|
|
pkg-config \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Create app directory
|
|
WORKDIR /app
|
|
|
|
# Copy requirements first for better caching
|
|
COPY requirements.txt .
|
|
|
|
# Install Python dependencies
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Copy application code
|
|
COPY . .
|
|
|
|
# Create necessary directories
|
|
RUN mkdir -p cache logs
|
|
|
|
# Expose port
|
|
EXPOSE 8000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
|
CMD curl -f http://localhost:8000/ || exit 1
|
|
|
|
# Copy entrypoint script
|
|
COPY docker-entrypoint.sh /usr/local/bin/
|
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
|
|
|
# Set entrypoint
|
|
ENTRYPOINT ["docker-entrypoint.sh"]
|
|
|
|
# Run gunicorn
|
|
CMD ["gunicorn", "--config", "gunicorn.conf.py", "web.app:app"]
|