forked from NatLibFi/Annif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
56 lines (45 loc) · 1.78 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
FROM python:3.8-slim-bullseye
LABEL maintainer="Juho Inkinen <[email protected]>"
SHELL ["/bin/bash", "-c"]
ARG optional_dependencies="fasttext voikko fasttext nn omikuji yake spacy"
ARG POETRY_VIRTUALENVS_CREATE=false
# Install system dependencies needed at runtime:
RUN apt-get update && \
if [[ $optional_dependencies =~ "voikko" ]]; then \
apt-get install -y --no-install-recommends \
libvoikko1 \
voikko-fi; \
fi && \
# Install rsync for model transfers:
apt-get install -y --no-install-recommends rsync && \
rm -rf /var/lib/apt/lists/* /usr/include/*
WORKDIR /Annif
RUN pip install --upgrade pip poetry --no-cache-dir && \
pip install poetry
COPY pyproject.toml setup.cfg README.md LICENSE.txt CITATION.cff projects.cfg.dist /Annif/
# First round of installation for Docker layer caching:
RUN echo "Installing dependencies for optional features: $optional_dependencies" \
&& poetry install -E "$optional_dependencies" \
&& rm -rf /root/.cache/pypoetry # No need for cache because of poetry.lock
# Download nltk data
RUN python -m nltk.downloader punkt -d /usr/share/nltk_data
# Download spaCy models, if the optional feature was selected
ARG spacy_models=en_core_web_sm
RUN if [[ $optional_dependencies =~ "spacy" ]]; then \
for model in $(echo $spacy_models | tr "," "\n"); do \
python -m spacy download $model; \
done; \
fi
# Second round of installation with the actual code:
COPY annif /Annif/annif
COPY tests /Annif/tests
RUN poetry install -E "$optional_dependencies"
WORKDIR /annif-projects
# Switch user to non-root:
RUN groupadd -g 998 annif_user && \
useradd -r -u 998 -g annif_user annif_user && \
chmod -R a+rX /Annif && \
mkdir -p /Annif/tests/data && \
chown -R annif_user:annif_user /annif-projects /Annif/tests/data
USER annif_user
CMD annif