From: Daan De Meyer Date: Wed, 22 Jan 2025 11:32:35 +0000 (+0100) Subject: Make mkosi available inside mkosi sandbox via zipapp X-Git-Tag: v25~12^2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca934eb21d40990e2e8a66ed480e141f8ec24325;p=thirdparty%2Fmkosi.git Make mkosi available inside mkosi sandbox via zipapp Currently, mkosi has to be installed outside of /usr when using a tools tree with mkosi sandbox to make it available inside mkosi sandbox. Let's remove this restriction by packaging up the host's mkosi as a zipapp and making the zipapp available in the sandbox. --- diff --git a/action.yaml b/action.yaml index 95c5a1ee2..5104379cd 100644 --- a/action.yaml +++ b/action.yaml @@ -75,12 +75,7 @@ runs: - name: Install shell: bash - run: | - sudo ln -svf ${{ github.action_path }}/bin/mkosi /usr/bin/mkosi - # Make sure that mkosi is still found inside "mkosi sandbox" where /usr is potentially replaced with - # a tools tree's /usr. - mkdir -p $HOME/.local/bin - ln -svf ${{ github.action_path }}/bin/mkosi $HOME/.local/bin/mkosi + run: sudo ln -svf ${{ github.action_path }}/bin/mkosi /usr/bin/mkosi - name: Dependencies shell: bash diff --git a/mkosi/__init__.py b/mkosi/__init__.py index e4ff8b0d8..10ace4d6c 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -20,6 +20,7 @@ import sys import tempfile import textwrap import uuid +import zipapp from collections.abc import Iterator, Mapping, Sequence from contextlib import AbstractContextManager from pathlib import Path @@ -3881,19 +3882,31 @@ def run_sandbox(args: Args, config: Config) -> None: *cmdline, ] - run( - cmdline, - stdin=sys.stdin, - stdout=sys.stdout, - env=os.environ | env, - log=False, - sandbox=config.sandbox( - devices=True, - network=True, - relaxed=True, - options=["--same-dir", *mounts], - ), - ) + with contextlib.ExitStack() as stack: + if config.tools() != Path("/"): + d = stack.enter_context(tempfile.TemporaryDirectory(prefix="mkosi-path-")) + zipapp.create_archive( + source=Path(__file__).parent, + target=Path(d) / "mkosi", + interpreter="/usr/bin/env python3", + ) + make_executable(Path(d) / "mkosi") + mounts += ["--ro-bind", d, "/mkosi"] + stack.enter_context(scopedenv({"PATH": f"/mkosi:{os.environ['PATH']}"})) + + run( + cmdline, + stdin=sys.stdin, + stdout=sys.stdout, + env=os.environ | env, + log=False, + sandbox=config.sandbox( + devices=True, + network=True, + relaxed=True, + options=["--same-dir", *mounts], + ), + ) def run_shell(args: Args, config: Config) -> None: