From ca9f812a1269ff9680452cbead04238cabd8113a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20L=C3=B3pez=20-=20https=3A//www=2Evauxoo=2Eco?= =?UTF-8?q?m/?= Date: Tue, 29 Sep 2026 21:31:27 +0000 Subject: [PATCH] [FIX] build.sh: Run pip without sudo The Dockerfile executes build.sh as root, before "USER odoo", so "sudo -E pip" only added one thing: sudo replaces PATH with its secure_path. Images based on the uv managed python install pip under /opt/python/current/bin, outside of secure_path, so both pip calls of install_dev_tools failed with "sudo: pip: command not found". The failure did not stop the function, and the build failed later in install_pgcli_venv with "virtualenv: not found" (exit code 2), e.g. generating the scripts for a project using BASE_IMAGE="vauxoo/odoo-190-image:2604-minimal". Calling pip directly keeps the environment (PIP_BREAK_SYSTEM_PACKAGES, the reason of "-E") and the PATH of the image. --- src/travis2docker/templates/build.sh | 4 ++-- tests/test_travis2docker.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/travis2docker/templates/build.sh b/src/travis2docker/templates/build.sh index a52596d..f7697b4 100644 --- a/src/travis2docker/templates/build.sh +++ b/src/travis2docker/templates/build.sh @@ -94,7 +94,7 @@ install_dev_tools(){ # emacs \ # byobu \ # multitail # Set the terminal with red letters build the docker - sudo -E pip install -q \ + pip install -q \ ipython \ py-spy \ virtualenv \ @@ -115,7 +115,7 @@ install_dev_tools(){ # pre install pre-commit-vauxoo? # sudo su odoo -c "git init /tmp/test && cd /tmp/test && pre-commit-vauxoo -f" touch /home/odoo/full_test-requirements.txt - sudo -E pip install -r /home/odoo/full_test-requirements.txt + pip install -r /home/odoo/full_test-requirements.txt # Install git-delta from .deb since not all Ubuntu versions ship the package GIT_DELTA_VERSION=0.18.2 diff --git a/tests/test_travis2docker.py b/tests/test_travis2docker.py index f91c3fb..741dbb5 100644 --- a/tests/test_travis2docker.py +++ b/tests/test_travis2docker.py @@ -3,6 +3,7 @@ import json import os import pathlib +import re import subprocess import sys from shutil import which @@ -215,3 +216,17 @@ def test_main_without_variables_sh(tmp_path, monkeypatch): ] with pytest.raises(InvalidRepoBranchError): cli_main(return_result=True) + + +def test_build_sh_pip_without_sudo(): + """build.sh runs as root in the Dockerfile, so pip must not go through sudo: + sudo resets PATH to its secure_path and images whose python lives outside of + it (e.g. uv managed /opt/python/current/bin) fail with "sudo: pip: command not found" + """ + build_sh = pathlib.Path(__file__).resolve().parent.parent / "src" / "travis2docker" / "templates" / "build.sh" + sudo_pip_lines = [ + line.strip() + for line in build_sh.read_text().splitlines() + if not line.strip().startswith("#") and re.search(r"\bsudo\b.*\bpip3?\b", line) + ] + assert not sudo_pip_lines, "pip called through sudo in build.sh: %s" % sudo_pip_lines