diff --git a/antlir/antlir2/bzl/image/layer.bzl b/antlir/antlir2/bzl/image/layer.bzl index 54cdd5030f..74ca8280f5 100644 --- a/antlir/antlir2/bzl/image/layer.bzl +++ b/antlir/antlir2/bzl/image/layer.bzl @@ -25,7 +25,7 @@ load("//antlir/rpm/dnf2buck:repo.bzl", "RepoInfo", "RepoSetInfo") load("//antlir/bzl/build_defs.bzl", "config", "get_visibility") load(":cfg.bzl", "layer_cfg") load(":depgraph.bzl", "build_depgraph") -load(":mounts.bzl", "all_mounts", "nspawn_mount_args") +load(":mounts.bzl", "all_mounts", "container_mount_args") def _map_image( ctx: AnalysisContext, @@ -69,7 +69,7 @@ def _map_image( return cmd, out -def _nspawn_sub_target(nspawn_binary: Dependency, subvol: Artifact, mounts: list[mount_record]) -> list[Provider]: +def _container_sub_target(binary: Dependency, subvol: Artifact, mounts: list[mount_record]) -> list[Provider]: dev_mode_args = cmd_args() if REPO_CFG.artifacts_require_repo: dev_mode_args = cmd_args( @@ -80,9 +80,9 @@ def _nspawn_sub_target(nspawn_binary: Dependency, subvol: Artifact, mounts: list DefaultInfo(), RunInfo(cmd_args( "sudo", - nspawn_binary[RunInfo], + binary[RunInfo], cmd_args(subvol, format = "--subvol={}"), - cmd_args([nspawn_mount_args(mount) for mount in mounts]), + cmd_args([container_mount_args(mount) for mount in mounts]), dev_mode_args, )), ] @@ -393,7 +393,7 @@ def _impl_with_features(features: ProviderCollection, *, ctx: AnalysisContext) - DefaultInfo( sub_targets = { "build": [DefaultInfo(build_script), RunInfo(cmd_args(build_script))], - "container": _nspawn_sub_target(ctx.attrs._run_nspawn, final_subvol, mounts = phase_mounts), + "container": _container_sub_target(ctx.attrs._run_container, final_subvol, mounts = phase_mounts), "features": [DefaultInfo(features_json_artifact)], "logs": [DefaultInfo(all_logs, sub_targets = { key: [DefaultInfo(artifact)] @@ -420,7 +420,7 @@ def _impl_with_features(features: ProviderCollection, *, ctx: AnalysisContext) - mounts = all_mounts(features = all_features, parent_layer = parent_layer_info) # @oss-disable - sub_targets["container"] = _nspawn_sub_target(ctx.attrs._run_nspawn, final_subvol, mounts) + sub_targets["container"] = _container_sub_target(ctx.attrs._run_container, final_subvol, mounts) sub_targets["debug"] = [DefaultInfo(sub_targets = debug_sub_targets)] providers = [ @@ -508,7 +508,7 @@ _layer_attrs = { default = None, ), "_objcopy": attrs.exec_dep(default = "fbsource//third-party/binutils:objcopy"), - "_run_nspawn": attrs.exec_dep(default = "//antlir/antlir2/nspawn_in_subvol:nspawn"), + "_run_container": attrs.exec_dep(default = "//antlir/antlir2/container_subtarget:run"), "_selected_target_arch": attrs.default_only(attrs.string( default = arch_select(aarch64 = "aarch64", x86_64 = "x86_64"), doc = "CPU arch that this layer is being built for. This is always " + diff --git a/antlir/antlir2/bzl/image/mounts.bzl b/antlir/antlir2/bzl/image/mounts.bzl index 48f26edc73..ce94ede9fc 100644 --- a/antlir/antlir2/bzl/image/mounts.bzl +++ b/antlir/antlir2/bzl/image/mounts.bzl @@ -54,7 +54,7 @@ def all_mounts( return mounts -def nspawn_mount_args(mount: mount_record) -> cmd_args: +def container_mount_args(mount: mount_record) -> cmd_args: if mount.layer: return cmd_args("--bind-mount-ro", mount.layer.src.subvol_symlink, mount.layer.mountpoint) elif mount.host: diff --git a/antlir/antlir2/bzl/package/defs.bzl b/antlir/antlir2/bzl/package/defs.bzl index 8958e276f7..f901295adf 100644 --- a/antlir/antlir2/bzl/package/defs.bzl +++ b/antlir/antlir2/bzl/package/defs.bzl @@ -23,7 +23,7 @@ _default_attrs = { "_antlir2_packager": attrs.default_only(attrs.exec_dep(default = "//antlir/antlir2/antlir2_packager:antlir2-packager")), "_dot_meta_feature": attrs.dep(default = "//antlir/antlir2/bzl/package:dot-meta"), "_objcopy": attrs.default_only(attrs.exec_dep(default = "fbsource//third-party/binutils:objcopy")), - "_run_nspawn": attrs.default_only(attrs.exec_dep(default = "//antlir/antlir2/nspawn_in_subvol:nspawn")), + "_run_container": attrs.exec_dep(default = "//antlir/antlir2/container_subtarget:run"), "_target_arch": attrs.default_only(attrs.string( default = arch_select(aarch64 = "aarch64", x86_64 = "x86_64"), )), @@ -81,7 +81,7 @@ def _generic_impl( "_antlir2": ctx.attrs._antlir2, "_dot_meta_feature": ctx.attrs._dot_meta_feature, "_objcopy": ctx.attrs._objcopy, - "_run_nspawn": ctx.attrs._run_nspawn, + "_run_container": ctx.attrs._run_container, "_target_arch": ctx.attrs._target_arch, }, with_artifacts = True).promise.map(partial( _generic_impl_with_layer, diff --git a/antlir/antlir2/bzl/package/stamp_buildinfo.bzl b/antlir/antlir2/bzl/package/stamp_buildinfo.bzl index bf5ae16289..1a593acb3a 100644 --- a/antlir/antlir2/bzl/package/stamp_buildinfo.bzl +++ b/antlir/antlir2/bzl/package/stamp_buildinfo.bzl @@ -16,7 +16,7 @@ def _impl(ctx: AnalysisContext) -> Promise: "target_arch": ctx.attrs._target_arch, "_feature_feature_targets": [ctx.attrs._dot_meta_feature], "_objcopy": ctx.attrs._objcopy, - "_run_nspawn": ctx.attrs._run_nspawn, + "_run_container": ctx.attrs._run_container, "_selected_target_arch": ctx.attrs._target_arch, }, with_artifacts = True).promise.map(lambda l: [l[LayerInfo], l[DefaultInfo]]) @@ -27,7 +27,7 @@ stamp_buildinfo_rule = rule( "_antlir2": attrs.exec_dep(default = "//antlir/antlir2/antlir2:antlir2"), "_dot_meta_feature": attrs.dep(default = "//antlir/antlir2/bzl/package:dot-meta"), "_objcopy": attrs.default_only(attrs.exec_dep(default = "fbsource//third-party/binutils:objcopy")), - "_run_nspawn": attrs.default_only(attrs.exec_dep(default = "//antlir/antlir2/nspawn_in_subvol:nspawn")), + "_run_container": attrs.exec_dep(default = "//antlir/antlir2/container_subtarget:run"), "_target_arch": attrs.default_only(attrs.string( default = arch_select(aarch64 = "aarch64", x86_64 = "x86_64"), )), diff --git a/antlir/antlir2/nspawn_in_subvol/BUCK b/antlir/antlir2/container_subtarget/BUCK similarity index 95% rename from antlir/antlir2/nspawn_in_subvol/BUCK rename to antlir/antlir2/container_subtarget/BUCK index 49061e7425..ba4ae7f273 100644 --- a/antlir/antlir2/nspawn_in_subvol/BUCK +++ b/antlir/antlir2/container_subtarget/BUCK @@ -3,7 +3,7 @@ load("//antlir/bzl:build_defs.bzl", "rust_binary") oncall("twimage") rust_binary( - name = "nspawn", + name = "run", srcs = glob(["src/**/*.rs"]), visibility = ["PUBLIC"], deps = [ diff --git a/antlir/antlir2/nspawn_in_subvol/src/main.rs b/antlir/antlir2/container_subtarget/src/main.rs similarity index 92% rename from antlir/antlir2/nspawn_in_subvol/src/main.rs rename to antlir/antlir2/container_subtarget/src/main.rs index 31714c49a7..720bafd225 100644 --- a/antlir/antlir2/nspawn_in_subvol/src/main.rs +++ b/antlir/antlir2/container_subtarget/src/main.rs @@ -6,6 +6,7 @@ */ use std::collections::HashMap; +use std::ffi::OsString; use std::os::unix::process::CommandExt; use std::path::PathBuf; @@ -31,6 +32,8 @@ struct Args { /// `--user` run command as a given user #[clap(long, default_value = "root")] user: String, + #[clap(last = true)] + cmd: Vec, } fn init_logging() { @@ -76,8 +79,13 @@ fn main() -> anyhow::Result<()> { cmd_builder.inputs(repo_root.into_path_buf()); cmd_builder.inputs(PathBuf::from("/usr/local/fbcode")); } + + let mut cmd = args.cmd.into_iter(); + let program = cmd.next().unwrap_or(OsString::from("/bin/bash")); + Err(isolate(cmd_builder.build())? - .command("/bin/bash")? + .command(program)? + .args(cmd) .exec() .into()) }