From e1161a03e6817bab63a1f6d7ab3d2415abb889d4 Mon Sep 17 00:00:00 2001 From: Christophe Monniez Date: Tue, 5 Jul 2022 10:26:31 +0200 Subject: [PATCH] [FIX] runbot: avoid sudo when using pip In bd4cf76b7 a new argument `--progress-bar off` was added to the pip command line. Unfortunately, it appears that this argument is not available in some pip versions, typically the one from Ubuntu Bionic (9.0.1) [0]. The argument appeared in version 10.0.0 [1]. Also, in the DockerFile, we allow the user to use `sudo` for `/usr/bin/pip3` and the main reason for that was to avoid having `pip` to re-install the packages that are pre-installed by the distribution package manager. That said, it appears that since pip 10.0.0 when installing packages locally for the user, pip now properly detects distribution installed packages. So, as the solution to fix the progress bar issue is to upgrade pip to a newer version, we can take advantage of it to get rid of the `sudo`. Besides the fact that `--user` is the default on Debian based distributions [2] , we enforce it in case another distribution is used in the Dockerfile. [0] https://packages.ubuntu.com/bionic-updates/python3-pip [1] https://pip.pypa.io/en/stable/news/#id744 [2] https://wiki.debian.org/Python#Deviations_from_upstream --- runbot/container.py | 4 +--- runbot/models/build.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/runbot/container.py b/runbot/container.py index 3d98a45d..e852d046 100644 --- a/runbot/container.py +++ b/runbot/container.py @@ -32,9 +32,7 @@ DOCKERUSER = """ RUN groupadd -g %(group_id)s odoo \\ && useradd -u %(user_id)s -g odoo -G audio,video odoo \\ && mkdir /home/odoo \\ -&& chown -R odoo:odoo /home/odoo \\ -&& echo "odoo ALL= NOPASSWD: /usr/bin/pip" > /etc/sudoers.d/pip \\ -&& echo "odoo ALL= NOPASSWD: /usr/bin/pip3" >> /etc/sudoers.d/pip +&& chown -R odoo:odoo /home/odoo USER odoo ENV COVERAGE_FILE /data/build/.coverage """ % {'group_id': os.getgid(), 'user_id': os.getuid()} diff --git a/runbot/models/build.py b/runbot/models/build.py index b53311bf..551ecce0 100644 --- a/runbot/models/build.py +++ b/runbot/models/build.py @@ -966,7 +966,7 @@ class BuildResult(models.Model): if not self.params_id.skip_requirements and os.path.isfile(commit_id._source_path('requirements.txt')): repo_dir = self._docker_source_folder(commit_id) requirement_path = os.path.join(repo_dir, 'requirements.txt') - pres.append(['sudo', 'pip%s' % py_version, 'install', '--progress-bar', 'off', '-r', '%s' % requirement_path]) + pres.append([f'python{py_version}', '-m', 'pip', 'install','--user', '--progress-bar', 'off', '-r', f'{requirement_path}']) addons_paths = self._get_addons_path() (server_commit, server_file) = self._get_server_info()