refactor(docker): replace uv with pip and move Django commands to runtime
Replace uv package manager with standard pip for dependency management. Switch base image from debian:bookworm-slim to python:3.12-slim to include Python runtime by default. Key changes: - Remove uv installation and configuration - Use requirements.txt instead of pyproject.toml/uv.lock - Install dependencies with pip instead of uv sync - Move collectstatic and migrate from build-time to runtime in CMD - Simplify gunicorn command invocation This simplifies the build process and makes the image more portable by using standard Python tooling. Running migrations and collectstatic at container startup ensures they execute against the correct database and storage backend.
This commit is contained in:
parent
0a02f1db14
commit
e722cbe311
37
dockerfile
37
dockerfile
@ -1,37 +1,32 @@
|
|||||||
FROM debian:bookworm-slim
|
FROM python:3.12-slim
|
||||||
|
|
||||||
# Set environment variables
|
# Environment settings
|
||||||
ENV PYTHONDONTWRITEBYTECODE 1
|
ENV PYTHONDONTWRITEBYTECODE=1
|
||||||
ENV PYTHONUNBUFFERED 1
|
ENV PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
# Set work directory
|
# Set work directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# System dependencies
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
build-essential \
|
build-essential \
|
||||||
curl wget \
|
curl wget \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
|
# Copy dependency file
|
||||||
ENV PATH="/root/.local/bin:${PATH}"
|
COPY requirements.txt .
|
||||||
|
|
||||||
# Copy only the dependency definitions first to leverage Docker's layer caching
|
# Install Python dependencies
|
||||||
COPY pyproject.toml uv.lock .python-version ./
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
# Install Python dependencies for production
|
# Copy project files
|
||||||
RUN uv sync --no-group dev --group prod
|
|
||||||
|
|
||||||
# Copy the rest of the application code into the container
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Collect the static files
|
# Expose port
|
||||||
RUN uv run --no-sync ./manage.py collectstatic --noinput
|
|
||||||
|
|
||||||
# Migrate the database
|
|
||||||
RUN uv run --no-sync ./manage.py migrate
|
|
||||||
|
|
||||||
# Expose the port Gunicorn will run on
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
# Run with gunicorn
|
# Run migrations + collectstatic + gunicorn at runtime
|
||||||
CMD ["uv", "run", "--no-sync", "gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "--access-logfile", "-", "--error-logfile", "-", "--log-level", "info", "config.wsgi:application"]
|
CMD \
|
||||||
|
python manage.py migrate && \
|
||||||
|
python manage.py collectstatic --noinput && \
|
||||||
|
gunicorn config.wsgi:application --bind 0.0.0.0:8000 --workers 3
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user