Skip to content
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

Merged
merged 5 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
<!-- For example, Docker, GitHub Actions, pre-commit, editors -->

- 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)

### Output

Expand Down
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ FROM python:3-slim AS builder

RUN mkdir /src
COPY . /src/
RUN pip install --no-cache-dir --upgrade pip setuptools wheel \
ENV VIRTUAL_ENV=/opt/venv
RUN python -m venv $VIRTUAL_ENV
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 \
&& 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"
Copy link
Collaborator

@cooperlees cooperlees Aug 1, 2022

Choose a reason for hiding this comment

The 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 which black for different users to show this working maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"]
CMD ["/opt/venv/bin/black"]