-
Notifications
You must be signed in to change notification settings - Fork 10
/
Dockerfile
executable file
·61 lines (48 loc) · 1.46 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
ARG PREZ_VERSION
ARG PYTHON_VERSION=3.13
ARG POETRY_VERSION=1.8.4
ARG ALPINE_VERSION=3.20
ARG VIRTUAL_ENV=/opt/venv
#
# Base
#
FROM python:${PYTHON_VERSION}-alpine${ALPINE_VERSION} AS base
ARG POETRY_VERSION
ARG VIRTUAL_ENV
ENV VIRTUAL_ENV=${VIRTUAL_ENV} \
POETRY_VIRTUALENVS_CREATE=false \
PATH=${VIRTUAL_ENV}/bin:/root/.local/bin:${PATH}
RUN apk add --no-cache \
bash \
pipx \
git
RUN pipx install poetry==${POETRY_VERSION}
WORKDIR /app
COPY . .
RUN poetry build
RUN python3 -m venv --system-site-packages ${VIRTUAL_ENV}
RUN ${VIRTUAL_ENV}/bin/pip3 install --no-cache-dir dist/*.whl
RUN ${VIRTUAL_ENV}/bin/pip3 install uvicorn
#
# Final
#
FROM python:${PYTHON_VERSION}-alpine${ALPINE_VERSION} AS final
ARG PREZ_VERSION
ENV PREZ_VERSION=${PREZ_VERSION}
ARG VIRTUAL_ENV
ENV VIRTUAL_ENV=${VIRTUAL_ENV} \
PATH=${VIRTUAL_ENV}/bin:/root/.local/bin:${PATH}
ENV APP_ROOT_PATH=''
COPY --from=base ${VIRTUAL_ENV} ${VIRTUAL_ENV}
RUN apk update && \
apk upgrade --no-cache && \
apk add --no-cache
WORKDIR /app
# prez module is already built as a package and installed in $VIRTUAL_ENV as a library
COPY main.py pyproject.toml ./
ENTRYPOINT uvicorn prez.app:assemble_app --factory \
--host=${HOST:-0.0.0.0} \
--port=${PORT:-8000} \
$( [ "$(echo "$PROXY_HEADERS" | tr '[:upper:]' '[:lower:]')" = "true" ] || [ "$PROXY_HEADERS" = "1" ] && echo "--proxy-headers" ) \
--forwarded-allow-ips=${FORWARDED_ALLOW_IPS:-127.0.0.1} \
--root-path "${APP_ROOT_PATH}"