Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (53 loc) · 1.63 KB
/
Copy pathDockerfile
File metadata and controls
70 lines (53 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# syntax=docker/dockerfile:1.4
ARG PYTHON_VERSION=3.13
############################
# 1. Builder stage: build wheels
############################
FROM python:${PYTHON_VERSION}-slim AS builder
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
gcc \
g++ \
libpq-dev \
libffi-dev \
libssl-dev \
libjpeg-dev \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt .
# Build wheels
RUN pip install --upgrade pip setuptools wheel \
&& pip wheel --no-cache-dir --wheel-dir=/wheels \
--prefer-binary \
-r requirements.txt
############################
# 2. Runtime stage: install wheels, copy code
############################
FROM python:${PYTHON_VERSION}-slim AS runtime
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
# Install runtime dependencies (for packages like psycopg2)
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq5 \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy built wheels and requirements.txt
COPY --from=builder /wheels /wheels
COPY requirements.txt .
# Install from wheels, clean up
RUN pip install --upgrade pip setuptools \
&& pip install --no-index --find-links=/wheels -r requirements.txt \
&& rm -rf /wheels
# Copy your application code
COPY . .
# Add entrypoint script
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Use entrypoint to run migrations before starting app
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 8000
CMD ["gunicorn", "backend.wsgi:application", "--bind", "0.0.0.0:8000"]