Files

39 lines
1.5 KiB
Docker
Raw Permalink Normal View History

# Translation service (translator/translator.py): Mozilla's Firefox
# Translations models on the Bergamot engine, and fastText language
# identification. Python 3.10: the newest the bergamot package is built for.
#
# docker build -f docker/Dockerfile.translator -t webmail/translator .
#
# The models are not in the image: they are downloaded into /data (a bind
# mount) on the first start and from the admin panel.
FROM python:3.10-slim
ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
DATA_DIR=/data \
HOME=/tmp
COPY translator/requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
# fastText's language identifier (lid.176, compressed; CC BY-SA 3.0).
ADD --checksum=sha256:8f3472cfe8738a7b6099e8e999c3cbfae0dcd15696aac7d7738a8039db603e83 \
https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.ftz /opt/lid.176.ftz
COPY translator/translator.py /app/translator.py
# The same uid as the backend: DATA_ROOT/translator is owned by it (init).
RUN useradd --uid 10001 --no-create-home --shell /usr/sbin/nologin translator \
&& mkdir -p /data && chown translator /data /opt/lid.176.ftz
USER translator
WORKDIR /app
EXPOSE 5000
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=5 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:5000/health', timeout=4)"
CMD ["uvicorn", "translator:app", "--host", "0.0.0.0", "--port", "5000", "--no-access-log"]