diff --git a/Dockerfile b/Dockerfile index c3a375a..6677d73 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,40 @@ -FROM continuumio/miniconda3 -RUN apt-get update && apt-get install -y build-essential - -ENV PYTHONIOENCODING=utf-8 -VOLUME /app/models +FROM continuumio/miniconda3 as build +RUN apt-get update && \ + apt-get install -y build-essential && \ + conda install -c conda-forge conda-pack mamba COPY environments/environment.yml . -RUN conda env create -f environment.yml -n nmt && rm environment.yml -SHELL ["conda", "run", "-n", "nmt", "/bin/bash", "-c"] -RUN python -c "import nltk; nltk.download(\"punkt\"); nltk.download(\"cmudict\")" -RUN pip install sockeye==1.18.106 --no-deps -SHELL ["/bin/bash", "-c"] +RUN mamba env create -f environment.yml -n venv && \ + rm environment.yml && \ + conda run -n venv pip install --no-deps sockeye==1.18.106 && \ + conda-pack -n venv -o /tmp/env.tar && \ + mkdir /venv && \ + cd /venv && \ + tar xf /tmp/env.tar && \ + rm /tmp/env.tar && \ + /venv/bin/conda-unpack && \ + conda clean -afy && \ + find /opt/conda/ -follow -type f -name '*.a' -delete && \ + find /opt/conda/ -follow -type f -name '*.pyc' -delete && \ + find /opt/conda/ -follow -type f -name '*.js.map' -delete && \ + conda env remove -n venv +FROM debian:buster + +ENV PYTHONIOENCODING=utf-8 WORKDIR /app -RUN adduser --disabled-password --gecos "app" app && \ - chown -R app:app /app && \ - chown -R app:app /opt/conda/envs/nmt +VOLUME /app/models +RUN adduser --disabled-password --gecos "app" app && \ + chown -R app:app /app USER app +COPY --from=build --chown=app:app /venv /venv +ENV PATH="/venv/bin:${PATH}" COPY --chown=app:app . . -ENV WORKER_NAME="" +RUN python -c "import nltk; nltk.download(\"punkt\")"; + RUN echo "python nmt_worker.py --worker \$WORKER_NAME" > entrypoint.sh -ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "nmt", "bash", "entrypoint.sh"] +ENTRYPOINT ["bash", "entrypoint.sh"] diff --git a/environments/environment.gpu.yml b/environments/environment.gpu.yml index 5f523de..8165a4b 100644 --- a/environments/environment.gpu.yml +++ b/environments/environment.gpu.yml @@ -12,7 +12,6 @@ dependencies: - pyyaml>=5.1 - numpy>1.19.2 - portalocker==1.6.0 - - sacrebleu==1.4.14 - regex==2020.10.15 - cudatoolkit==11.0.221 - cudnn==8.0.4 diff --git a/environments/environment.yml b/environments/environment.yml index bf11ab9..fd0e02f 100644 --- a/environments/environment.yml +++ b/environments/environment.yml @@ -12,7 +12,6 @@ dependencies: - pyyaml>=5.1 - numpy>1.19.2 - portalocker==1.6.0 - - sacrebleu==1.4.14 - regex==2020.10.15 - pip - pip: