Skip to content

Commit ec54542

Browse files
committed
Stamp git info and build ID into the image
Capture this image build's git state and a BUILD_ID (CI-provided, or a UTC timestamp fallback) and write both into /etc/os-release of @minimal before it is snapshotted to @Minimal_stock, so every profile inherits them via COW. Resolve the os-release symlink so the real file is edited in place. The MOTD and login banner now report the build ID instead of a decoded timestamp.
1 parent b78ed2f commit ec54542

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

build-rootfs-img.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55

66
set -e
77

8+
# Capture Git information
9+
[ -n "${GIT_HASH}" ] || GIT_HASH=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
10+
[ -n "${GIT_BRANCH}" ] || GIT_BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null || git describe --tags --exact-match 2>/dev/null || echo "detached")
11+
[ -n "${GIT_MSG}" ] || GIT_MSG=$(git log -1 --pretty=format:"%s" 2>/dev/null | sed 's/[\"()]/\\&/g; s/'"'"'/\\&/g' || echo "unknown")
12+
[ -n "${GIT_INFO}" ] || GIT_INFO="${GIT_BRANCH}@${GIT_HASH}: ${GIT_MSG}"
13+
GIT_INFO=$(echo "$GIT_INFO" | tr -dc '[:alnum:][:space:]')
14+
15+
# Build identifier: CI sets BUILD_ID in the environment (e.g. "build-1419"); otherwise
16+
# fall back to a UTC timestamp, same default/format as build-images.sh.
17+
: "${BUILD_ID:=$(date -u '+%Y%m%d-%H%M')}"
18+
819
if [ -c /dev/kvm -a -w /dev/kvm ]; then
920
# Have virtualization support, can use fakemachine (default, fast, safe)
1021
DEBOS="debos -c $(nproc) -m 6Gb"
@@ -29,7 +40,7 @@ mkdir -p "$IMG_OUT"/linux_tmp
2940
cp -r "$LINUX_OUT"/* "$IMG_OUT"/linux_tmp
3041

3142
echo "Creating the root FS image"
32-
$DEBOS --artifactdir="$IMG_OUT" -t imagesize:"$IMGSIZE" -t kerneldir:linux_tmp debian-rk3576-img.yaml
43+
$DEBOS --artifactdir="$IMG_OUT" -t imagesize:"$IMGSIZE" -t kerneldir:linux_tmp -t gitinfo:"$GIT_INFO" -t buildid:"$BUILD_ID" debian-rk3576-img.yaml
3344
sync "$IMG_OUT"/debian-nobootloader.img
3445

3546
owner=$(stat -c %u "$IMG_OUT"/debian-nobootloader.img)

debian-rk3576-img.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
{{ $kerneldir := or .kerneldir "prebuilt/linux" }}
44
{{ $cmdline := or .cmdline "audit=0 console=tty1 console=ttyS0,1500000n8" }}
55
{{ $fslabel := or .fslabel "flipperos" }}
6+
{{ $gitinfo := or .gitinfo "unknown" }}
7+
{{ $buildid := or .buildid "unknown" }}
68
{{- /* fs-wide btrfs mount options. ssd is FORCED (loopback/eMMC isn't reliably
79
detected as non-rotational). */ -}}
810
{{ $btrfsopts := or .btrfsopts "compress=zstd,noatime,ssd,discard=async" }}
@@ -130,6 +132,21 @@ actions:
130132
chroot: true
131133
command: systemctl set-default multi-user.target
132134

135+
# The ospack tarball already carries a BUILD_GIT (the ospack build's git state), and the
136+
# ospack is cached/reused across image builds. Replace it with THIS image build's git
137+
# state so the stamp reflects the actual image. Stamped into @Minimal before it is snapshotted
138+
# to @Minimal_stock, so every profile inherits it via COW. Both are consumed by the MOTD/banner.
139+
- action: run
140+
description: Save GIT info
141+
chroot: true
142+
command: |
143+
# /etc/os-release is normally a symlink to /usr/lib/os-release; resolve it so
144+
# sed edits the real file in place instead of replacing the symlink.
145+
osr="$(readlink -f /etc/os-release)"
146+
sed -i '/^BUILD_GIT=/d; /^BUILD_ID=/d' "$osr"
147+
echo 'BUILD_GIT="{{ $gitinfo }}"' >> "$osr"
148+
echo 'BUILD_ID={{ $buildid }}' >> "$osr"
149+
133150
# ===========================================================================
134151
# Stock (RO) bases + per-profile bootable roots.
135152
#

0 commit comments

Comments
 (0)