Skip to content

Commit

Permalink
multi-stage build
Browse files Browse the repository at this point in the history
  • Loading branch information
liisaratsep committed Sep 14, 2021
1 parent 6afca1e commit b12ed29
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
44 changes: 29 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
1 change: 0 additions & 1 deletion environments/environment.gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion environments/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b12ed29

Please sign in to comment.