From a93c06529e1b08576ca679363416a1b0af6c5b09 Mon Sep 17 00:00:00 2001 From: Nicolo Intrieri Date: Mon, 1 Aug 2022 23:26:51 +0200 Subject: [PATCH 1/5] makes install available for all users in docker image moves the installation path from /root/.local to a virtualenv. this way we still get the lightweight multistage build without excluding non-root users. --- Dockerfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index c393e29f632..d23c965443a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,16 +2,19 @@ FROM python:3-slim AS builder RUN mkdir /src COPY . /src/ +ENV VIRTUAL_ENV=/opt/venv +RUN python -m venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" RUN pip install --no-cache-dir --upgrade pip setuptools wheel \ # Install build tools to compile dependencies that don't have prebuilt wheels && apt update && apt install -y git build-essential \ && cd /src \ - && pip install --user --no-cache-dir .[colorama,d] + && pip install --no-cache-dir .[colorama,d] FROM python:3-slim # copy only Python packages to limit the image size -COPY --from=builder /root/.local /root/.local -ENV PATH=/root/.local/bin:$PATH +COPY --from=builder /opt/venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" CMD ["black"] From 387531fc6caf7ac0b1147d517be50d8ec926dab1 Mon Sep 17 00:00:00 2001 From: Nicolo Intrieri Date: Mon, 1 Aug 2022 23:49:47 +0200 Subject: [PATCH 2/5] adds changelog entry for docker-image fix A changelog entry has been added under the Integration subheader --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index a30ac7f25e1..e295e0e6d2b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -47,6 +47,7 @@ - Vim plugin: prefix messages with `Black: ` so it's clear they come from Black (#3194) +- Docker: changes the installation path to be available to non-root users (#3202) ### Output From 9e8bb858e08114f27a000195146f00e08ffb3525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2?= Date: Tue, 2 Aug 2022 09:37:14 +0200 Subject: [PATCH 3/5] changes dockerfile to use the venv activate script we are now using the inbuilt venv activate script, as well as explicitly mentioning the binary location in the entrypoint cmd. --- Dockerfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index d23c965443a..4e8f12f9798 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,7 @@ RUN mkdir /src COPY . /src/ ENV VIRTUAL_ENV=/opt/venv RUN python -m venv $VIRTUAL_ENV -ENV PATH="$VIRTUAL_ENV/bin:$PATH" -RUN pip install --no-cache-dir --upgrade pip setuptools wheel \ +RUN . /opt/venv/bin/activate && pip install --no-cache-dir --upgrade pip setuptools wheel \ # Install build tools to compile dependencies that don't have prebuilt wheels && apt update && apt install -y git build-essential \ && cd /src \ @@ -17,4 +16,4 @@ FROM python:3-slim COPY --from=builder /opt/venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" -CMD ["black"] +CMD ["/opt/venv/bin/black"] From f79cf0cb75a8c61e7bfd92ac587595550caa4fbe Mon Sep 17 00:00:00 2001 From: Cooper Lees Date: Tue, 2 Aug 2022 08:11:18 -0700 Subject: [PATCH 4/5] Update CHANGES.md Just being a little more explicit at what was actually done --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index e295e0e6d2b..e91290b7d37 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -47,7 +47,7 @@ - Vim plugin: prefix messages with `Black: ` so it's clear they come from Black (#3194) -- Docker: changes the installation path to be available to non-root users (#3202) +- Docker: changed to a /opt/venv installation + added to PATH to be available to non-root users (#3202) ### Output From 8b0701fbe5e152ca7301eca477aacc0f6468c34b Mon Sep 17 00:00:00 2001 From: Cooper Lees Date: Tue, 2 Aug 2022 08:12:51 -0700 Subject: [PATCH 5/5] Update CHANGES.md Formatting which I was worried about. --- CHANGES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index e91290b7d37..5b29f20bfff 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -47,7 +47,8 @@ - Vim plugin: prefix messages with `Black: ` so it's clear they come from Black (#3194) -- Docker: changed to a /opt/venv installation + added to PATH to be available to non-root users (#3202) +- Docker: changed to a /opt/venv installation + added to PATH to be available to + non-root users (#3202) ### Output