Merge pull request 'refactor(docker): replace uv with pip and move Django commands to runtime' (#20) from feature/meetings into main

Reviewed-on: https://gitea.blackbusinesslabs.com/ATTUNE-HEART-THERAPY/alternative-backend-service/pulls/20
This commit is contained in:
Saani 2025-11-23 19:12:56 +00:00
commit ceca8895e2

View File

@ -1,37 +1,32 @@
FROM debian:bookworm-slim
FROM python:3.12-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Environment settings
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Set work directory
WORKDIR /app
# System dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl wget \
&& rm -rf /var/lib/apt/lists/*
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.local/bin:${PATH}"
# Copy dependency file
COPY requirements.txt .
# Copy only the dependency definitions first to leverage Docker's layer caching
COPY pyproject.toml uv.lock .python-version ./
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Install Python dependencies for production
RUN uv sync --no-group dev --group prod
# Copy the rest of the application code into the container
# Copy project files
COPY . .
# Collect the static files
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 port
EXPOSE 8000
# Run with gunicorn
CMD ["uv", "run", "--no-sync", "gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "--access-logfile", "-", "--error-logfile", "-", "--log-level", "info", "config.wsgi:application"]
# Run migrations + collectstatic + gunicorn at runtime
CMD \
python manage.py migrate && \
python manage.py collectstatic --noinput && \
gunicorn config.wsgi:application --bind 0.0.0.0:8000 --workers 3