Skip to content

Commit d498321

Browse files
vmagrometa-codesync[bot]
authored andcommitted
[antlir2][debian] step towards proper automated build of debian-trixie build appliance
Summary: Add a proper impl() build appliance for debian-trixie that builds itself from features (like centos appliances do), while keeping the existing manually-bootstrapped `trixie.tar.gz` archive to build the new one until this diff lands and we can bump MSDK safely. This required making several BUCK files OS-aware via select() on the package_manager constraint: - build_appliance/BUCK: select between apt and dnf package manager features, and skip dnf-specific cleanup (yum.repos.d, dnf.conf removal) for apt - antlir2_packager/BUCK: select between apt_install and rpms_install for packager tools, with appropriate package names for each ecosystem - New apt/build_appliance/BUCK: apt-equivalent of the dnf build_appliance features (apt, dpkg, python3, mount) - debian-trixie/BUCK: add impl() call with rpm2extents=False and bootstrap_build_appliance pointing to the existing tarball-based appliance Test Plan: ``` ❯ buck build fbcode//antlir/antlir2/facebook/images/build_appliance/debian-trixie:antlir2_build_appliance_debian_trixie'[out]' fbcode//antlir/antlir2/facebook/images/build_appliance/debian-trixie:antlir2_build_appliance_debian_trixie[out] buck-out/v2/art/fbcode/db9872a2533ba461/antlir/antlir2/facebook/images/build_appliance/debian-trixie/__antlir2_build_appliance_debian_trixie__/out ❯ tree -l buck-out/v2/art/fbcode/db9872a2533ba461/antlir/antlir2/facebook/images/build_appliance/debian-trixie/__antlir2_build_appliance_debian_trixie__/out | head buck-out/v2/art/fbcode/db9872a2533ba461/antlir/antlir2/facebook/images/build_appliance/debian-trixie/__antlir2_build_appliance_debian_trixie__/out └── dir -> ../../../../../../../../../488708e8759f923e/antlir/antlir2/facebook/images/build_appliance/debian-trixie/__build-appliance.impl.dir__/build-appliance.impl.dir ├── __antlir2__ │ ├── build_appliance │ ├── out │ ├── root │ └── working_directory ├── etc │ ├── adduser.conf │ ├── alternatives ``` And it can pass the apt feature tests ``` ❯ buck2 test fbcode//antlir/antlir2/features/apt/... Buck UI: https://www.internalfb.com/buck2/4ba36879-f97c-4d44-81a5-aa5e37d39723 Tests finished: Pass 6. Fail 0. Fatal 0. Skip 0. Omit 0. Infra Failure 0. Build failure 0 ``` https://www.internalfb.com/intern/testinfra/testrun/10977524245798669 Make sure centos build still works: ``` ❯ buck2 build --show-output fbcode//antlir/antlir2/facebook/images/build_appliance/centos9: BUILD SUCCEEDED fbcode//antlir/antlir2/facebook/images/build_appliance/centos9:build-appliance.impl.dir buck-out/v2/art/fbcode/381139113463cae0/antlir/antlir2/facebook/images/build_appliance/centos9/__build-appliance.impl.dir__/build-appliance.impl.dir fbcode//antlir/antlir2/facebook/images/build_appliance/centos9:build-appliance.impl.layer buck-out/v2/art/fbcode/381139113463cae0/antlir/antlir2/facebook/images/build_appliance/centos9/__build-appliance.impl.layer__/compile/subvol_symlink fbcode//antlir/antlir2/facebook/images/build_appliance/centos9:rpm2extents buck-out/v2/art-anon/anon_msdk/2035dc5044ef1a7dantlir/antlir2/facebook/images/build_appliance/centos9/msdk/5c3efc3b28aadb5a/__rpm2extents__/extracted/rpm2extents fbcode//antlir/antlir2/facebook/images/build_appliance/centos9:rpm2extents.impl buck-out/v2/art/fbcode/381139113463cae0/antlir/antlir2/facebook/images/build_appliance/centos9/__rpm2extents.impl__/compile/subvol_symlink fbcode//antlir/antlir2/facebook/images/build_appliance/centos9:rpm2extents.impl.xar buck-out/v2/art/fbcode/381139113463cae0/antlir/antlir2/facebook/images/build_appliance/centos9/__rpm2extents.impl.xar__/rpm2extents.impl.xar ``` Reviewed By: justintrudell Differential Revision: D93776524 fbshipit-source-id: da5ecf56d8cc58959b395f39e13b8f10bb20fbc8
1 parent da94960 commit d498321

File tree

6 files changed

+102
-14
lines changed

6 files changed

+102
-14
lines changed

antlir/antlir2/antlir2_isolate/isolate_unshare/isolate_unshare_preexec/src/pid1.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,17 @@ async fn pid1_async(args: Pid1Args) -> Result<()> {
9696
)));
9797
}
9898

99-
let mut pid2 = pid2.spawn().context("while spawning pid2")?;
99+
let mut pid2 = match pid2.spawn() {
100+
Ok(pid2) => pid2,
101+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
102+
return Err(Error::msg(format!(
103+
"NotFound while spawning pid2 - is {} in the layer {} ?",
104+
String::from_utf8_lossy(args.program.as_bytes()),
105+
args.isolation.layer.display(),
106+
)));
107+
}
108+
Err(e) => return Err(Error::from(e).context("while spawning pid2")),
109+
};
100110
// I call this pid2, but it might not actually be 2, so grab it now
101111
let pid2_id = Pid::from_raw(pid2.id().context("while getting pid2 pid")? as i32);
102112
let pid2_wait = pid2.wait();

antlir/antlir2/antlir2_packager/BUCK

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,27 @@ rust_binary(
5959
feature.new(
6060
name = "build-appliance-features",
6161
features = [
62-
feature.rpms_install(rpms = [
62+
feature.package_install(subjects = [
6363
"cpio",
6464
"dosfstools",
6565
"e2fsprogs",
6666
"mtools",
67-
"rpm-build",
68-
"rpm-sign",
6967
"skopeo",
7068
"squashfs-tools",
7169
"zstd",
7270
]),
7371
select({
72+
"//antlir/antlir2/os/package_manager:package_manager[apt]": feature.apt_install(packages = [
73+
"dpkg-dev",
74+
"erofs-utils",
75+
]),
76+
"DEFAULT": feature.rpms_install(rpms = [
77+
"rpm-build",
78+
"rpm-sign",
79+
]),
80+
}),
81+
select({
82+
"//antlir/antlir2/os/package_manager:package_manager[apt]": None,
7483
"//antlir/antlir2/os:centos8": None,
7584
"//antlir/antlir2/os:rhel8": None,
7685
"//antlir/antlir2/os:rhel8.8": None,
@@ -87,6 +96,7 @@ feature.new(
8796
name = "btrfs-progs",
8897
features = internal_external(
8998
fb = [
99+
feature.ensure_dirs_exist(dirs = "/usr/local/bin"),
90100
feature.install(
91101
src = "fbsource//third-party/btrfs-progs:btrfs",
92102
dst = "/usr/local/bin/btrfs",
@@ -100,7 +110,7 @@ feature.new(
100110
dst = "/usr/local/bin/mkfs.btrfs",
101111
),
102112
],
103-
oss = [feature.rpms_install(rpms = ["btrfs-progs"])],
113+
oss = [feature.package_install(subjects = ["btrfs-progs"])],
104114
),
105115
visibility = [],
106116
)

antlir/antlir2/build_appliance/BUCK

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ feature.new(
77
features = [
88
# Ensure that we don't end up with upstream dnf repos that might
99
# interfere with the snapshot
10-
feature.remove(
11-
must_exist = False,
12-
path = "/etc/yum.repos.d",
13-
),
14-
feature.remove(
15-
must_exist = False,
16-
path = "/etc/dnf/dnf.conf",
17-
),
10+
select({
11+
"//antlir/antlir2/os/package_manager:package_manager[apt]": None,
12+
"DEFAULT": feature.remove(
13+
must_exist = False,
14+
path = "/etc/yum.repos.d",
15+
),
16+
}),
17+
select({
18+
"//antlir/antlir2/os/package_manager:package_manager[apt]": None,
19+
"DEFAULT": feature.remove(
20+
must_exist = False,
21+
path = "/etc/dnf/dnf.conf",
22+
),
23+
}),
1824
feature.ensure_dirs_exist(dirs = "/__antlir2__"),
1925
feature.ensure_subdirs_exist(
2026
into_dir = "/__antlir2__",
@@ -32,7 +38,10 @@ feature.new(
3238
into_dir = "/__antlir2__",
3339
subdirs_to_create = "out",
3440
),
35-
"//antlir/antlir2/package_managers/dnf/build_appliance:features",
41+
select({
42+
"//antlir/antlir2/os/package_manager:package_manager[apt]": "//antlir/antlir2/package_managers/apt/build_appliance:features",
43+
"DEFAULT": "//antlir/antlir2/package_managers/dnf/build_appliance:features",
44+
}),
3645
],
3746
visibility = [
3847
"PUBLIC",

antlir/antlir2/bzl/feature/defs.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ load("//antlir/antlir2/features/group:group.bzl", "group_add")
1515
load("//antlir/antlir2/features/hardlink:hardlink.bzl", "hardlink")
1616
load("//antlir/antlir2/features/install:install.bzl", "install", "install_text")
1717
load("//antlir/antlir2/features/mount:mount.bzl", "host_mount", "layer_mount")
18+
load("//antlir/antlir2/features/package_install:package_install.bzl", "package_install", "package_remove")
1819
load("//antlir/antlir2/features/remove:remove.bzl", "remove")
1920
load("//antlir/antlir2/features/requires:requires.bzl", "requires")
2021
load("//antlir/antlir2/features/rpm:rpm.bzl", "dnf_module_enable", "rpms_install", "rpms_remove", "rpms_remove_if_exists", "rpms_upgrade")
@@ -40,6 +41,8 @@ feature = struct(
4041
install_text = install_text,
4142
layer_mount = layer_mount,
4243
hardlink = hardlink,
44+
package_install = package_install,
45+
package_remove = package_remove,
4346
host_mount = host_mount,
4447
remove = remove,
4548
requires = requires,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
load("//antlir/antlir2/features/apt:apt.bzl", "apt_install", "apt_remove")
7+
load("//antlir/antlir2/features/rpm:rpm.bzl", "rpms_install", "rpms_remove")
8+
9+
def package_install(*, subjects: list[str]):
10+
"""
11+
Install packages by name, automatically selecting the correct package
12+
manager (apt or dnf) based on the OS configuration.
13+
14+
Elements in `subjects` are package names like `"bash"` or `"systemd"`.
15+
"""
16+
return select({
17+
"//antlir/antlir2/os/package_manager:package_manager[apt]": apt_install(packages = subjects),
18+
"//antlir/antlir2/os/package_manager:package_manager[dnf5]": rpms_install(subjects = subjects),
19+
"//antlir/antlir2/os/package_manager:package_manager[dnf]": rpms_install(subjects = subjects),
20+
"DEFAULT": select_fail("cannot install packages without a package manager"),
21+
})
22+
23+
def package_remove(*, subjects: list[str]):
24+
"""
25+
Remove packages by name, automatically selecting the correct package
26+
manager (apt or dnf) based on the OS configuration.
27+
28+
Elements in `subjects` are package names. If a package is not installed,
29+
this feature will fail.
30+
"""
31+
return select({
32+
"//antlir/antlir2/os/package_manager:package_manager[apt]": apt_remove(packages = subjects),
33+
"//antlir/antlir2/os/package_manager:package_manager[dnf5]": rpms_remove(rpms = subjects),
34+
"//antlir/antlir2/os/package_manager:package_manager[dnf]": rpms_remove(rpms = subjects),
35+
"DEFAULT": select_fail("cannot remove packages without a package manager"),
36+
})
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature")
2+
3+
oncall("antlir")
4+
5+
feature.new(
6+
name = "features",
7+
features = [
8+
feature.apt_install(packages = [
9+
"apt",
10+
"base-files",
11+
"dpkg",
12+
"mount",
13+
"python3",
14+
"python3-apt",
15+
]),
16+
],
17+
visibility = [
18+
"//antlir/antlir2/build_appliance:features",
19+
],
20+
)

0 commit comments

Comments
 (0)