Skip to content

Commit 1d097fc

Browse files
LZhaoMRadxaYuntian
authored andcommitted
feat: add building with snapshot support
1 parent 51bf7a7 commit 1d097fc

File tree

4 files changed

+70
-21
lines changed

4 files changed

+70
-21
lines changed

src/libexec/rsdk/rsdk-build

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ generate_rootfs() {
5353
JSONNET_ARGS+=("--tla-str" "distro_mirror=$RSDK_OPTION_DISTRO_MIRROR")
5454
fi
5555

56+
if [[ -n ${RSDK_OPTION_SNAPSHOT_TIMESTAMP} ]]; then
57+
JSONNET_ARGS+=("--tla-str" "snapshot_timestamp=$RSDK_OPTION_SNAPSHOT_TIMESTAMP")
58+
fi
59+
5660
if [[ -n ${RSDK_OPTION_RADXA_MIRROR} ]]; then
5761
JSONNET_ARGS+=("--tla-str" "radxa_mirror=$RSDK_OPTION_RADXA_MIRROR")
5862
fi
@@ -177,7 +181,7 @@ main() {
177181
source "$SCRIPT_DIR/../../lib/rsdk/utils.sh"
178182

179183
local TEMP
180-
if ! TEMP="$(getopt -o "hdPTm:M:i:k:f:p:s:" -l "no-efi,help,debug,dry-run,no-pkgs-json,test-repo,mirror:,image-name:,no-cache,override-kernel:,override-firmware:,override-product:,no-vendor-packages,debs:,sdboot,sector-size:" -n "$0" -- "$@")"; then
184+
if ! TEMP="$(getopt -o "hdPTm:M:i:k:f:p:s:" -l "no-efi,help,debug,dry-run,no-pkgs-json,test-repo,mirror:,image-name:,no-cache,override-kernel:,override-firmware:,override-product:,no-vendor-packages,debs:,sdboot,sector-size:,snapshot:" -n "$0" -- "$@")"; then
181185
return
182186
fi
183187
eval set -- "$TEMP"
@@ -186,6 +190,7 @@ main() {
186190
local RSDK_OPTION_DEBUG="${RSDK_OPTION_DEBUG:-false}"
187191
local RSDK_OPTION_REPO_SUFFIX="${RSDK_OPTION_REPO_SUFFIX:-}"
188192
local RSDK_OPTION_DISTRO_MIRROR="${RSDK_OPTION_DISTRO_MIRROR:-}"
193+
local RSDK_OPTION_SNAPSHOT_TIMESTAMP="${RSDK_OPTION_SNAPSHOT_TIMESTAMP:-}"
189194
local RSDK_OPTION_RADXA_MIRROR="${RSDK_OPTION_RADXA_MIRROR:-}"
190195
local RSDK_OPTION_ROOTFS="${RSDK_OPTION_ROOTFS:-rootfs.tar}"
191196
local RSDK_OPTION_IMAGE_NAME="${RSDK_OPTION_IMAGE_NAME:-$("$SCRIPT_DIR/../../bin/rsdk" config build.default_image_name)}"
@@ -227,6 +232,10 @@ main() {
227232
RSDK_OPTION_DISTRO_MIRROR="$1"
228233
shift
229234
;;
235+
--snapshot)
236+
RSDK_OPTION_SNAPSHOT_TIMESTAMP="$1"
237+
shift
238+
;;
230239
-M)
231240
RSDK_OPTION_RADXA_MIRROR="$1"
232241
RSDK_OPTION_PKGS_JSON="false"
@@ -287,6 +296,13 @@ main() {
287296
return 1
288297
fi
289298

299+
# If '--snapshot' and '-m | --mirror' switch on at the same time, exit
300+
# with error because they are not compatible
301+
if [[ -n $RSDK_OPTION_SNAPSHOT_TIMESTAMP ]] && [[ -n $RSDK_OPTION_DISTRO_MIRROR ]]; then
302+
echo "You can not use snapshot when using custom Debian / Ubuntu archive mirror." >&2
303+
return 1
304+
fi
305+
290306
SUITE="${2:-$(jq -er --arg product "$PRODUCT" '.[] | select(.product == $product).supported_suite[0]' "$SCRIPT_DIR/../../share/rsdk/configs/products.json")}"
291307
EDITION="${3:-$(jq -er --arg product "$PRODUCT" '.[] | select(.product == $product).supported_edition[0]' "$SCRIPT_DIR/../../share/rsdk/configs/products.json")}"
292308
local OUTPUT="$PWD/out/${PRODUCT}_${SUITE}_${EDITION}"

src/libexec/rsdk/rsdk-help

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Build RadxaOS system image.
3737
Build using Radxa APT test archives.
3838
-m | --mirror <mirror_url>
3939
Specify custom Debian / Ubuntu archive mirror URL.
40+
--snapshot <timestamp>
41+
Build using Debian / Ubuntu snapshot archive.
42+
A timestamp is required. Ex: 20260105T082626Z.
43+
This is incompatible with '-m | --mirror <mirror_url>'.
4044
-M <mirror_url>
4145
Specify custom non-Debian non-Ubuntu archive mirror URL. This mirror should
4246
serve both Radxa archives as well as any other 3rd party archives.

src/share/rsdk/build/mod/distro.libjsonnet

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,49 @@
11
local distro_check = import "../../configs/distro_check.libjsonnet";
22

3-
local distro_base(suite, distro_mirror, distro, architecture, distro_mirror_default) = {
3+
local mirror_link(
4+
distro_mirror,
5+
snapshot_timestamp,
6+
distro,
7+
architecture,
8+
distro_mirror_default,
9+
snapshot_mirror_default
10+
) = if snapshot_timestamp != ""
11+
then
12+
// Build with snapshot service
13+
snapshot_mirror_default + snapshot_timestamp
14+
else
15+
(if distro_mirror == ""
16+
then
17+
// Primary archive
18+
distro_mirror_default
19+
else
20+
distro_mirror) + "/" +
21+
(if distro == "ubuntu" && architecture != "amd64"
22+
then
23+
distro + "-ports"
24+
else
25+
distro);
26+
27+
local distro_base(
28+
suite,
29+
distro_mirror,
30+
distro,
31+
architecture,
32+
snapshot_timestamp,
33+
distro_mirror_default,
34+
snapshot_mirror_default,
35+
) = {
436
mmdebstrap+: {
537
components+: [
638
"main",
739
],
840
mirrors+: [
9-
// Primary archive
10-
(if distro_mirror == ""
11-
then
12-
distro_mirror_default
13-
else
14-
distro_mirror)
15-
+ "/" +
16-
(if distro == "ubuntu" && architecture != "amd64"
17-
then
18-
distro + "-ports"
19-
else
20-
distro),
41+
mirror_link(distro_mirror,
42+
snapshot_timestamp,
43+
distro,
44+
architecture,
45+
distro_mirror_default,
46+
snapshot_mirror_default),
2147
],
2248
"setup-hooks"+: [
2349
|||
@@ -26,7 +52,7 @@ local distro_base(suite, distro_mirror, distro, architecture, distro_mirror_defa
2652
# backports archive
2753
head -n 1 "$1/etc/apt/sources.list" | sed -E -e "s/(%(suite)s)/\\1-backports/" > "$1/etc/apt/sources.list.d/50-%(suite)s-backports.list"
2854
# security archive
29-
head -n 1 "$1/etc/apt/sources.list" | sed -E -e "s/(%(suite)s)/\\1-security/" -e "s|/debian |/debian-security |" > "$1/etc/apt/sources.list.d/50-%(suite)s-security.list"
55+
head -n 1 "$1/etc/apt/sources.list" | sed -E -e "s/(%(suite)s)/\\1-security/" -e "s|/debian|/debian-security|" > "$1/etc/apt/sources.list.d/50-%(suite)s-security.list"
3056
# main archive
3157
mv "$1/etc/apt/sources.list" "$1/etc/apt/sources.list.d/50-%(suite)s.list"
3258
||| % {
@@ -53,8 +79,9 @@ local distro_debian(
5379
suite,
5480
distro_mirror,
5581
architecture,
82+
snapshot_timestamp,
5683
distro = "debian",
57-
) = distro_base(suite, distro_mirror, distro, architecture, "https://deb.debian.org") + {
84+
) = distro_base(suite, distro_mirror, distro, architecture, snapshot_timestamp, "https://deb.debian.org", "https://snapshot.debian.org/archive/debian/") + {
5885
mmdebstrap+: {
5986
components+: std.prune([
6087
"contrib",
@@ -68,8 +95,9 @@ local distro_ubuntu(
6895
suite,
6996
distro_mirror,
7097
architecture,
98+
snapshot_timestamp,
7199
distro = "ubuntu",
72-
) = distro_base(suite, distro_mirror, distro, architecture, "http://ports.ubuntu.com") + {
100+
) = distro_base(suite, distro_mirror, distro, architecture, snapshot_timestamp, "http://ports.ubuntu.com", "https://snapshot.ubuntu.com/ubuntu/") + {
73101
mmdebstrap+: {
74102
components+: [
75103
"restricted",
@@ -79,10 +107,10 @@ local distro_ubuntu(
79107
}
80108
};
81109

82-
function(suite, distro_mirror, architecture)
110+
function(suite, distro_mirror, architecture, snapshot_timestamp)
83111
if distro_check(suite) == "debian"
84112
then
85-
distro_debian(suite, distro_mirror, architecture)
113+
distro_debian(suite, distro_mirror, architecture, snapshot_timestamp)
86114
else if distro_check(suite) == "ubuntu"
87115
then
88-
distro_ubuntu(suite, distro_mirror, architecture)
116+
distro_ubuntu(suite, distro_mirror, architecture, snapshot_timestamp)

src/share/rsdk/build/rootfs.jsonnet

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function(
1414
rsdk_rev = "",
1515

1616
distro_mirror = "",
17+
snapshot_timestamp = "",
1718

1819
radxa_mirror = "",
1920
radxa_repo_suffix = "",
@@ -28,7 +29,7 @@ function(
2829
firmware_override = "",
2930
install_vscodium = false,
3031
use_pkgs_json = true,
31-
) distro(suite, distro_mirror, architecture)
32+
) distro(suite, distro_mirror, architecture, snapshot_timestamp)
3233
+ additional_repos(suite, radxa_mirror, radxa_repo_suffix, product, temp_dir, install_vscodium, use_pkgs_json)
3334
+ packages(suite, edition, product, temp_dir, vendor_packages, linux_override, firmware_override)
3435
+ cleanup()

0 commit comments

Comments
 (0)