DRF_Template/Dockerfile

43 lines
No EOL
1.1 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Stage 1: Builder
FROM python:3.13.7-slim AS builder
# Install uv binary from its official docker repository
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Install OS-level dependencies(needed for compiling python packages)
RUN apt-get update && apt-get install -y --no-install-recommends \
curl build-essential && rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy dependency management files
# (Only pyproject.toml and uv.lock file is needed to replicate the environment))
COPY pyproject.toml uv.lock /app/
# Use uv to install all project dependenies in a virtual environment
RUN uv sync --frozen --compile-bytecode
# Stage 2: Runtime
FROM python:3.13.7-slim AS runtime
# Environment variables
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
WORKDIR /app
# Copy the virtual environment from the builder stage
COPY --from=builder /app /app
# Add the virtual environments binary directory to PATH
ENV PATH="/app/.venv/bin:$PATH"
# Copy project files
COPY . /app/
RUN chmod +x /app/.docker/start.sh
# Expose Django's default port
EXPOSE 8000
ENTRYPOINT [ "/app/.docker/start.sh" ]