Skip to content

Commit 727d48b

Browse files
committed
refactor(os): make mkosi components self-describing
1 parent 1fdf33b commit 727d48b

16 files changed

Lines changed: 419 additions & 104 deletions

os/mkosi/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ DSTACK_DEV_CACHE_DIR="$HOME/.cache/dstack/mkosi-dev" \
6060

6161
The cache covers dstack Rust, the container stack, Sysbox, nvattest, the
6262
kernel build tree, NVIDIA, ZFS and both OVMF variants. Its key conservatively
63-
includes all tracked and untracked mkosi/Yocto/dstack inputs, tool versions,
64-
architecture, flavor and `SOURCE_DATE_EPOCH`. `image` and `repro-check`
65-
unconditionally disable this development cache, even if the internal enable
66-
flag is inherited from the environment. Release artifacts, Debian rootfs,
67-
dm-verity data and measurements are never cached.
63+
includes the inputs, tools, packages and component dependencies declared by
64+
each file in `components/`, plus architecture, flavor and
65+
`SOURCE_DATE_EPOCH`. `build-components.sh` is intentionally only the ordered
66+
component list. Component install trees are merged with strict non-directory
67+
conflict detection. `image` and `repro-check` never pass the development-cache
68+
option. Release artifacts, Debian rootfs, dm-verity data and measurements are
69+
never cached.
6870

6971
On a 16-job development host, a clean production work directory takes about
7072
17 minutes (measured 16m45s); allow 20--30 minutes with cold compiler and
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# shellcheck shell=bash disable=SC2034
3+
COMPONENT_NAME=container-stack
4+
COMPONENT_CACHE_PATHS=(component-stages/container-stack)
5+
COMPONENT_ROOTFS_TREES=(component-stages/container-stack)
6+
COMPONENT_KERNEL_TREES=()
7+
8+
component_cache_key() {
9+
key_value "$NVIDIA_CONTAINER_TOOLKIT_REVISION" "$LIBNVIDIA_CONTAINER_REVISION" \
10+
"$NERDCTL_VERSION" "$NERDCTL_SHA256" "$CNI_VERSION" "$CNI_SHA256" \
11+
"$STARGZ_VERSION" "$STARGZ_SHA256"
12+
key_file "$SELF/scripts/build-container-stack.sh" \
13+
"$SELF/patches/libnvidia-container/0001-omit-prefix-map-from-build-flags.patch"
14+
key_tree os/yocto/layers/meta-nvidia/recipes-graphics/nvidia-container-toolkit \
15+
os/yocto/layers/meta-dstack/recipes-containers
16+
key_tools gcc go
17+
key_packages libelf-dev libtirpc-dev
18+
}
19+
20+
component_build() {
21+
"$SELF/scripts/build-container-stack.sh" "$WORK/container-stack-build" \
22+
"$WORK/component-stages/container-stack"
23+
}

os/mkosi/components/dstack-rust.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# shellcheck shell=bash disable=SC2034
3+
COMPONENT_NAME=dstack-rust
4+
COMPONENT_CACHE_PATHS=(component-stages/dstack-rust)
5+
COMPONENT_ROOTFS_TREES=(component-stages/dstack-rust)
6+
COMPONENT_KERNEL_TREES=()
7+
8+
component_cache_key() {
9+
key_file "$SELF/scripts/stage-rootfs.sh"
10+
key_tree dstack os/common/rootfs
11+
key_tools rustc cargo
12+
}
13+
14+
component_build() {
15+
"$SELF/scripts/stage-rootfs.sh" "$WORK/component-stages/dstack-rust" "$FLAVOR"
16+
}

os/mkosi/components/kernel.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# shellcheck shell=bash disable=SC2034
3+
COMPONENT_NAME=kernel
4+
COMPONENT_CACHE_PATHS=("linux-$KERNEL_VERSION" kernel-build component-stages/kernel)
5+
COMPONENT_ROOTFS_TREES=()
6+
COMPONENT_KERNEL_TREES=(component-stages/kernel)
7+
8+
component_cache_key() {
9+
key_value "$KERNEL_VERSION" "$KERNEL_SHA256"
10+
key_file "$SELF/scripts/build-kernel.sh" "$SELF/kernel.config" \
11+
"$ROOT/os/yocto/layers/meta-dstack/recipes-kernel/linux/files/0001-x86-tdx-select-dma-direct-remap.patch" \
12+
"$ROOT/os/yocto/layers/meta-dstack/recipes-kernel/linux/files/0002-acpi-sandbox-block-aml-systemmemory-ram-access.patch"
13+
key_tools gcc ld make pahole
14+
key_packages binutils dwarves bc bison flex libssl-dev libelf-dev
15+
}
16+
17+
component_build() {
18+
"$SELF/scripts/build-kernel.sh" "$WORK" "$WORK/component-stages/kernel"
19+
}

os/mkosi/components/nvattest.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# shellcheck shell=bash disable=SC2034
3+
COMPONENT_NAME=nvattest
4+
COMPONENT_CACHE_PATHS=(component-stages/nvattest)
5+
COMPONENT_ROOTFS_TREES=(component-stages/nvattest)
6+
COMPONENT_KERNEL_TREES=()
7+
8+
component_cache_key() {
9+
key_value "$NVATTEST_VERSION" "$NVATTEST_REVISION"
10+
key_file "$SELF/scripts/build-nvattest.sh"
11+
key_tree os/mkosi/patches/nvattest \
12+
os/yocto/layers/meta-nvidia/recipes-graphics/nvattest
13+
key_tools gcc cmake ninja rustc cargo
14+
key_packages libssl-dev libcurl4-openssl-dev
15+
}
16+
17+
component_build() {
18+
"$SELF/scripts/build-nvattest.sh" "$WORK/nvattest-build" \
19+
"$WORK/component-stages/nvattest"
20+
}

os/mkosi/components/nvidia.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# shellcheck shell=bash disable=SC2034
3+
COMPONENT_NAME=nvidia
4+
COMPONENT_CACHE_PATHS=(component-stages/nvidia-root component-stages/nvidia-kernel)
5+
COMPONENT_ROOTFS_TREES=(component-stages/nvidia-root)
6+
COMPONENT_KERNEL_TREES=(component-stages/nvidia-kernel)
7+
8+
component_cache_key() {
9+
key_dependency kernel
10+
key_value "$NVIDIA_VERSION" "$NVIDIA_RUN_SHA256" \
11+
"$NVIDIA_FABRICMANAGER_SHA256" "$NVIDIA_NSCQ_SHA256"
12+
key_file "$SELF/scripts/build-nvidia.sh" \
13+
"$SELF/patches/nvidia/0001-linux-7.1-drop-legacy-of-gpio-api.patch"
14+
key_tree os/yocto/layers/meta-nvidia/recipes-graphics/nvidia
15+
key_tools gcc make
16+
}
17+
18+
component_build() {
19+
"$SELF/scripts/build-nvidia.sh" "$WORK/nvidia-build" \
20+
"$WORK/linux-$KERNEL_VERSION" "$WORK/kernel-build" \
21+
"$WORK/component-stages/nvidia-root" "$WORK/component-stages/nvidia-kernel"
22+
}
23+
24+
component_prepare_outputs() {
25+
find "$WORK/component-stages/nvidia-kernel/usr/lib/modules" -maxdepth 2 \
26+
-type f -name 'modules.*' -delete
27+
}

os/mkosi/components/ovmf.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# shellcheck shell=bash disable=SC2034
3+
COMPONENT_NAME=ovmf
4+
COMPONENT_CACHE_PATHS=(component-stages/ovmf)
5+
COMPONENT_ROOTFS_TREES=()
6+
COMPONENT_KERNEL_TREES=(component-stages/ovmf)
7+
8+
component_cache_key() {
9+
key_file "$SELF/scripts/build-ovmf.sh" \
10+
"$ROOT/os/yocto/layers/meta-dstack/recipes-core/dstack-ovmf/dstack-ovmf/0004-Reproduciable.patch"
11+
key_tools gcc make python3
12+
key_packages nasm acpica-tools uuid-dev
13+
}
14+
15+
component_build() {
16+
mkdir -p "$WORK/component-stages/ovmf"
17+
"$SELF/scripts/build-ovmf.sh" "$WORK/ovmf-build" \
18+
"$WORK/component-stages/ovmf/ovmf.fd" \
19+
"$WORK/component-stages/ovmf/ovmf-sev.fd"
20+
}

os/mkosi/components/sysbox.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# shellcheck shell=bash disable=SC2034
3+
COMPONENT_NAME=sysbox
4+
COMPONENT_CACHE_PATHS=(component-stages/sysbox)
5+
COMPONENT_ROOTFS_TREES=(component-stages/sysbox)
6+
COMPONENT_KERNEL_TREES=()
7+
8+
component_cache_key() {
9+
key_value "$SYSBOX_VERSION" "$SYSBOX_REVISION" "$SYSBOX_RUNC_REVISION" \
10+
"$SYSBOX_FS_REVISION" "$SYSBOX_MGR_REVISION" "$SYSBOX_IPC_REVISION" \
11+
"$SYSBOX_LIBS_REVISION" "$SYSBOX_FUSE_REVISION"
12+
key_file "$SELF/scripts/build-sysbox.sh"
13+
key_tree os/yocto/layers/meta-dstack/recipes-core/dstack-sysbox
14+
key_tools go
15+
key_packages libseccomp-dev
16+
}
17+
18+
component_build() {
19+
"$SELF/scripts/build-sysbox.sh" "$WORK/sysbox-build" \
20+
"$WORK/component-stages/sysbox"
21+
}

os/mkosi/components/zfs.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# shellcheck shell=bash disable=SC2034
3+
COMPONENT_NAME=zfs
4+
COMPONENT_CACHE_PATHS=(component-stages/zfs-root component-stages/zfs-kernel)
5+
COMPONENT_ROOTFS_TREES=(component-stages/zfs-root)
6+
COMPONENT_KERNEL_TREES=(component-stages/zfs-kernel)
7+
8+
component_cache_key() {
9+
key_dependency kernel
10+
key_value "$ZFS_VERSION" "$ZFS_REVISION"
11+
key_file "$SELF/scripts/build-zfs.sh" \
12+
"$SELF/patches/zfs/0001-linux-6.19-7.1-compat.patch" \
13+
"$ROOT/os/yocto/layers/meta-dstack/recipes-core/dstack-zfs/dstack-zfs/0001-Define-strndupa-if-it-does-not-exist.patch"
14+
key_tools gcc make autoconf automake
15+
key_packages libssl-dev libelf-dev zlib1g-dev libtool uuid-dev
16+
}
17+
18+
component_build() {
19+
"$SELF/scripts/build-zfs.sh" "$WORK/zfs-build" \
20+
"$WORK/linux-$KERNEL_VERSION" "$WORK/kernel-build" \
21+
"$WORK/component-stages/zfs-root" "$WORK/component-stages/zfs-kernel"
22+
}
23+
24+
component_prepare_outputs() {
25+
find "$WORK/component-stages/zfs-kernel/usr/lib/modules" -maxdepth 2 \
26+
-type f -name 'modules.*' -delete
27+
}
Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,35 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: Apache-2.0
3-
# Build and compose every non-Debian guest component. Cache-aware staging is
4-
# kept here so the release pipeline in build.sh remains cache-agnostic.
53
set -euo pipefail
64
ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)
75
SELF="$ROOT/os/mkosi"
86
# shellcheck source=/dev/null
97
source "$SELF/versions.env"
108
# shellcheck source=/dev/null
119
source "$SELF/scripts/dev-cache.sh"
10+
# shellcheck source=/dev/null
11+
source "$SELF/scripts/component-framework.sh"
1212

1313
use_cache=0
1414
if [[ ${1:-} == --dev-cache ]]; then use_cache=1; shift; fi
15-
WORK=$(realpath -m "${1:?work directory required}")
16-
STAGE=$(realpath -m "${2:?rootfs staging tree required}")
17-
KSTAGE=$(realpath -m "${3:?kernel staging tree required}")
18-
FLAVOR=${4:?flavor required}
19-
COMPONENTS="$WORK/component-stages"
20-
mkdir -p "$STAGE" "$KSTAGE" "$COMPONENTS"
21-
dev_cache_init "$use_cache" "$ROOT" "$FLAVOR" "${SOURCE_DATE_EPOCH:?}"
22-
23-
merge() { cp -a "$1/." "$2/"; }
24-
25-
root="$COMPONENTS/dstack-rust"
26-
dev_cache_run dstack-rust "$WORK" component-stages/dstack-rust -- \
27-
"$SELF/scripts/stage-rootfs.sh" "$root" "$FLAVOR"
28-
merge "$root" "$STAGE"
29-
30-
root="$COMPONENTS/container-stack"
31-
dev_cache_run container-stack "$WORK" component-stages/container-stack -- \
32-
"$SELF/scripts/build-container-stack.sh" "$WORK/container-stack-build" "$root"
33-
merge "$root" "$STAGE"
34-
35-
root="$COMPONENTS/sysbox"
36-
dev_cache_run sysbox "$WORK" component-stages/sysbox -- \
37-
"$SELF/scripts/build-sysbox.sh" "$WORK/sysbox-build" "$root"
38-
merge "$root" "$STAGE"
39-
40-
root="$COMPONENTS/nvattest"
41-
dev_cache_run nvattest "$WORK" component-stages/nvattest -- \
42-
"$SELF/scripts/build-nvattest.sh" "$WORK/nvattest-build" "$root"
43-
merge "$root" "$STAGE"
44-
45-
dev_cache_run kernel "$WORK" "linux-$KERNEL_VERSION" kernel-build kernel-stage -- \
46-
"$SELF/scripts/build-kernel.sh" "$WORK" "$KSTAGE"
47-
48-
root="$COMPONENTS/nvidia-root" modules="$COMPONENTS/nvidia-kernel"
49-
dev_cache_run nvidia "$WORK" component-stages/nvidia-root component-stages/nvidia-kernel -- \
50-
"$SELF/scripts/build-nvidia.sh" "$WORK/nvidia-build" \
51-
"$WORK/linux-$KERNEL_VERSION" "$WORK/kernel-build" "$root" "$modules"
52-
merge "$root" "$STAGE"; merge "$modules" "$KSTAGE"
53-
54-
root="$COMPONENTS/zfs-root" modules="$COMPONENTS/zfs-kernel"
55-
dev_cache_run zfs "$WORK" component-stages/zfs-root component-stages/zfs-kernel -- \
56-
"$SELF/scripts/build-zfs.sh" "$WORK/zfs-build" \
57-
"$WORK/linux-$KERNEL_VERSION" "$WORK/kernel-build" "$root" "$modules"
58-
merge "$root" "$STAGE"; merge "$modules" "$KSTAGE"
59-
60-
root="$COMPONENTS/ovmf"; mkdir -p "$root"
61-
dev_cache_run ovmf "$WORK" component-stages/ovmf -- \
62-
"$SELF/scripts/build-ovmf.sh" "$WORK/ovmf-build" \
63-
"$root/ovmf.fd" "$root/ovmf-sev.fd"
64-
install -Dm0644 "$root/ovmf.fd" "$KSTAGE/ovmf.fd"
65-
install -Dm0644 "$root/ovmf-sev.fd" "$KSTAGE/ovmf-sev.fd"
15+
work=${1:?work directory required}
16+
stage=${2:?rootfs staging tree required}
17+
kstage=${3:?kernel staging tree required}
18+
flavor=${4:?flavor required}
19+
component_framework_init "$use_cache" "$ROOT" "$SELF" \
20+
"$(realpath -m "$work")" "$(realpath -m "$stage")" \
21+
"$(realpath -m "$kstage")" "$flavor"
22+
23+
components=(
24+
dstack-rust
25+
container-stack
26+
sysbox
27+
nvattest
28+
kernel
29+
nvidia
30+
zfs
31+
ovmf
32+
)
33+
34+
for component in "${components[@]}"; do component_run "$component"; done
35+
component_assemble

0 commit comments

Comments
 (0)