clan-cli: clan_cli.bwrap -> clan_lib.bwrap
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from clan_lib.cmd import Log, RunOpts, run
|
||||
from clan_lib.nix import nix_shell
|
||||
|
||||
_works: bool | None = None
|
||||
|
||||
|
||||
def bubblewrap_works() -> bool:
|
||||
global _works
|
||||
if _works is None:
|
||||
_works = _bubblewrap_works()
|
||||
return _works
|
||||
|
||||
|
||||
def _bubblewrap_works() -> bool:
|
||||
real_bash_path = Path("bash")
|
||||
if os.environ.get("IN_NIX_SANDBOX"):
|
||||
bash_executable_path = Path(str(shutil.which("bash")))
|
||||
real_bash_path = bash_executable_path.resolve()
|
||||
|
||||
# fmt: off
|
||||
cmd = nix_shell(
|
||||
[
|
||||
"bash",
|
||||
"bubblewrap",
|
||||
],
|
||||
[
|
||||
"bwrap",
|
||||
"--unshare-all",
|
||||
"--tmpfs", "/",
|
||||
"--ro-bind", "/nix/store", "/nix/store",
|
||||
"--dev", "/dev",
|
||||
"--chdir", "/",
|
||||
"--bind", "/proc", "/proc",
|
||||
"--uid", "1000",
|
||||
"--gid", "1000",
|
||||
"--",
|
||||
# do nothing, just test if bash executes
|
||||
str(real_bash_path), "-c", ":"
|
||||
],
|
||||
)
|
||||
|
||||
# fmt: on
|
||||
res = run(cmd, RunOpts(log=Log.BOTH, check=False))
|
||||
return res.returncode == 0
|
||||
@@ -1,16 +0,0 @@
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
from clan_cli.bwrap import bubblewrap_works
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform != "linux", reason="bubblewrap only works on linux")
|
||||
def test_bubblewrap_works_on_linux() -> None:
|
||||
assert bubblewrap_works() is True
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.platform == "linux", reason="bubblewrap does not work on non-linux"
|
||||
)
|
||||
def test_bubblewrap_detection_non_linux() -> None:
|
||||
assert bubblewrap_works() is False
|
||||
@@ -104,7 +104,7 @@ def generate_service_facts(
|
||||
service, machine.facts_data[service]["generator"]["prompt"]
|
||||
)
|
||||
env["prompt_value"] = prompt_value
|
||||
from clan_cli import bwrap
|
||||
from clan_lib import bwrap
|
||||
|
||||
if sys.platform == "linux" and bwrap.bubblewrap_works():
|
||||
cmd = bubblewrap_cmd(generator, facts_dir, secrets_dir)
|
||||
|
||||
@@ -218,7 +218,7 @@ def execute_generator(
|
||||
prompt_file = tmpdir_prompts / prompt.name
|
||||
value = get_prompt_value(prompt.name)
|
||||
prompt_file.write_text(value)
|
||||
from clan_cli import bwrap
|
||||
from clan_lib import bwrap
|
||||
|
||||
final_script = generator.final_script()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user