78 lines
3.2 KiB
Docker
78 lines
3.2 KiB
Docker
# Stage 1: Base Image and System Dependencies
|
|
# ------------------------------------------
|
|
# Use an official Python slim image. These are multi-arch and will pull the arm64 variant on Apple Silicon.
|
|
# Choose the Python version matching your project requirement (e.g., 3.11, 3.12).
|
|
FROM python:3.11-slim AS base
|
|
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
|
|
|
# Set environment variables to prevent interactive prompts during package installations
|
|
ENV PYTHONDONTWRITEBYTECODE 1
|
|
ENV PYTHONUNBUFFERED 1
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
|
|
# Install essential system dependencies
|
|
# - build-essential: Required for compiling some Python packages with C extensions.
|
|
# - pkg-config: Helper tool for finding library compilation flags.
|
|
# - default-libmysqlclient-dev: Required for mysqlclient (MySQL/MariaDB adapter).
|
|
# (Replaced libpq-dev from previous version).
|
|
# - curl: Needed to download the uv installer script.
|
|
# Clean up apt cache afterwards to keep the image size down.
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends \
|
|
build-essential \
|
|
pkg-config \
|
|
default-libmysqlclient-dev \
|
|
curl \
|
|
clang \
|
|
&& apt-get clean \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Stage 2: Install uv
|
|
# -------------------
|
|
# Install uv using the recommended script.
|
|
# RUN curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
# Add uv to the PATH
|
|
# ENV PATH="/root/.cargo/bin:$PATH"
|
|
|
|
# Stage 3: Application Setup
|
|
# --------------------------
|
|
# Set the working directory inside the container
|
|
WORKDIR /app
|
|
|
|
# Copy dependency file(s)
|
|
# Ensure requirements.txt includes Django and all other necessary packages.
|
|
# COPY requirements.txt requirements.txt
|
|
# If you use pyproject.toml for dependencies primarily, copy it instead or as well:
|
|
COPY pyproject.toml pyproject.toml
|
|
|
|
# Install Python dependencies using uv from requirements.txt
|
|
# --system: Install packages into the system Python environment within the container (common for Docker)
|
|
# --no-cache: Avoid caching downloads/builds within this layer to keep it smaller
|
|
# RUN uv pip install --system --no-cache-dir -r requirements.txt
|
|
|
|
# NOTE: Removed the 'uv pip install .' command below as it caused the
|
|
# "Multiple top-level packages discovered" error. We typically only need
|
|
# to install dependencies from requirements.txt for running a Django app in Docker.
|
|
# Ensure your requirements.txt is complete.
|
|
# -----------------------------------------------------------------------------
|
|
# Or if using pyproject.toml (ensure it defines dependencies correctly):
|
|
|
|
ENV UV_LINK_MODE=copy
|
|
RUN uv pip install --system --no-cache-dir .
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
# Copy the rest of the application code into the container
|
|
COPY . .
|
|
|
|
# Collect static files
|
|
RUN uv run python cmcsales/manage.py collectstatic --noinput
|
|
|
|
# Expose the port the Django app runs on (adjust if you use a different port)
|
|
EXPOSE 8000
|
|
|
|
|
|
# Default command to run the application
|
|
# This is often overridden by docker-compose.yml, but it's good practice to have a default.
|
|
# Replace 'myproject' with your actual Django project directory name if different.
|
|
CMD ["uv", "run", "python", "cmcsales/manage.py", "runserver", "0.0.0.0:8000"] |