47 lines
1.3 KiB
Docker
47 lines
1.3 KiB
Docker
# {{ cookiecutter.project_name }} - Dockerfile for Google Cloud Run
|
|
#
|
|
# Build:
|
|
# docker build -t {{ cookiecutter.project_slug }} .
|
|
#
|
|
# Run locally:
|
|
# docker run -p 8080:8080 -e DJANGO_SETTINGS_MODULE={{ cookiecutter.project_slug }}.settings.dev {{ cookiecutter.project_slug }}
|
|
|
|
FROM python:3.11-slim
|
|
|
|
# Install uv for faster dependency installation
|
|
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
|
|
|
|
# Set environment variables
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
ENV PYTHONUNBUFFERED=1
|
|
ENV PORT=8080
|
|
|
|
# Set work directory
|
|
WORKDIR /app
|
|
|
|
# Install system dependencies
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
build-essential \
|
|
libpq-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install Python dependencies (uv is much faster than pip)
|
|
COPY requirements.txt .
|
|
RUN uv pip install --system --no-cache -r requirements.txt
|
|
|
|
# Copy project files
|
|
COPY . .
|
|
|
|
# Collect static files (for WhiteNoise)
|
|
RUN python manage.py collectstatic --noinput --settings={{ cookiecutter.project_slug }}.settings.base || true
|
|
|
|
# Create non-root user for security
|
|
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
|
|
USER appuser
|
|
|
|
# Expose port
|
|
EXPOSE 8080
|
|
|
|
# Run gunicorn
|
|
CMD exec gunicorn --bind :$PORT --workers 2 --threads 4 --timeout 60 {{ cookiecutter.project_slug }}.wsgi:application
|