-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
66 lines (42 loc) · 1.74 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
58
59
60
61
62
63
64
65
66
#################### Base ####################
ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION}-slim AS base
ENV UID=1112 \
GID=1112 \
USER_NAME=python \
GROUP_NAME=python \
WORK_DIR=/usr/app \
TEMP_DIR_PATH=/tmp \
PORT=8000
HEALTHCHECK --interval=5m --timeout=3s \
CMD curl -f http://localhost:${PORT}/api/ping || exit 1
RUN groupadd -g ${GID} ${GROUP_NAME} && \
useradd -l -r -u ${UID} -g ${GROUP_NAME} ${USER_NAME}
RUN apt-get update && apt-get install -y --no-install-recommends git && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
#################### Requirements generation ####################
ARG POETRY_VERSION=1.4.2
FROM base AS requirements-stage
WORKDIR ${TEMP_DIR_PATH}
COPY ./pyproject.toml ./poetry.lock* ${TEMP_DIR_PATH}/
RUN pip install --no-cache-dir "poetry==${POETRY_VERSION}" && \
poetry export -f requirements.txt --output requirements.txt --without-hashes && \
poetry export -f requirements.txt --output requirements.dev.txt --without-hashes --with dev
#################### development ####################
FROM base AS development
ENV ENV=development
WORKDIR ${WORK_DIR}
COPY --from=requirements-stage ${TEMP_DIR_PATH}/requirements.dev.txt ${WORK_DIR}/requirements.txt
RUN pip install --no-cache-dir --upgrade -r "${WORK_DIR}/requirements.txt"
EXPOSE ${PORT}
#################### production ####################
FROM base AS production
ENV ENV=production
WORKDIR ${WORK_DIR}
COPY --from=requirements-stage ${TEMP_DIR_PATH}/requirements.txt ${WORK_DIR}/requirements.txt
RUN pip install --no-cache-dir --upgrade -r "${WORK_DIR}/requirements.txt"
COPY ./app ${WORK_DIR}/app
EXPOSE ${PORT}
USER ${USER_NAME}
CMD ["gunicorn", "-k", "uvicorn.workers.UvicornWorker", "app.main:app"]