Skip to content

Update Dockerfile #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,53 @@
# First, build the application in the `/app` directory.
# ---- Stage 1: Builder ----
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder

# Install system build tools needed for compiling CFFI and dependencies
RUN apt-get update && apt-get install -y \
build-essential \
gcc \
libffi-dev \
python3-dev \
&& rm -rf /var/lib/apt/lists/*

ENV UV_COMPILE_BYTECODE=1
ENV UV_LINK_MODE=copy
WORKDIR /app

# Install dependencies without dev packages
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project --no-dev

# Copy all source files
ADD . /app

# Sync again to install any local project dependencies
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev

# Then, use a final image without uv
# ---- Stage 2: Runtime ----
FROM python:3.12-slim-bookworm

# Copy the application from the builder
# Create app user (optional security)
RUN useradd -m app

# Copy from builder
COPY --from=builder --chown=app:app /app /app

# Set working dir
WORKDIR /app

# Set environment variables
# Set environment
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PATH="/app/.venv/bin:$PATH"

# Expose port 8000
# Set permissions
USER app

# Expose port
EXPOSE 8000

# Use gunicorn on port 8000
CMD ["gunicorn", "--bind", ":8000", "--workers", "2", "django_project.wsgi"]
# Start server with Gunicorn
CMD ["gunicorn", "--bind", ":8000", "--workers", "2", "django_project.wsgi"]