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 76fb14a commit f4ad708
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
42 changes: 28 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
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\")"
SHELL ["/bin/bash", "-c"]
RUN mamba env create -f environment.yml -n venv && \
rm environment.yml && \
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"]
11 changes: 3 additions & 8 deletions environments/environment.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
channels:
- pytorch
- anaconda
- conda-forge
- defaults
- pytorch
dependencies:
- python=3.7.5
- nltk==3.4.5
- python-dotenv==0.15.0
- marshmallow==3.10.0
- pytorch==1.8.1
- gunicorn==20.0.4
- webargs>=7.0.1
- pyyaml>=5.1
- numpy>1.19.2
- portalocker==1.6.0
- sacrebleu==1.4.14
- pyyaml==5.3.1
- numpy==1.20.3
- regex==2020.10.15
- git
- pip
Expand Down

0 comments on commit f4ad708

Please sign in to comment.