-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
51 lines (36 loc) · 1.21 KB
/
Copy pathDockerfile
File metadata and controls
51 lines (36 loc) · 1.21 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
# Stage 1 - Install build dependencies
FROM python:3.13-slim AS builder
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Build tools kept in the builder stage in case a future requirement needs to
# compile a wheel. psycopg2-binary itself ships precompiled, so the runtime
# image below stays slim.
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Stage 2 - Runtime image
FROM python:3.13-slim
ARG PORT=8080
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PATH="/opt/venv/bin:$PATH"
ENV PORT=${PORT}
WORKDIR /app
COPY --from=builder /opt/venv /opt/venv
COPY app.py ./
COPY database.py ./
COPY gunicorn.conf.py ./
COPY static ./static
COPY templates ./templates
RUN addgroup --system app \
&& adduser --system --ingroup app --home /home/app --shell /usr/sbin/nologin app \
&& chown -R app:app /app /home/app
USER app
ENV HOME=/home/app
EXPOSE ${PORT}
CMD ["sh", "-c", "exec gunicorn -c gunicorn.conf.py --bind 0.0.0.0:${PORT} --access-logfile - --error-logfile - app:app"]