diff --git a/core/imageroot/usr/local/agent/actions/update-module/05pullimages b/core/imageroot/usr/local/agent/actions/update-module/05pullimages index f3e92bd20..d561d739f 100755 --- a/core/imageroot/usr/local/agent/actions/update-module/05pullimages +++ b/core/imageroot/usr/local/agent/actions/update-module/05pullimages @@ -33,8 +33,9 @@ os.chdir(os.environ['AGENT_INSTALL_DIR']) # fail fast! request = json.load(sys.stdin) image_url = request['module_url'] +force = "force" in request and request["force"] is True -if image_url == os.getenv('IMAGE_URL'): +if not force and image_url == os.getenv('IMAGE_URL'): print(agent.SD_WARNING + f"The module URL {image_url} is already installed", file=sys.stderr) sys.exit(0) @@ -44,10 +45,13 @@ os.kill(os.getppid(), signal.SIGUSR1) agent.set_weight('05pullimages', '5') -# Download the requested image -agent.run_helper('podman-pull-missing', image_url, - progress_callback = agent.get_progress_callback(1, 30) -).check_returncode() +if not force: + # Download the requested image + agent.run_helper('podman-pull-missing', image_url, + progress_callback = agent.get_progress_callback(1, 30) + ).check_returncode() +else: + subprocess.run(['podman', 'pull', image_url]).check_returncode() # Parse the image labels with subprocess.Popen(['podman', 'image', 'inspect', image_url], stdout=subprocess.PIPE, stderr=sys.stderr) as proc: @@ -62,10 +66,14 @@ if 'org.nethserver.images' in inspect_labels: else: extra_images = [] -# Start the download of extra images -agent.run_helper('podman-pull-missing', *extra_images, - progress_callback = agent.get_progress_callback(31, 80) -).check_returncode() +if not force: + # Start the download of extra images + agent.run_helper('podman-pull-missing', *extra_images, + progress_callback = agent.get_progress_callback(31, 80) + ).check_returncode() +else: + for extra_image_url in extra_images: + subprocess.run(['podman', 'pull', extra_image_url]).check_returncode() # Extract and install the imageroot contents. See chdir() at the beginning # of this script. diff --git a/core/imageroot/usr/local/agent/actions/update-module/validate-input.json b/core/imageroot/usr/local/agent/actions/update-module/validate-input.json index 0dd0cdf6e..6ce465550 100644 --- a/core/imageroot/usr/local/agent/actions/update-module/validate-input.json +++ b/core/imageroot/usr/local/agent/actions/update-module/validate-input.json @@ -13,6 +13,10 @@ "module_url": { "type": "string", "minLength": 1 + }, + "force": { + "type": "boolean", + "default": false } } } diff --git a/core/imageroot/var/lib/nethserver/cluster/actions/update-module/50update b/core/imageroot/var/lib/nethserver/cluster/actions/update-module/50update index 5495126da..b8a303b3d 100755 --- a/core/imageroot/var/lib/nethserver/cluster/actions/update-module/50update +++ b/core/imageroot/var/lib/nethserver/cluster/actions/update-module/50update @@ -33,6 +33,8 @@ image_url= request.get('module_url') instances = request['instances'] image_id = '' +force = "force" in request and request["force"] is True + rdb = agent.redis_connect(privileged=True) # Explicit image_url always wins @@ -56,10 +58,14 @@ ping_errors = agent.tasks.runp_brief([{"agent_id": f"module/{mid}", "action": "l ) agent.assert_exp(ping_errors == 0) -# Pull the image from the remote server, if not already available locally -agent.run_helper('podman-pull-missing', image_url, - progress_callback=agent.get_progress_callback(0,30) -).check_returncode() + +if not force: + # Pull the image from the remote server, if not already available locally + agent.run_helper('podman-pull-missing', image_url, + progress_callback=agent.get_progress_callback(0,30) + ).check_returncode() +else: + subprocess.run(['podman', 'pull', image_url]).check_returncode() # Retrieve the image org.nethserver.authorizations label with subprocess.Popen(['podman', 'image', 'inspect', image_url], stdout=subprocess.PIPE, stderr=sys.stderr) as proc: @@ -89,7 +95,8 @@ for module_id in instances: "agent_id": f"module/{module_id}", "action": "update-module", "data": { - "module_url": image_url + "module_url": image_url, + "force" : force } }) diff --git a/core/imageroot/var/lib/nethserver/cluster/actions/update-module/validate-input.json b/core/imageroot/var/lib/nethserver/cluster/actions/update-module/validate-input.json index fe7234b7b..7fb381050 100644 --- a/core/imageroot/var/lib/nethserver/cluster/actions/update-module/validate-input.json +++ b/core/imageroot/var/lib/nethserver/cluster/actions/update-module/validate-input.json @@ -36,6 +36,10 @@ "pattern": "^.+[0-9]+$" }, "minItems": 1 + }, + "force": { + "type": "boolean", + "default": false } } }