From b5830854f9c316b71624d02a2d30a56bdd70520f Mon Sep 17 00:00:00 2001 From: czoido Date: Thu, 12 Sep 2024 09:25:33 +0200 Subject: [PATCH] wip --- ci/Dockerfile | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/ci/Dockerfile b/ci/Dockerfile index 29d924bd9c1..3c877ea6107 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -3,36 +3,22 @@ FROM ubuntu:latest LABEL maintainer="Conan.io " ARG DEBIAN_FRONTEND=noninteractive + ENV PY38 3.8.6 +# Install essential packages and dependencies for pyenv and other tools RUN apt-get -qq update \ && apt-get -qq install -y --no-install-recommends \ - sudo ca-certificates adduser \ + sudo ca-certificates \ make build-essential libssl-dev zlib1g-dev libbz2-dev \ libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \ xz-utils tk-dev libffi-dev liblzma-dev git \ - && adduser --disabled-password --gecos "" --uid 1001 runner \ - && groupadd docker --gid 123 \ - && usermod -aG sudo runner \ - && usermod -aG docker runner \ - && echo "%sudo ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers \ - && echo "Defaults env_keep += \"DEBIAN_FRONTEND\"" >> /etc/sudoers - + && rm -rf /var/lib/apt/lists/* -# Add 'runner' user similar to GitHub's runner user setup -RUN adduser --disabled-password --gecos "" --uid 1001 runner \ - && groupadd docker --gid 123 \ - && usermod -aG sudo runner \ - && usermod -aG docker runner \ - && echo "%sudo ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers \ - && echo "Defaults env_keep += \"DEBIAN_FRONTEND\"" >> /etc/sudoers - -WORKDIR /home/runner - -# Set PATH and install pyenv for the runner user -USER runner +# Set up environment variables for pyenv ENV PATH /home/runner/.pyenv/shims:/home/runner/.pyenv/bin:$PATH +# Install pyenv and Python version RUN curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash \ && pyenv init - \ && pyenv virtualenv-init - \ @@ -40,10 +26,22 @@ RUN curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-instal && pyenv install $PY38 \ && pyenv global $PY38 -# Clean up unnecessary build dependencies, but keep git -USER root +# Remove not needed packages except git RUN apt-get -qq remove make build-essential gcc \ - && rm -rf /var/lib/apt/lists + && rm -rf /var/lib/apt/lists/* + +# Check if the user 'runner' exists, if not, set necessary permissions +RUN if ! id -u runner > /dev/null 2>&1; then \ + adduser --disabled-password --gecos "" --uid 1001 runner; \ + groupadd docker --gid 123; \ + usermod -aG sudo runner; \ + usermod -aG docker runner; \ + fi \ + && echo "%sudo ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers \ + && echo "Defaults env_keep += \"DEBIAN_FRONTEND\"" >> /etc/sudoers -USER runner +# Set up the work directory for the runner user WORKDIR /home/runner + +# Switch to the runner user, assuming it exists or was just created +USER runner