Skip to content

Commit

Permalink
Merge pull request #6 from reubenmiller/add-build-info
Browse files Browse the repository at this point in the history
Add build info to image and publish firmware version
  • Loading branch information
reubenmiller authored Nov 21, 2023
2 parents e60b082 + ad3adba commit d4b1d69
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 10 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/bake-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
env:
PI_BASE_IMAGE: "https://downloads.raspberrypi.org/raspios_lite_arm64/images/raspios_lite_arm64-2023-10-10/2023-10-10-raspios-bookworm-arm64-lite.img.xz"

jobs:
jobs:
bake-image:
name: Bake Image
runs-on: ubuntu-latest
Expand All @@ -18,21 +18,22 @@ jobs:
with:
submodules: recursive

- uses: extractions/setup-just@v1

- name: Set image name
run: echo "IMAGE_NAME=tedge_rugpi_$(date +'%Y-%m-%d-%H%M').img" >> $GITHUB_ENV
run: echo "IMAGE_NAME=$(just generate_version)" >> $GITHUB_ENV

- name: Install QEMU
run: docker run --privileged --rm tonistiigi/binfmt --install arm64

- name: Extract Image
run: ./run-bakery extract ${{ env.PI_BASE_IMAGE }} build/base.tar
run: just extract

- name: Customize System
run: ./run-bakery customize build/base.tar build/customized.tar
run: just customize

- name: Bake Image
run:
./run-bakery bake build/customized.tar build/${{ env.IMAGE_NAME }}
run: just bake

- name: Upload Image
uses: actions/upload-artifact@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.rugpi
/build
recipes/build-info/files/.build_info
**/debian-packages.list
9 changes: 8 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
export IMAGE_URL := "https://downloads.raspberrypi.org/raspios_lite_arm64/images/raspios_lite_arm64-2023-10-10/2023-10-10-raspios-bookworm-arm64-lite.img.xz"
export RUGPI_IMAGE := "ghcr.io/silitics/rugpi-bakery:latest"

export IMAGE_NAME := replace_regex(file_stem(IMAGE_URL), ".img$", "")
export IMAGE_NAME := env_var_or_default("IMAGE_NAME", replace_regex(file_stem(IMAGE_URL), ".img$", ""))
export BASE_TAR := "build" / IMAGE_NAME + ".base.tar"
export CUSTOM_TAR := "build" / IMAGE_NAME + ".tedge.tar"
export OUTPUT_IMAGE := "build" / IMAGE_NAME + ".tedge.img"
export BUILD_INFO := file_stem(IMAGE_NAME)

# Generate a version name (that can be used in follow up commands)
generate_version:
@echo "tedge_rugpi_$(date +'%Y-%m-%d-%H%M').img"

# Show the install paths
show:
Expand All @@ -14,6 +19,7 @@ show:
@echo "BASE_TAR: {{BASE_TAR}}"
@echo "CUSTOM_TAR: {{CUSTOM_TAR}}"
@echo "OUTPUT_IMAGE: {{OUTPUT_IMAGE}}"
@echo "BUILD_INFO: {{BUILD_INFO}}"

# Clean build and cache
clean:
Expand All @@ -25,6 +31,7 @@ extract:

# Apply recipes to the base image
customize:
echo "{{BUILD_INFO}}" > "{{justfile_directory()}}/recipes/build-info/files/.build_info"
./run-bakery customize "{{BASE_TAR}}" "{{CUSTOM_TAR}}"

# Create the image that can be flashed to an SD card or applied using the rugpi interface
Expand Down
Empty file.
2 changes: 2 additions & 0 deletions recipes/build-info/recipe.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
description = "Add build-info about the image"
priority = -1 # Execute at the end
10 changes: 10 additions & 0 deletions recipes/build-info/steps/00-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
set -e

BUILD_INFO_HOST="$RECIPE_DIR/files/.build_info"
BUILD_INFO_TARGET=/etc/.build_info

if [ -f "$BUILD_INFO_HOST" ]; then
echo "Adding build-info: $BUILD_INFO_TARGET"
cat "$BUILD_INFO_HOST" > "$BUILD_INFO_TARGET"
fi
10 changes: 10 additions & 0 deletions recipes/rugpi-auto-rollback/files/healthcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ HOT=$(/usr/bin/rugpi-ctrl system info | grep Hot | cut -d: -f2 | xargs)
DEFAULT=$(/usr/bin/rugpi-ctrl system info | grep Default | cut -d: -f2 | xargs)
DEVICE_ID="$(tedge config get device.id)"
TARGET="$(tedge config get mqtt.topic_root)/$(tedge config get mqtt.device_topic_id)"
BUILD_INFO=/etc/.build_info

log "Current rugpi-ctrl state:"
/usr/bin/rugpi-ctrl system info | log_r
Expand Down Expand Up @@ -64,6 +65,15 @@ collect_rugpi() {
if [ -z "$DEVICE_ID" ]; then
return 0
fi

# Collect firmware information
if [ -f "$BUILD_INFO" ]; then
name=$(cut -d_ -f1-2 "$BUILD_INFO")
version=$(cut -d_ -f3- "$BUILD_INFO")
fi
PAYLOAD=$(printf '{"name":"%s","version":"%s"}' "${name:-tedge_rugpi}" "${version:-unknown}")
tedge mqtt pub -q 1 -r "$TARGET/twin/c8y_Firmware" "$PAYLOAD" ||:

# Collect rugpi state information, e.g. which partition is active
PAYLOAD=$(printf '{"hot":"%s","default":"%s"}' "$HOT" "$DEFAULT")
tedge mqtt pub -q 1 -r "$TARGET/twin/rugpi" "$PAYLOAD" ||:
Expand Down
2 changes: 1 addition & 1 deletion recipes/sbom/recipe.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
description = "Create software bill of materials"
priority = -1 # Execute at the end
priority = -1000 # Execute at the end

0 comments on commit d4b1d69

Please sign in to comment.