@@ -9,10 +9,14 @@ action=${1:-image}
99BUILD_DIR=${2:- $SELF / build}
1010BUILD_DIR=$( realpath -m " $BUILD_DIR " )
1111case " $action " in
12- image|repro-check|lint) ;;
13- * ) echo " Usage: $0 {image|repro-check|lint} [build-dir]" >&2 ; exit 2 ;;
12+ image|dev-image| repro-check|lint) ;;
13+ * ) echo " Usage: $0 {image|dev-image| repro-check|lint} [build-dir]" >&2 ; exit 2 ;;
1414esac
1515if [[ $action == lint ]]; then exec " $SELF /tests/acceptance.sh" ; fi
16+ unset DSTACK_DEV_CACHE_ACTIVE
17+ [[ $action == dev-image ]] && export DSTACK_DEV_CACHE_ACTIVE=1
18+ # shellcheck source=/dev/null
19+ source " $SELF /scripts/dev-cache.sh"
1620command -v mkosi > /dev/null || { echo ' mkosi >= 26 is required' >&2 ; exit 1; }
1721actual=$( mkosi --version | awk ' {print $2}' | cut -d. -f1)
1822(( actual >= MKOSI_MIN_VERSION )) || { echo " mkosi >= $MKOSI_MIN_VERSION required" >&2 ; exit 1; }
@@ -22,18 +26,84 @@ export TZ=UTC LC_ALL=C
2226build_one () {
2327 local out=$1 work=$2 flavor=$3
2428 local stage=" $work /rootfs-stage" kstage=" $work /kernel-stage" tree=" $work /rootfs"
25- rm -rf " $work " " $out " ; mkdir -p " $stage " " $kstage " " $out "
26- " $SELF /scripts/stage-rootfs.sh" " $stage " " $flavor "
27- " $SELF /scripts/build-container-stack.sh" " $work /container-stack-build" " $stage "
28- " $SELF /scripts/build-sysbox.sh" " $work /sysbox-build" " $stage "
29- " $SELF /scripts/build-nvattest.sh" " $work /nvattest-build" " $stage "
30- " $SELF /scripts/build-kernel.sh" " $work " " $kstage "
31- " $SELF /scripts/build-nvidia.sh" " $work /nvidia-build" \
32- " $work /linux-$KERNEL_VERSION " " $work /kernel-build" " $stage " " $kstage "
33- " $SELF /scripts/build-zfs.sh" " $work /zfs-build" \
34- " $work /linux-$KERNEL_VERSION " " $work /kernel-build" " $stage " " $kstage "
35- " $SELF /scripts/build-ovmf.sh" " $work /ovmf-build" \
36- " $kstage /ovmf.fd" " $kstage /ovmf-sev.fd"
29+ local components=" $work /component-stages" source_fingerprint=disabled tool_fingerprint=disabled
30+ rm -rf " $work " " $out " ; mkdir -p " $stage " " $kstage " " $out " " $components "
31+ if [[ ${DSTACK_DEV_CACHE_ACTIVE:- 0} == 1 ]]; then
32+ source_fingerprint=$(
33+ git -C " $ROOT " ls-files -z --cached --others --exclude-standard -- \
34+ dstack os/common os/mkosi os/yocto/layers/meta-dstack \
35+ os/yocto/layers/meta-nvidia \
36+ | sort -z | while IFS= read -r -d ' ' input; do
37+ if [[ -f $ROOT /$input ]]; then
38+ sha256sum " $ROOT /$input "
39+ elif [[ -d $ROOT /$input ]]; then
40+ printf ' gitlink %s %s\n' " $input " \
41+ " $( git -C " $ROOT /$input " rev-parse HEAD) "
42+ else
43+ printf ' missing %s\n' " $input "
44+ fi
45+ done | sha256sum | cut -d' ' -f1
46+ )
47+ tool_fingerprint=$( {
48+ gcc --version | head -1; ld --version | head -1; go version
49+ rustc --version; cargo --version; cmake --version | head -1
50+ make --version | head -1; pahole --version; tar --version | head -1
51+ } | sha256sum | cut -d' ' -f1)
52+ fi
53+ component_key () {
54+ dev_cache_key " $1 " " $flavor " " $source_fingerprint " \
55+ " $tool_fingerprint " " $SOURCE_DATE_EPOCH " " $( uname -m) "
56+ }
57+ merge_stage () { cp -a " $1 /." " $2 /" ; }
58+
59+ base_stage=" $components /dstack-rust"
60+ dev_cache_run dstack-rust " $( component_key dstack-rust) " " $work " 1 \
61+ component-stages/dstack-rust -- \
62+ " $SELF /scripts/stage-rootfs.sh" " $base_stage " " $flavor "
63+ merge_stage " $base_stage " " $stage "
64+
65+ container_stage=" $components /container-stack"
66+ dev_cache_run container-stack " $( component_key container-stack) " " $work " 1 \
67+ component-stages/container-stack -- \
68+ " $SELF /scripts/build-container-stack.sh" " $work /container-stack-build" " $container_stage "
69+ merge_stage " $container_stage " " $stage "
70+
71+ sysbox_stage=" $components /sysbox"
72+ dev_cache_run sysbox " $( component_key sysbox) " " $work " 1 \
73+ component-stages/sysbox -- \
74+ " $SELF /scripts/build-sysbox.sh" " $work /sysbox-build" " $sysbox_stage "
75+ merge_stage " $sysbox_stage " " $stage "
76+
77+ nvattest_stage=" $components /nvattest"
78+ dev_cache_run nvattest " $( component_key nvattest) " " $work " 1 \
79+ component-stages/nvattest -- \
80+ " $SELF /scripts/build-nvattest.sh" " $work /nvattest-build" " $nvattest_stage "
81+ merge_stage " $nvattest_stage " " $stage "
82+
83+ dev_cache_run kernel " $( component_key kernel) " " $work " 3 \
84+ " linux-$KERNEL_VERSION " kernel-build kernel-stage -- \
85+ " $SELF /scripts/build-kernel.sh" " $work " " $kstage "
86+
87+ nvidia_root=" $components /nvidia-root" nvidia_kernel=" $components /nvidia-kernel"
88+ dev_cache_run nvidia " $( component_key nvidia) " " $work " 2 \
89+ component-stages/nvidia-root component-stages/nvidia-kernel -- \
90+ " $SELF /scripts/build-nvidia.sh" " $work /nvidia-build" \
91+ " $work /linux-$KERNEL_VERSION " " $work /kernel-build" " $nvidia_root " " $nvidia_kernel "
92+ merge_stage " $nvidia_root " " $stage " ; merge_stage " $nvidia_kernel " " $kstage "
93+
94+ zfs_root=" $components /zfs-root" zfs_kernel=" $components /zfs-kernel"
95+ dev_cache_run zfs " $( component_key zfs) " " $work " 2 \
96+ component-stages/zfs-root component-stages/zfs-kernel -- \
97+ " $SELF /scripts/build-zfs.sh" " $work /zfs-build" \
98+ " $work /linux-$KERNEL_VERSION " " $work /kernel-build" " $zfs_root " " $zfs_kernel "
99+ merge_stage " $zfs_root " " $stage " ; merge_stage " $zfs_kernel " " $kstage "
100+
101+ ovmf_stage=" $components /ovmf" ; mkdir -p " $ovmf_stage "
102+ dev_cache_run ovmf " $( component_key ovmf) " " $work " 1 component-stages/ovmf -- \
103+ " $SELF /scripts/build-ovmf.sh" " $work /ovmf-build" \
104+ " $ovmf_stage /ovmf.fd" " $ovmf_stage /ovmf-sev.fd"
105+ install -Dm0644 " $ovmf_stage /ovmf.fd" " $kstage /ovmf.fd"
106+ install -Dm0644 " $ovmf_stage /ovmf-sev.fd" " $kstage /ovmf-sev.fd"
37107 # ExtraTrees is copied over Debian's usr-merged root where /bin, /sbin and
38108 # /lib are symlinks. Normalize build systems (notably OpenZFS) that install
39109 # into the legacy physical directories before handing the tree to mkosi.
84154 " $SELF /tests/check-output.sh" " $out /$release_name -$DSTACK_VERSION " " $flavor "
85155}
86156
87- if [[ $action == image ]]; then
157+ if [[ $action == image || $action == dev-image ]]; then
88158 for flavor in $FLAVORS ; do build_one " $BUILD_DIR /out/$flavor " " $BUILD_DIR /work-$flavor " " $flavor " ; done
89159 exit
90160fi
0 commit comments