fixes
This commit is contained in:
73
dbapp/Dockerfile.prod
Normal file
73
dbapp/Dockerfile.prod
Normal file
@@ -0,0 +1,73 @@
|
||||
# Multi-stage build for production
|
||||
FROM python:3.13-slim as requirements-stage
|
||||
|
||||
# Install system dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
gdal-bin \
|
||||
libgdal-dev \
|
||||
proj-bin \
|
||||
proj-data \
|
||||
libproj-dev \
|
||||
libgeos-dev \
|
||||
build-essential \
|
||||
libpq-dev \
|
||||
gcc \
|
||||
g++ \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Python dependencies for GDAL
|
||||
RUN pip install --upgrade pip && \
|
||||
pip install --no-cache-dir GDAL==$(gdal-config --version)
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy project requirements
|
||||
COPY pyproject.toml uv.lock ./
|
||||
|
||||
# Install uv package manager
|
||||
RUN pip install --upgrade pip && pip install uv
|
||||
|
||||
# Install dependencies using uv
|
||||
RUN uv pip install --system --only-binary=gdal,shapely,pyproj --no-cache-dir -r uv.lock
|
||||
|
||||
|
||||
# Production stage
|
||||
FROM python:3.13-slim
|
||||
|
||||
# Install runtime system dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
gdal-bin \
|
||||
libgdal30 \
|
||||
libproj25 \
|
||||
libgeos-c1v5 \
|
||||
postgresql-client \
|
||||
libpq5 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Set environment variables
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
DJANGO_SETTINGS_MODULE=dbapp.settings.production
|
||||
|
||||
# Set work directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy Python dependencies from previous stage
|
||||
COPY --from=requirements-stage /usr/local/lib/python3.13/site-packages /usr/local/lib/python3.13/site-packages
|
||||
COPY --from=requirements-stage /usr/local/bin /usr/local/bin
|
||||
|
||||
# Copy project
|
||||
COPY . .
|
||||
|
||||
# Create non-root user for security
|
||||
RUN useradd --create-home --shell /bin/bash app && chown -R app:app /app
|
||||
USER app
|
||||
|
||||
# Collect static files
|
||||
RUN python manage.py collectstatic --noinput
|
||||
|
||||
# Expose port
|
||||
EXPOSE 8000
|
||||
|
||||
# Run gunicorn server
|
||||
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "--timeout", "120", "dbapp.wsgi:application"]
|
||||
Reference in New Issue
Block a user