diff --git a/.github/workflows/bake-image.yml b/.github/workflows/bake-image.yml index ac09a23..4b91338 100644 --- a/.github/workflows/bake-image.yml +++ b/.github/workflows/bake-image.yml @@ -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 @@ -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 diff --git a/.gitignore b/.gitignore index e0a7f5a..5c2c3b3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.rugpi /build +recipes/build-info/files/.build_info **/debian-packages.list \ No newline at end of file diff --git a/justfile b/justfile index 0883499..a2c13a0 100644 --- a/justfile +++ b/justfile @@ -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: @@ -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: @@ -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 diff --git a/recipes/build-info/files/.gitignore b/recipes/build-info/files/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/recipes/build-info/recipe.toml b/recipes/build-info/recipe.toml new file mode 100644 index 0000000..42fa956 --- /dev/null +++ b/recipes/build-info/recipe.toml @@ -0,0 +1,2 @@ +description = "Add build-info about the image" +priority = -1 # Execute at the end \ No newline at end of file diff --git a/recipes/build-info/steps/00-install.sh b/recipes/build-info/steps/00-install.sh new file mode 100755 index 0000000..8ff942c --- /dev/null +++ b/recipes/build-info/steps/00-install.sh @@ -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 diff --git a/recipes/rugpi-auto-rollback/files/healthcheck.sh b/recipes/rugpi-auto-rollback/files/healthcheck.sh index 6cea6ff..7bccb26 100755 --- a/recipes/rugpi-auto-rollback/files/healthcheck.sh +++ b/recipes/rugpi-auto-rollback/files/healthcheck.sh @@ -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 @@ -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" ||: diff --git a/recipes/sbom/recipe.toml b/recipes/sbom/recipe.toml index 829245d..54d6f51 100644 --- a/recipes/sbom/recipe.toml +++ b/recipes/sbom/recipe.toml @@ -1,2 +1,2 @@ description = "Create software bill of materials" -priority = -1 # Execute at the end \ No newline at end of file +priority = -1000 # Execute at the end \ No newline at end of file