52 lines
1.4 KiB
Docker
52 lines
1.4 KiB
Docker
# Use specific version instead of 'latest' for reproducible builds
|
|
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11-slim
|
|
|
|
# Set environment variables for Python optimization
|
|
ENV PYTHONUNBUFFERED=1
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
ENV PYTHONPATH=/app
|
|
ENV PIP_NO_CACHE_DIR=1
|
|
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
|
|
|
|
# Create non-root user for security
|
|
RUN groupadd -r sba && useradd -r -g sba sba
|
|
|
|
# Set working directory
|
|
WORKDIR /usr/src/app
|
|
|
|
# Install system dependencies in a single layer
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
gcc \
|
|
libpq-dev \
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
&& apt-get clean
|
|
|
|
# Copy requirements first for better layer caching
|
|
COPY requirements.txt ./
|
|
|
|
# Install Python dependencies with optimizations
|
|
RUN pip install --no-cache-dir --upgrade pip && \
|
|
pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Copy application code
|
|
COPY ./app /app/app
|
|
|
|
# Create necessary directories and set permissions
|
|
RUN mkdir -p /usr/src/app/storage /usr/src/app/logs && \
|
|
chown -R sba:sba /usr/src/app && \
|
|
chmod -R 755 /usr/src/app
|
|
|
|
# Health check for container monitoring
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD curl -f http://localhost:80/health || exit 1
|
|
|
|
# Switch to non-root user
|
|
USER sba
|
|
|
|
# Expose port
|
|
EXPOSE 80
|
|
|
|
# Add labels for metadata
|
|
LABEL maintainer="SBA League Management"
|
|
LABEL version="1.0"
|
|
LABEL description="Major Domo Database API" |