-
Notifications
You must be signed in to change notification settings - Fork 18
/
Dockerfile.build
48 lines (31 loc) · 1.22 KB
/
Dockerfile.build
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
ARG TRANSLATOR_MODEL_NAME='winstxnhdw/nllb-200-distilled-1.3B-ct2-int8'
ARG LANGUAGE_DETECTOR_MODEL_NAME='facebook/fasttext-language-identification'
FROM python:3.12-slim AS python-builder
ENV POETRY_VIRTUALENVS_CREATE=false
ENV POETRY_HOME=/opt/poetry
ENV PATH=$POETRY_HOME/bin:$PATH
COPY pyproject.toml poetry.lock ./
RUN python -m venv $POETRY_HOME
RUN $POETRY_HOME/bin/pip install poetry
RUN poetry install --without=dev,cuda
FROM python:slim AS model-builder
ARG TRANSLATOR_MODEL_NAME
ARG LANGUAGE_DETECTOR_MODEL_NAME
RUN pip install huggingface_hub
RUN python -c \
"from huggingface_hub import snapshot_download, hf_hub_download; \
snapshot_download('$TRANSLATOR_MODEL_NAME'); \
hf_hub_download('$LANGUAGE_DETECTOR_MODEL_NAME', 'model.bin')"
FROM python:3.12-slim
ARG TRANSLATOR_MODEL_NAME
ARG LANGUAGE_DETECTOR_MODEL_NAME
ENV HOME=/home/user
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
RUN useradd -m -u 1000 user
USER user
WORKDIR $HOME/app
COPY --chown=user --from=model-builder /root/.cache/huggingface $HOME/.cache/huggingface
COPY --chown=user --from=python-builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --chown=user . $HOME/app
CMD ["python", "main.py"]