From 868198661d3290ce883d495f13f96f7a3bbb65e6 Mon Sep 17 00:00:00 2001 From: aalok-sathe Date: Thu, 3 Feb 2022 14:07:59 -0500 Subject: [PATCH] clean up dockerfile; bugfix "pip cache" throws error, instead rely on env variable PIP_NO_CACHE_DIR=false as in https://github.com/pypa/pip/issues/5735 --- Dockerfile | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4dd324b..02b9aca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,12 @@ # syntax=docker/dockerfile:1 -FROM ubuntu:20.04 as builddeps +FROM ubuntu:20.04 -# source: https://stackoverflow.com/a/54763270/2434875 + +################################################################ +#### set up environment #### +#### source: https://stackoverflow.com/a/54763270/2434875 +#### source: https://github.com/pypa/pip/issues/5735 +################################################################ ENV PYTHONFAULTHANDLER=1 \ PYTHONUNBUFFERED=1 \ PYTHONHASHSEED=random \ @@ -11,7 +16,11 @@ ENV PYTHONFAULTHANDLER=1 \ POETRY_VERSION=1.1.10 WORKDIR /app -# install necessary packages using apt + + +################################################################ +#### install system-wide dependencies and utilities; cache #### +################################################################ RUN apt update RUN apt install -y python3.8 python3.8-dev python3-pip RUN apt install -y python2.7 python2.7-dev @@ -26,35 +35,32 @@ COPY poetry.lock pyproject.toml /app/ COPY sentspace /app/sentspace # RUN python3.8 -m venv /venv -FROM builddeps as build -RUN ls -lah . .. +################################################################ +#### install package dependencies; build using poetry #### +################################################################ +RUN ls -lah . +RUN pip config set global.cache-dir false RUN poetry config virtualenvs.create false RUN poetry install -E polyglot --no-interaction --no-ansi --no-root && \ poetry build -f wheel && \ pip install --no-deps . dist/*.whl && \ rm -rf dist *.egg-info -# ADD ./requirements.txt /app/requirements/requirements.txt -# unnecessary: # ADD . /app/ - -# install ZS package separately (pypi install fails) -# RUN python3.8 -m pip install -U pip cython -# RUN apt install -y git -# RUN git clone https://github.com/njsmith/zs -# RUN cd zs && git checkout v0.10.0 && pip install . -# RUN rm -rf zs -# install rest of the requirements using pip -# RUN pip install -r ./requirements.txt RUN polyglot download morph2.en -# RUN pip install -U ipython ipykernel jupyter -# cleanup + +################################################################ +#### cleanup #### +################################################################ RUN apt remove -y git RUN apt autoremove -y -RUN pip cache purge RUN apt clean && rm -rf /var/lib/apt/lists/* + +################################################################ +#### set up entrypoint to use as standalone app #### +################################################################ EXPOSE 8051 ENTRYPOINT [ "python3.8", "-m", "sentspace" ] CMD [ "-h" ] \ No newline at end of file