Рефакторинг и деплоинг
This commit is contained in:
@@ -1,43 +1,57 @@
|
||||
# Use Python 3.13 slim image as base
|
||||
FROM python:3.13.9-slim
|
||||
FROM python:3.13-slim
|
||||
|
||||
# Set environment variables
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
PYTHONPATH=/app \
|
||||
DJANGO_SETTINGS_MODULE=dbapp.settings.production
|
||||
|
||||
# Install system dependencies including GDAL and PostGIS dependencies
|
||||
# Install system dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
gdal-bin \
|
||||
libgdal-dev \
|
||||
proj-bin \
|
||||
proj-data \
|
||||
libproj-dev \
|
||||
libproj25 \
|
||||
libgeos-dev \
|
||||
postgresql-client \
|
||||
libgeos-c1v5 \
|
||||
build-essential \
|
||||
postgresql-client \
|
||||
libpq-dev \
|
||||
libpq5 \
|
||||
netcat-openbsd \
|
||||
gcc \
|
||||
g++ \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Set environment variables
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1
|
||||
|
||||
# Set work directory
|
||||
WORKDIR /app
|
||||
|
||||
# Upgrade pip
|
||||
RUN pip install --upgrade pip
|
||||
|
||||
# Copy requirements file
|
||||
COPY requirements.txt ./
|
||||
|
||||
# Install dependencies
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy project files
|
||||
COPY pyproject.toml uv.lock ./
|
||||
|
||||
# Install uv and dependencies
|
||||
RUN pip install --no-cache-dir uv && \
|
||||
uv sync --frozen --no-dev
|
||||
|
||||
# Copy project code (после установки зависимостей для лучшего кэширования)
|
||||
COPY . .
|
||||
|
||||
# Collect static files
|
||||
RUN uv run manage.py collectstatic --noinput
|
||||
# Create directories
|
||||
RUN mkdir -p /app/staticfiles /app/logs /app/media
|
||||
|
||||
# Set permissions for entrypoint
|
||||
RUN chmod +x /app/entrypoint.sh
|
||||
|
||||
# Create non-root user
|
||||
RUN useradd --create-home --shell /bin/bash app && \
|
||||
chown -R app:app /app
|
||||
|
||||
USER app
|
||||
|
||||
# Expose port
|
||||
EXPOSE 8000
|
||||
|
||||
# Run gunicorn server
|
||||
CMD [".venv/bin/gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "dbapp.wsgi:application"]
|
||||
# Run entrypoint script
|
||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||
|
||||
Reference in New Issue
Block a user