Skip to content

Commit

Permalink
apps: Add ability to disable apps for offline update
Browse files Browse the repository at this point in the history
Add ability to disable apps update for offline update.
It adds the `fetched-apps.uri=None` value to each target, so the
target consumer, fioctl and aklite-offline, knows whether
to consider apps for the target offline update or not.

Signed-off-by: Mike Sul <[email protected]>
  • Loading branch information
mike-sul committed May 28, 2024
1 parent 17f3055 commit 88fd596
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
38 changes: 24 additions & 14 deletions apps/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def get_args():
help='Directory to output the tarred apps data to', required=True)
parser.add_argument('-tt', '--tuf-targets',
help='TUF targets to be updated with URI to fetched app archive')
parser.add_argument('-dd', '--disable',
help='TUF targets to be updated with URI to fetched app archive',
default=False, action='store_true')

args = parser.parse_args()
return args
Expand All @@ -71,20 +74,27 @@ def main(args: argparse.Namespace):
with open(args.targets_file) as f:
targets = json.load(f)

shortlist = [x.strip() for x in args.apps_shortlist.split(',') if x] \
if args.apps_shortlist else None

fetched_target_apps = fetch_target_apps(targets, shortlist, token, args.fetch_dir)
for target, target_json in targets.items():
out_file = os.path.join(args.dst_dir, f"{target}.apps.tar")
logging.info(f"Tarring fetched apps of {target} to {out_file}...")
tar_fetched_apps(os.path.join(args.fetch_dir, target), out_file)
target_json["custom"]["fetched-apps"] = {
"uri": os.path.join(os.environ["H_RUN_URL"], f"{target}.apps.tar"),
}
if fetched_target_apps[target] and len(fetched_target_apps[target]) > 0:
target_json["custom"]["fetched-apps"]["shortlist"] = \
",".join(fetched_target_apps[target])
if args.disable:
logging.info("Disabling apps for offline update...")
for target, target_json in targets.items():
target_json["custom"]["fetched-apps"] = {
"uri": None
}
else:
shortlist = [x.strip() for x in args.apps_shortlist.split(',') if x] \
if args.apps_shortlist else None

fetched_target_apps = fetch_target_apps(targets, shortlist, token, args.fetch_dir)
for target, target_json in targets.items():
out_file = os.path.join(args.dst_dir, f"{target}.apps.tar")
logging.info(f"Tarring fetched apps of {target} to {out_file}...")
tar_fetched_apps(os.path.join(args.fetch_dir, target), out_file)
target_json["custom"]["fetched-apps"] = {
"uri": os.path.join(os.environ["H_RUN_URL"], f"{target}.apps.tar"),
}
if fetched_target_apps[target] and len(fetched_target_apps[target]) > 0:
target_json["custom"]["fetched-apps"]["shortlist"] = \
",".join(fetched_target_apps[target])

with open(args.targets_file, "w") as f:
json.dump(targets, f)
Expand Down
9 changes: 9 additions & 0 deletions apps/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ if [ "${FETCH_APPS}" == "1" ]; then
--apps-shortlist="${FETCH_APPS_SHORTLIST}" \
--dst-dir="${ARCHIVE}" \
--tuf-targets="${TUF_REPO}/roles/unsigned/targets.json"
elif [ "${FETCH_APPS}" == "0" ]; then
status "Disabling apps update for offline update..."
"${HERE}/fetch.py" \
--factory "${FACTORY}" \
--targets-file="${ARCHIVE}/targets-created.json" \
--token-file="${SECRETS}/osftok" \
--disable \
--dst-dir="${ARCHIVE}" \
--tuf-targets="${TUF_REPO}/roles/unsigned/targets.json"
fi

cp "${TUF_REPO}/roles/unsigned/targets.json" "${ARCHIVE}/targets-after.json"
Expand Down

0 comments on commit 88fd596

Please sign in to comment.