-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
57 lines (45 loc) · 1.62 KB
/
Dockerfile
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
# ================================== BUILDER ===================================
ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION} AS build
# Environments to reduce size of docker image
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONFAULTHANDLER=true
ENV PYTHONUNBUFFERED=true
ENV PYTHONHASHSEED=random
ENV PIP_NO_CACHE_DIR=true
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
ENV PIP_DEFAULT_TIMEOUT=100
# Install system updates and tools
RUN apt-get update
RUN python -m pip install --upgrade pip
# Add workdir and user non root user
WORKDIR /srv
RUN useradd -m sid
# Copy and install production requirements
COPY --chown=sid:sid app /srv/app
COPY --chown=sid:sid requirements.txt /srv
COPY --chown=sid:sid autoapp.py /srv
RUN python -m pip install -r requirements.txt
# ================================= PRODUCTION =================================
FROM build AS production
USER root
# Copy and install production requirements
RUN pip install gunicorn~=21.2.0 gevent~=24.2.1
# Change to non root user and expose port
USER sid
EXPOSE 5000
# Define entrypoint and default command
ENTRYPOINT [ "python", "-m", "gunicorn"]
CMD [ "-k", "gevent", "autoapp:app", "--bind", "0.0.0.0:5000" ]
# ================================= DEVELOPMENT ================================
FROM build AS development
USER root
# Copy and install debugger requirements
RUN pip install debugpy
# Change to non root user and expose port
USER sid
EXPOSE 5000
EXPOSE 5678
# Define entrypoint and default command
ENTRYPOINT ["python", "-m", "debugpy", "--listen", "0.0.0.0:5678", "--wait-for-client", "-m", "flask" ]
CMD [ "run", "--no-debugger", "--no-reload", "--host", "0.0.0.0" ]