Add build cancellation feature to cloud-init process</message>
<message>Implement a new API endpoint for cancelling ongoing cloud-init builds, allowing users to request a build cancellation via the dashboard. Update the dashboard UI to include a cancel button that appears during the build process, enhancing user experience by providing control over long-running operations. Modify the build script to check for cancellation requests, ensuring that builds can be stopped gracefully. This feature improves usability and responsiveness in the cloud-init image building workflow.
This commit is contained in:
@@ -8,6 +8,7 @@ set -e
|
||||
PROV_DIR="${CM4_PROVISIONING_DIR:-/var/lib/cm4-provisioning}"
|
||||
REQUEST_FILE="$PROV_DIR/build_cloudinit_request.json"
|
||||
STATUS_FILE="$PROV_DIR/build_cloudinit_status.json"
|
||||
CANCEL_FILE="$PROV_DIR/build_cloudinit_cancel"
|
||||
[[ -f /opt/cm4-provisioning/env ]] && source /opt/cm4-provisioning/env
|
||||
BACKUPS_DIR="${BACKUPS_DIR:-$PROV_DIR/backups}"
|
||||
CLOUDINIT_IMAGES_DIR="${CLOUDINIT_IMAGES_DIR:-$PROV_DIR/cloudinit-images}"
|
||||
@@ -25,7 +26,16 @@ write_status() {
|
||||
"$(date +%s)" > "$STATUS_FILE"
|
||||
}
|
||||
|
||||
check_cancel() {
|
||||
if [[ -f "$CANCEL_FILE" ]]; then
|
||||
write_status "cancelled" "Build cancelled." "" ""
|
||||
rm -f "$REQUEST_FILE" "$CANCEL_FILE"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
[[ -f "$REQUEST_FILE" ]] || { echo "No request file"; exit 0; }
|
||||
check_cancel
|
||||
|
||||
# Use temp dir on provisioning dir (not /tmp) so we have enough space for decompress (~3GB+)
|
||||
mkdir -p "$PROV_DIR"
|
||||
@@ -75,6 +85,7 @@ CURL_ERR="$TEMP_DIR/curl_err.txt"
|
||||
SHA256_FILE="$TEMP_DIR/expected.sha256"
|
||||
|
||||
# Fetch official SHA256 checksum if available (Raspberry Pi OS publishes .img.xz.sha256 next to each image)
|
||||
check_cancel
|
||||
write_status "downloading" "Checking for existing image and checksum…" "" ""
|
||||
EXPECTED_HASH=""
|
||||
if curl -sfL -o "$SHA256_FILE" "$SHA256_URL" 2>/dev/null && [[ -s "$SHA256_FILE" ]]; then
|
||||
@@ -122,6 +133,7 @@ else
|
||||
cp "$XZ_FILE" "$CACHED"
|
||||
fi
|
||||
|
||||
check_cancel
|
||||
write_status "decompressing" "Decompressing image…" "" ""
|
||||
# Check we have a real xz file (not HTML error page)
|
||||
if ! command -v xz >/dev/null 2>&1; then
|
||||
@@ -156,6 +168,7 @@ if ! xz -T 1 -d -k -f "$XZ_FILE" 2>"$XZ_ERR"; then
|
||||
fi
|
||||
[[ -f "$IMG_FILE" ]] || { write_status "error" "" "" "image.img not found after decompress"; exit 1; }
|
||||
|
||||
check_cancel
|
||||
write_status "injecting" "Mounting boot partition and injecting cloud-init…" "" ""
|
||||
LOOP=$(losetup -f --show -P "$IMG_FILE")
|
||||
boot_part="${LOOP}p1"
|
||||
@@ -171,6 +184,7 @@ cp "$TEMP_DIR/network-config" "$MNT/network-config"
|
||||
umount "$MNT"
|
||||
losetup -d "$LOOP"
|
||||
|
||||
check_cancel
|
||||
write_status "finalizing" "Copying image to cloud-init images…" "" ""
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
cp "$IMG_FILE" "$OUT_PATH"
|
||||
|
||||
Reference in New Issue
Block a user