New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
makes install available for all users in docker image #3202
Changes from 2 commits
a93c065
387531f
9e8bb85
f79cf0c
8b0701f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this make the PATH persistent like this? i.e.everyone who download and runs commands in this container will get this PATH prepend by default? Can you add test output of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it will prepend the PATH for all users. Here's a couple examples: # test output as host user
❯ docker run --user $(id -u):$(id -g) nborges/black:pr which black
/opt/venv/bin/black
# test output as root
❯ docker run --user 0:0 nborges/black:pr which black
/opt/venv/bin/black |
||||||
|
||||||
CMD ["black"] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Lets do this so it's more evident to people looking that we're in a venv and this is the black binary you should expect to use ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, adding this as well |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know if this will work - Ignore if it does not ...
Lets use the inbuilt
activate
script venv includes ... This way if any fixes are made in future python's venv module we get them for free.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion, i agree. Being that RUN instructions are independent from each other we are kind of forced to do this:
RUN . /opt/venv/bin/activate && pip install ...
It works indeed. I'm adding this, let me know what you think about it!