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:
nearxos
2026-02-23 10:21:06 +02:00
parent e13ad3d8f9
commit ec973cc2b3
5 changed files with 90 additions and 2 deletions

View File

@@ -44,6 +44,7 @@ GOLDEN_IMAGE = Path(os.environ.get("CM4_GOLDEN_IMAGE", str(BASE_DIR / "golden.im
NETWORK_DEVICES_FILE = Path(os.environ.get("CM4_NETWORK_DEVICES_FILE", str(BASE_DIR / "network_devices.json")))
BUILD_STATUS_FILE = Path(os.environ.get("CM4_BUILD_STATUS_FILE", str(BASE_DIR / "build_cloudinit_status.json")))
BUILD_REQUEST_FILE = Path(os.environ.get("CM4_BUILD_REQUEST_FILE", str(BASE_DIR / "build_cloudinit_request.json")))
BUILD_CANCEL_FILE = BUILD_REQUEST_FILE.parent / "build_cloudinit_cancel"
SHRINK_REQUEST_FILE = Path(os.environ.get("CM4_SHRINK_REQUEST_FILE", str(BASE_DIR / "shrink_request.json")))
SHRINK_STATUS_FILE = Path(os.environ.get("CM4_SHRINK_STATUS_FILE", str(BASE_DIR / "shrink_status.json")))
FIRST_BOOT_STATUS_FILE = Path(os.environ.get("CM4_FIRST_BOOT_STATUS_FILE", str(BASE_DIR / "first_boot_status.json")))
@@ -1616,6 +1617,18 @@ def api_build_cloudinit_status():
return jsonify(_build_status_read())
@app.route("/api/build-cloudinit-cancel", methods=["POST"])
@require_admin
def api_build_cloudinit_cancel():
"""Request cancellation of the current build (host script checks for cancel file)."""
try:
BUILD_CANCEL_FILE.parent.mkdir(parents=True, exist_ok=True)
BUILD_CANCEL_FILE.write_text("")
return jsonify({"ok": True, "message": "Cancel requested. Build will stop at next check."})
except OSError as e:
return jsonify({"ok": False, "error": str(e)}), 500
@app.route("/api/build-cloudinit", methods=["POST"])
@require_admin
def api_build_cloudinit():