-
Notifications
You must be signed in to change notification settings - Fork 0
/
flask-gunicorn.Dockerfile
90 lines (74 loc) · 1.91 KB
/
flask-gunicorn.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
ARG APP_NAME=pritunl_slack_app
ARG APP_PATH=/opt/${APP_NAME}
ARG PYTHON_VERSION=3.10.7
ARG POETRY_VERSION=1.8.2
ARG APP_PORT=9000
#
# Stage: staging
#
FROM python:${PYTHON_VERSION} AS staging
ARG APP_NAME
ARG APP_PATH
ARG POETRY_VERSION
ENV \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1
ENV \
POETRY_VERSION=${POETRY_VERSION} \
POETRY_HOME="/opt/poetry" \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1
RUN curl -sSL https://install.python-poetry.org | python3 -
ENV PATH="$POETRY_HOME/bin:$PATH"
WORKDIR ${APP_PATH}
COPY ./poetry.lock ./pyproject.toml ./README.md ./
COPY ./${APP_NAME} ./${APP_NAME}
#
# Stage: development
#
FROM staging AS development
ARG APP_NAME
ARG APP_PATH
ARG APP_PORT
WORKDIR ${APP_PATH}
RUN poetry install --extras flask
ENV FLASK_APP=${APP_NAME}/flask_handler.py \
FLASK_DEBUG=True \
FLASK_RUN_HOST=0.0.0.0 \
FLASK_RUN_PORT=${APP_PORT}
ENTRYPOINT ["poetry", "run"]
CMD ["flask", "run"]
#
# Stage: build
#
FROM staging AS build
ARG APP_PATH
WORKDIR ${APP_PATH}
RUN poetry build --format wheel
RUN poetry export --extras flask --format requirements.txt --output constraints.txt --without-hashes
#
# Stage: production
#
FROM python:${PYTHON_VERSION} AS production
ARG APP_NAME
ARG APP_PATH
ARG APP_PORT
ENV \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1
ENV \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100
WORKDIR ${APP_PATH}
COPY --from=build ${APP_PATH}/dist/*.whl ./
COPY --from=build ${APP_PATH}/constraints.txt ./
RUN pip install --find-links=./ ${APP_NAME}[flask] --constraint constraints.txt
ENV APP_NAME=${APP_NAME}
ENV APP_PORT=${APP_PORT}
COPY ./docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["gunicorn", "${APP_NAME}.flask_handler:flask_app", "--bind :${APP_PORT}"]