-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.prod
More file actions
57 lines (39 loc) · 1.57 KB
/
Dockerfile.prod
File metadata and controls
57 lines (39 loc) · 1.57 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
52
53
54
55
56
57
# syntax=docker/dockerfile:1.6
FROM python:3.11-slim AS builder
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
RUN --mount=type=cache,target=/var/cache/apt \
--mount=type=cache,target=/var/lib/apt/lists \
apt-get update \
&& apt-get install -y --no-install-recommends build-essential
COPY . /app
RUN --mount=type=cache,target=/root/.cache/pip \
python -m pip install --upgrade pip \
&& python -m pip wheel --wheel-dir /wheels --constraint /app/constraints.lock . \
&& python -m pip wheel --no-deps --wheel-dir /wheels/app --constraint /app/constraints.lock .
FROM python:3.11-slim AS runtime
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
ARG APP_UID=1000
ARG APP_GID=1000
RUN groupadd -g ${APP_GID} app \
&& useradd -u ${APP_UID} -g ${APP_GID} -m app
COPY --from=builder /wheels /wheels
COPY --from=builder /app/constraints.lock /app/constraints.lock
RUN python -m pip install --no-cache-dir --no-index --find-links=/wheels \
--constraint /app/constraints.lock \
/wheels/app/*.whl \
&& rm -rf /wheels
COPY migrations /app/migrations
COPY alembic.ini /app/alembic.ini
RUN mkdir -p /app/storage \
&& chown -R app:app /app
USER app
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=2s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health/deps', timeout=2).read()"
CMD ["sh", "-c", "uvicorn apps.api.app.main:app --host 0.0.0.0 --port 8000 --workers ${UVICORN_WORKERS:-${WEB_CONCURRENCY:-2}}"]