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

Docker images use a user install of Black so don't work when running as another user #2975

Closed
RoryDungan opened this issue Mar 30, 2022 · 1 comment · Fixed by #3202
Closed
Assignees
Labels
C: integrations Editor plugins and other integrations C: packaging Installation and packaging of Black help wanted Extra attention is needed S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: enhancement New feature or request

Comments

@RoryDungan
Copy link

Describe the bug

Since bd96139, Docker images use a user install of Black. This means they can't be used when running a container as a user other than root.

This is a problem for me because we run Black inside of Jenkins and Jenkins runs all containers with the same UID as the host, meaning that Black cannot run because it isn't on the PATH and in any case /root/.local/bin/black is inaccessible. It also seems like it could be problematic in any situation where the Black Docker container needs to write a file, because files it creates must be owned by root.

To Reproduce

Previously this would work:

$ docker run --rm -it -u $(id -u):$(id -g) -v $PWD:/workspace -w /workspace pyfound/black:21.9b0 black --check .
All done! ✨ 🍰 ✨
4 files would be left unchanged.

However on versions 21.10b0 and up, including the latest 22.3.0 I get the following output:

$ docker run --rm -it -u $(id -u):$(id -g) -v $PWD:/workspace -w /workspace pyfound/black:21.10b0 black --check .
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "black": executable file not found in $PATH: unknown.
$ docker run --rm -it -u $(id -u):$(id -g) -v $PWD:/workspace -w /workspace pyfound/black:22.3.0 black --check .
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "black": executable file not found in $PATH: unknown.

Expected behavior

I should be able to run the Black Docker container as any user, not just root.

Environment

  • Black's version: 21.10b0, 22.3.0
  • OS and Python version: [Linux/Python 3.10.4]
@RoryDungan RoryDungan added the T: bug Something isn't working label Mar 30, 2022
@cooperlees cooperlees self-assigned this Mar 30, 2022
@cooperlees
Copy link
Collaborator

cooperlees commented Mar 30, 2022

Hi - Thanks for reporting. I agree, should be able to run black as non root. We shouldn't promote using root (even this it's in a container) wherever possible.

I guess we just have to remove the pip --user (that I missed when reviewing this) and copy the system install to the actual image.

I'll try look at it soon but happy to take any PR to fix this.

@cooperlees cooperlees added the C: packaging Installation and packaging of Black label Mar 30, 2022
@ichard26 ichard26 added the help wanted Extra attention is needed label Aug 1, 2022
@ichard26 ichard26 added this to the Release 22.8.0 milestone Aug 1, 2022
@ichard26 ichard26 added T: enhancement New feature or request C: integrations Editor plugins and other integrations S: accepted The changes in this design / enhancement issue have been accepted and can be implemented and removed T: bug Something isn't working labels Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: integrations Editor plugins and other integrations C: packaging Installation and packaging of Black help wanted Extra attention is needed S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants