Skip to content

Docker: Init python venv with non-root user #2769

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

Merged
merged 2 commits into from
Apr 9, 2025
Merged
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
33 changes: 16 additions & 17 deletions Base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ ENV DEBIAN_FRONTEND=noninteractive \
SEL_DOWNLOAD_DIR=${HOME}/Downloads \
VIDEO_FOLDER="/videos" \
# Path to the Configfile
CONFIG_FILE="/opt/selenium/config.toml"
CONFIG_FILE="/opt/selenium/config.toml" \
VENV_PATH=/opt/venv

#========================
# Miscellaneous packages
Expand Down Expand Up @@ -69,25 +70,15 @@ RUN apt-get -qqy update \
#========================================
# Install Python for utilities
#========================================
ENV PATH="$VENV_PATH/bin:$PATH" \
VIRTUAL_ENV="$VENV_PATH"

RUN apt-get -qqy update \
&& apt-get upgrade -yq \
&& apt-get -qqy --no-install-recommends install \
python3 python3-pip python3-venv python3-setuptools \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*

ENV VENV_PATH=/opt/venv
RUN python3 -m venv $VENV_PATH \
echo "source $VENV_PATH/bin/activate" >> /etc/bash.bashrc

RUN $VENV_PATH/bin/python3 -m pip install --upgrade pip setuptools virtualenv psutil \
&& wget -q https://github.com/Supervisor/supervisor/archive/refs/heads/main.zip -O /tmp/supervisor.zip \
&& unzip /tmp/supervisor.zip -d /tmp \
&& cd /tmp/supervisor-main \
&& $VENV_PATH/bin/python3 -m pip install --break-system-packages . \
&& rm -rf /tmp/supervisor.zip /tmp/supervisor-main

ENV PATH="$VENV_PATH/bin:$PATH" \
VIRTUAL_ENV="$VENV_PATH"
python3 python3-pip python3-venv \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/* \
&& echo "source $VENV_PATH/bin/activate" >> /etc/bash.bashrc

RUN ARCH=$(if [ "$(dpkg --print-architecture)" = "arm64" ]; then echo "aarch64"; else echo "$(dpkg --print-architecture)"; fi) \
&& wget -q https://github.com/moparisthebest/static-curl/releases/download/v8.11.0/curl-$ARCH -O /usr/bin/curl \
Expand Down Expand Up @@ -198,6 +189,14 @@ RUN ARCH=$(if [ "$(dpkg --print-architecture)" = "amd64" ]; then echo "x86_64";
#===================================================
USER ${SEL_UID}:${SEL_GID}

RUN python3 -m venv $VENV_PATH \
&& $VENV_PATH/bin/python3 -m pip install --upgrade pip setuptools virtualenv psutil \
&& wget -q https://github.com/Supervisor/supervisor/archive/refs/heads/main.zip -O /tmp/supervisor.zip \
&& unzip /tmp/supervisor.zip -d /tmp \
&& cd /tmp/supervisor-main \
&& $VENV_PATH/bin/python3 -m pip install --break-system-packages . \
&& rm -rf /tmp/supervisor.zip /tmp/supervisor-main

RUN /opt/bin/add-jks-helper.sh -d /opt/selenium/secrets \
&& /opt/bin/add-cert-helper.sh -d /opt/selenium/secrets ${CERT_TRUST_ATTR}
#======================================
Expand Down
Loading