Avoid sudo being required with pip

This commit is contained in:
Chuck Lantz
2020-01-18 00:27:28 +00:00
parent 797aef8e05
commit 76ea9a8c2b
2 changed files with 9 additions and 1 deletions

View File

@@ -16,6 +16,10 @@ ARG USERNAME=vscode
ARG USER_UID=1000 ARG USER_UID=1000
ARG USER_GID=$USER_UID ARG USER_GID=$USER_UID
ENV PIP_TARGET=/usr/local/share/pip-global
ENV PYTHONPATH=${PYTHONPATH}:${PIP_TARGET}
ENV PATH=${PATH}:${PIP_TARGET}/bin
# Uncomment the following COPY line and the corresponding lines in the `RUN` command if you wish to # Uncomment the following COPY line and the corresponding lines in the `RUN` command if you wish to
# include your requirements in the image itself. It is suggested that you only do this if your # include your requirements in the image itself. It is suggested that you only do this if your
# requirements rarely (if ever) change. # requirements rarely (if ever) change.
@@ -43,6 +47,10 @@ RUN apt-get update \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\ && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
&& chmod 0440 /etc/sudoers.d/$USERNAME \ && chmod 0440 /etc/sudoers.d/$USERNAME \
# #
# Create alternate global install location that both uses have rights to access
&& mkdir -p /usr/local/share/pip-global \
&& chown ${USERNAME}:root /usr/local/share/pip-global \
#
# Avoid having to use "sudo" with pip when running as non-root user # Avoid having to use "sudo" with pip when running as non-root user
&& echo 'if [ "$(stat -c %U /usr/local/bin)" != "$(id -u)" ]; then \ && echo 'if [ "$(stat -c %U /usr/local/bin)" != "$(id -u)" ]; then \
sudo chown -R $(id -u):root /usr/local/lib/python*/site-packages \ sudo chown -R $(id -u):root /usr/local/lib/python*/site-packages \

View File

@@ -18,7 +18,7 @@
"appPort": [ 9000 ], "appPort": [ 9000 ],
// Install flask and any other dependencies // Install flask and any other dependencies
"postCreateCommand": "sudo pip install -r requirements.txt", "postCreateCommand": "pip install -r requirements.txt",
// Comment out next line to run as root // Comment out next line to run as root
"remoteUser": "vscode", "remoteUser": "vscode",