forked from NatLibFi/Annif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
64 lines (50 loc) · 1.99 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
FROM python:3.8-slim-bullseye AS builder
LABEL maintainer="Juho Inkinen <[email protected]>"
SHELL ["/bin/bash", "-c"]
ARG optional_dependencies=dev,voikko,pycld3,fasttext,nn,omikuji,yake,spacy
# Bulding fastText needs some system packages
RUN if [[ $optional_dependencies =~ "fasttext" ]]; then \
apt-get update && \
apt-get install -y --no-install-recommends \
build-essential && \
pip install --no-cache-dir \
fasttext==0.9.2; \
fi
FROM python:3.8-slim-bullseye
SHELL ["/bin/bash", "-c"]
COPY --from=builder /usr/local/lib/python3.8 /usr/local/lib/python3.8
# Install system dependencies needed at runtime:
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libvoikko1 \
voikko-fi \
# For Docker healthcheck:
&& apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/* /usr/include/*
WORKDIR /Annif
RUN pip install --upgrade pip --no-cache-dir
COPY setup.py README.md LICENSE.txt projects.cfg.dist /Annif/
# Install dependencies for optional features.
ARG optional_dependencies=dev,voikko,pycld3,fasttext,nn,omikuji,yake,spacy
RUN echo "Installing dependencies for optional features: $optional_dependencies" \
&& pip install .[$optional_dependencies] --no-cache-dir
# Download nltk data (handle occasional timeout in with 3 tries):
RUN for i in 1 2 3; do python -m nltk.downloader punkt -d /usr/share/nltk_data && break || sleep 1; done
# 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
# Install Annif by copying source and make the installation editable:
COPY annif /Annif/annif
COPY tests /Annif/tests
RUN pip install -e .
WORKDIR /annif-projects
# Switch user to non-root:
RUN groupadd -g 998 annif_user \
&& useradd -r -u 998 -g annif_user annif_user \
&& chown -R annif_user:annif_user /annif-projects
USER annif_user
CMD annif