Skip to content

Commit

Permalink
core. add force flag to udate-module actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Amygos committed Oct 11, 2023
1 parent 591ad83 commit 2a14d27
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
26 changes: 17 additions & 9 deletions core/imageroot/usr/local/agent/actions/update-module/05pullimages
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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:
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"module_url": {
"type": "string",
"minLength": 1
},
"force": {
"type": "boolean",
"default": false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
"pattern": "^.+[0-9]+$"
},
"minItems": 1
},
"force": {
"type": "boolean",
"default": false
}
}
}

0 comments on commit 2a14d27

Please sign in to comment.