-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Dockerfile
97 lines (85 loc) · 3.04 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
ARG PYTHON_VERSION=3.11
# create off user
ARG USER_UID=1000
ARG USER_GID=$USER_UID
# base python setup
# -----------------
FROM python:$PYTHON_VERSION-slim as python-base
RUN apt-get update && \
apt-get install --no-install-suggests --no-install-recommends -y curl && \
apt-get autoremove --purge && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv" \
POETRY_HOME="/opt/poetry" \
POETRY_VERSION=1.8.3 \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
# building packages
# -----------------
FROM python-base as builder-base
RUN curl -sSL https://install.python-poetry.org | python3 -
WORKDIR $PYSETUP_PATH
# we need README.md for poetry check
COPY poetry.lock pyproject.toml README.md ./
RUN poetry check --lock || \
( echo "Poetry.lock is outdated, please run make update_poetry_lock" && false )
RUN poetry install --without dev
# This is our final image
# ------------------------
FROM python-base as runtime
COPY --from=builder-base $VENV_PATH $VENV_PATH
COPY --from=builder-base $POETRY_HOME $POETRY_HOME
RUN poetry config virtualenvs.create false
ENV POETRY_VIRTUALENVS_IN_PROJECT=false
# create some folders, to later ensure right ownership
RUN mkdir -p /opt/search/data && \
mkdir -p /opt/search/synonyms
# create off user
ARG USER_UID
ARG USER_GID
RUN groupadd -g $USER_GID off && \
useradd -u $USER_UID -g off -m off && \
mkdir -p /home/off && \
mkdir -p /opt/search && \
chown off:off -R /opt/search /home/off
COPY --chown=off:off app /opt/search/app
COPY docker/docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
COPY --chown=off:off poetry.lock pyproject.toml /opt/search/
USER off:off
WORKDIR /opt/search
ENTRYPOINT /docker-entrypoint.sh $0 $@
CMD ["uvicorn", "app.api:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]
# building dev packages
# ----------------------
FROM builder-base as builder-dev
WORKDIR $PYSETUP_PATH
# we need README.md for poetry check
COPY poetry.lock pyproject.toml README.md ./
# full install, with dev packages
RUN poetry check --lock || \
( echo "Poetry.lock is outdated, please run make update_poetry_lock" && false )
RUN poetry install
# image with dev tooling
# ----------------------
# This image will be used by default, unless a target is specified in docker-compose.yml
FROM runtime as runtime-dev
COPY --from=builder-dev $VENV_PATH $VENV_PATH
COPY --from=builder-dev $POETRY_HOME $POETRY_HOME
# Handle possible issue with Docker being too eager after copying files
RUN true
COPY .flake8 pyproject.toml ./
# create folders that we mount in dev to avoid permission problems
USER root
RUN \
mkdir -p /opt/search/gh_pages /opt/search/docs /opt/search/.cov && \
chown -R off:off /opt/search/gh_pages /opt/search/docs /opt/search/.cov
USER off