From 60b864fbcc0be5b07e437662fa2fbde082dea19f Mon Sep 17 00:00:00 2001 From: Jon Kafton <939376+jonkafton@users.noreply.github.com> Date: Thu, 1 Feb 2024 10:04:51 +0100 Subject: [PATCH] Build steps for Poetry virtualenv --- Dockerfile | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index b7767dee5d..b540e901e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,27 +18,42 @@ RUN mkdir /src RUN adduser --disabled-password --gecos "" mitodl RUN mkdir /var/media && chown -R mitodl:mitodl /var/media -# Poetry env configuration +## Set some poetry config ENV \ - # poetry: POETRY_VERSION=1.5.1 \ - POETRY_CACHE_DIR='/tmp/cache/poetry' + POETRY_VIRTUALENVS_CREATE=false \ + POETRY_CACHE_DIR='/tmp/cache/poetry' \ + POETRY_HOME='/home/mitodl/.local' \ + VIRTUAL_ENV="/opt/venv" +ENV PATH="$VIRTUAL_ENV/bin:$POETRY_HOME/bin:$PATH" # Install poetry RUN pip install "poetry==$POETRY_VERSION" -# Install project packages COPY pyproject.toml /src COPY poetry.lock /src +RUN chown -R mitodl:mitodl /src +RUN mkdir ${VIRTUAL_ENV} && chown -R mitodl:mitodl ${VIRTUAL_ENV} + +## Install poetry itself, and pre-create a venv with predictable name +USER mitodl +RUN curl -sSL https://install.python-poetry.org \ + | \ + POETRY_VERSION=${POETRY_VERSION} \ + POETRY_HOME=${POETRY_HOME} \ + python3 -q WORKDIR /src +RUN python3 -m venv $VIRTUAL_ENV RUN poetry install # Add project +USER root COPY . /src WORKDIR /src RUN chown -R mitodl:mitodl /src RUN apt-get clean && apt-get purge + USER mitodl EXPOSE 8063