from collections.abc import Sequence
from mkosi.context import Context
-from mkosi.mounts import finalize_source_mounts
+from mkosi.mounts import finalize_ephemeral_source_mounts
from mkosi.run import find_binary, run
from mkosi.sandbox import apivfs_cmd, finalize_crypto_mounts
from mkosi.types import PathString
apivfs: bool = True,
mounts: Sequence[PathString] = (),
) -> None:
- run(
- apt_cmd(context, command) + [operation, *sort_packages(packages)],
- sandbox=(
- context.sandbox(
- network=True,
- options=[
- "--bind", context.root, context.root,
- "--bind", context.cache_dir / "lib/apt", context.cache_dir / "lib/apt",
- "--bind", context.cache_dir / "cache/apt", context.cache_dir / "cache/apt",
- "--ro-bind", context.workspace / "apt.conf", context.workspace / "apt.conf",
- *(["--ro-bind", m, m] if (m := context.config.local_mirror) else []),
- *finalize_crypto_mounts(tools=context.config.tools()),
- *finalize_source_mounts(context.config),
- *mounts,
- "--chdir", "/work/src",
- ],
- ) + (apivfs_cmd(context.root) if apivfs else [])
- ),
- env=context.config.environment,
- )
+ with finalize_ephemeral_source_mounts(context.config) as sources:
+ run(
+ apt_cmd(context, command) + [operation, *sort_packages(packages)],
+ sandbox=(
+ context.sandbox(
+ network=True,
+ options=[
+ "--bind", context.root, context.root,
+ "--bind", context.cache_dir / "lib/apt", context.cache_dir / "lib/apt",
+ "--bind", context.cache_dir / "cache/apt", context.cache_dir / "cache/apt",
+ "--ro-bind", context.workspace / "apt.conf", context.workspace / "apt.conf",
+ *(["--ro-bind", m, m] if (m := context.config.local_mirror) else []),
+ *finalize_crypto_mounts(tools=context.config.tools()),
+ *sources,
+ *mounts,
+ "--chdir", "/work/src",
+ ],
+ ) + (apivfs_cmd(context.root) if apivfs else [])
+ ),
+ env=context.config.environment,
+ )
from mkosi.context import Context
from mkosi.installer.rpm import RpmRepository, fixup_rpmdb_location, setup_rpm
-from mkosi.mounts import finalize_source_mounts
+from mkosi.mounts import finalize_ephemeral_source_mounts
from mkosi.run import find_binary, run
from mkosi.sandbox import apivfs_cmd, finalize_crypto_mounts
from mkosi.types import PathString
def invoke_dnf(context: Context, command: str, packages: Iterable[str], apivfs: bool = True) -> None:
- run(
- dnf_cmd(context) + [command, *sort_packages(packages)],
- sandbox=(
- context.sandbox(
- network=True,
- options=[
- "--bind", context.root, context.root,
- "--bind",
- context.cache_dir / "cache" / dnf_subdir(context),
- context.cache_dir / "cache" / dnf_subdir(context),
- "--bind",
- context.cache_dir / "lib" / dnf_subdir(context),
- context.cache_dir / "lib" / dnf_subdir(context),
- *(["--ro-bind", m, m] if (m := context.config.local_mirror) else []),
- *finalize_crypto_mounts(tools=context.config.tools()),
- *finalize_source_mounts(context.config),
- "--chdir", "/work/src",
- ],
- ) + (apivfs_cmd(context.root) if apivfs else [])
- ),
- env=context.config.environment,
- )
+ with finalize_ephemeral_source_mounts(context.config) as sources:
+ run(
+ dnf_cmd(context) + [command, *sort_packages(packages)],
+ sandbox=(
+ context.sandbox(
+ network=True,
+ options=[
+ "--bind", context.root, context.root,
+ "--bind",
+ context.cache_dir / "cache" / dnf_subdir(context),
+ context.cache_dir / "cache" / dnf_subdir(context),
+ "--bind",
+ context.cache_dir / "lib" / dnf_subdir(context),
+ context.cache_dir / "lib" / dnf_subdir(context),
+ *(["--ro-bind", m, m] if (m := context.config.local_mirror) else []),
+ *finalize_crypto_mounts(tools=context.config.tools()),
+ *sources,
+ "--chdir", "/work/src",
+ ],
+ ) + (apivfs_cmd(context.root) if apivfs else [])
+ ),
+ env=context.config.environment,
+ )
fixup_rpmdb_location(context)
from typing import NamedTuple
from mkosi.context import Context
-from mkosi.mounts import finalize_source_mounts
+from mkosi.mounts import finalize_ephemeral_source_mounts
from mkosi.run import run
from mkosi.sandbox import apivfs_cmd, finalize_crypto_mounts
from mkosi.types import PathString
packages: Sequence[str] = (),
apivfs: bool = True,
) -> None:
- run(
- pacman_cmd(context) + [operation, *options, *sort_packages(packages)],
- sandbox=(
- context.sandbox(
- network=True,
- options=[
- "--bind", context.root, context.root,
- "--bind", context.cache_dir / "cache/pacman/pkg", context.cache_dir / "cache/pacman/pkg",
- *(["--ro-bind", m, m] if (m := context.config.local_mirror) else []),
- *finalize_crypto_mounts(tools=context.config.tools()),
- *finalize_source_mounts(context.config),
- "--chdir", "/work/src",
- ],
- ) + (apivfs_cmd(context.root) if apivfs else [])
- ),
- env=context.config.environment,
- )
+ with finalize_ephemeral_source_mounts(context.config) as sources:
+ run(
+ pacman_cmd(context) + [operation, *options, *sort_packages(packages)],
+ sandbox=(
+ context.sandbox(
+ network=True,
+ options=[
+ "--bind", context.root, context.root,
+ "--bind", context.cache_dir / "cache/pacman/pkg", context.cache_dir / "cache/pacman/pkg",
+ *(["--ro-bind", m, m] if (m := context.config.local_mirror) else []),
+ *finalize_crypto_mounts(tools=context.config.tools()),
+ *sources,
+ "--chdir", "/work/src",
+ ],
+ ) + (apivfs_cmd(context.root) if apivfs else [])
+ ),
+ env=context.config.environment,
+ )
from mkosi.config import yes_no
from mkosi.context import Context
from mkosi.installer.rpm import RpmRepository, fixup_rpmdb_location, setup_rpm
-from mkosi.mounts import finalize_source_mounts
+from mkosi.mounts import finalize_ephemeral_source_mounts
from mkosi.run import run
from mkosi.sandbox import apivfs_cmd, finalize_crypto_mounts
from mkosi.types import PathString
options: Sequence[str] = (),
apivfs: bool = True,
) -> None:
- run(
- zypper_cmd(context) + [verb, *options, *sort_packages(packages)],
- sandbox=(
- context.sandbox(
- network=True,
- options=[
- "--bind", context.root, context.root,
- "--bind", context.cache_dir / "cache/zypp", context.cache_dir / "cache/zypp",
- *(["--ro-bind", m, m] if (m := context.config.local_mirror) else []),
- *finalize_crypto_mounts(tools=context.config.tools()),
- *finalize_source_mounts(context.config),
- "--chdir", "/work/src",
- ],
- ) + (apivfs_cmd(context.root) if apivfs else [])
- ),
- env=context.config.environment,
- )
+ with finalize_ephemeral_source_mounts(context.config) as sources:
+ run(
+ zypper_cmd(context) + [verb, *options, *sort_packages(packages)],
+ sandbox=(
+ context.sandbox(
+ network=True,
+ options=[
+ "--bind", context.root, context.root,
+ "--bind", context.cache_dir / "cache/zypp", context.cache_dir / "cache/zypp",
+ *(["--ro-bind", m, m] if (m := context.config.local_mirror) else []),
+ *finalize_crypto_mounts(tools=context.config.tools()),
+ *sources,
+ "--chdir", "/work/src",
+ ],
+ ) + (apivfs_cmd(context.root) if apivfs else [])
+ ),
+ env=context.config.environment,
+ )
fixup_rpmdb_location(context)
delete_whiteout_files(upperdir)
-def finalize_source_mounts(config: Config) -> list[PathString]:
- mounts = {t.with_prefix(Path("/work/src")) for t in config.build_sources}
-
- options: list[PathString] = ["--dir", "/work/src"]
- for src, target in sorted(mounts, key=lambda s: s[1]):
- options += ["--ro-bind", src, target]
-
- return options
-
-
@contextlib.contextmanager
def finalize_ephemeral_source_mounts(config: Config) -> Iterator[list[PathString]]:
with contextlib.ExitStack() as stack: