-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
36 lines (33 loc) · 1.07 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
# syntax=docker/dockerfile:1
# Stage 1: Base image
FROM python:3.11-slim AS base
ARG UID=10001
ARG USER_NAME=appuser
RUN adduser \
--disabled-password \
--gecos "" \
--home "/app" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER_NAME}"
WORKDIR /app
RUN chown ${USER_NAME}:${USER_NAME} /app
RUN --mount=type=cache,target=/root/.cache/pip \
--mount=type=bind,source=requirements.txt,target=requirements.txt \
python -m pip install -r requirements.txt
# Stage 2: Unittest stage
FROM base as unittest
RUN --mount=type=cache,target=/root/.cache/pip \
--mount=type=bind,source=requirements-test.txt,target=requirements-test.txt \
python -m pip install -r requirements-test.txt
COPY --chown=${USER_NAME}:${USER_NAME} ./main/ ./main
COPY ./tests/ ./tests
RUN PYTHONPATH=/app pytest -s -vvv /app/tests/unit
# Stage 3: Final stage
FROM base as final
COPY --from=unittest /app/main ./main
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
USER ${USER_NAME}
CMD ["python", "-m", "uvicorn", "main.entrypoint:api", "--host", "0.0.0.0"]