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