-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fetch apps for offline update #324
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
43d4bde
apps: Rename unused file to fetch apps
mike-sul e6edcfe
apps: Add manual test for apps fetching
mike-sul 8b0634c
apps: Fetch apps specified in targets file
mike-sul 92f19e8
apps: Fetch apps after publishing if enabled
mike-sul 43aad96
assemble: Fetch app archive if exists
mike-sul fdbf8a2
customize-target: Copy fetched apps if present
mike-sul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/python3 | ||
# | ||
# Copyright (c) 2021 Foundries.io | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import argparse | ||
import json | ||
import logging | ||
import traceback | ||
import os | ||
import sys | ||
|
||
from apps.target_apps_fetcher import SkopeAppFetcher | ||
from factory_client import FactoryClient | ||
from helpers import cmd | ||
|
||
|
||
def fetch_target_apps(targets: dict, apps_shortlist: str, token: str, dst_dir: str): | ||
apps_fetcher = SkopeAppFetcher(token, dst_dir) | ||
for target_name, target_json in targets.items(): | ||
apps_fetcher.fetch_target(FactoryClient.Target(target_name, target_json), | ||
apps_shortlist, force=True) | ||
|
||
|
||
def tar_fetched_apps(src_dir: str, out_file: str): | ||
os.makedirs(os.path.dirname(out_file), exist_ok=True) | ||
cmd('tar', '-cf', out_file, '-C', src_dir, '.') | ||
|
||
|
||
def get_args(): | ||
parser = argparse.ArgumentParser('Pull Targets Apps and their images from Registries and ' | ||
'store them on a file system') | ||
parser.add_argument('-f', '--factory', help='Apps Factory', required=True) | ||
parser.add_argument('-t', '--targets-file', | ||
help='A json with Targets to dump/fetch apps for', required=True) | ||
parser.add_argument('-a', '--token-file', | ||
help='File where the Factory API Token is stored', required=True) | ||
parser.add_argument('-d', '--fetch-dir', | ||
help='Directory to fetch apps and images to', required=True) | ||
parser.add_argument('-s', '--apps-shortlist', | ||
help='Comma separated list of Target Apps to fetch', default=None) | ||
parser.add_argument('-o', '--dst-dir', | ||
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') | ||
|
||
args = parser.parse_args() | ||
return args | ||
|
||
|
||
def main(args: argparse.Namespace): | ||
exit_code = os.EX_OK | ||
try: | ||
with open(args.token_file) as f: | ||
token = f.read() | ||
with open(args.targets_file) as f: | ||
targets = json.load(f) | ||
|
||
fetch_target_apps(targets, args.apps_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"), | ||
"shortlist": args.apps_shortlist, | ||
} | ||
with open(args.targets_file, "w") as f: | ||
json.dump(targets, f) | ||
|
||
if args.tuf_targets: | ||
with open(args.tuf_targets, "r") as f: | ||
tuf_targets = json.load(f) | ||
|
||
tuf_targets["targets"].update(targets) | ||
|
||
with open(args.tuf_targets, "w") as f: | ||
json.dump(tuf_targets, f) | ||
|
||
except Exception as exc: | ||
logging.error('Failed to pull Target apps and images: {}\n{}'.format(exc, traceback.format_exc())) | ||
exit_code = os.EX_SOFTWARE | ||
return exit_code | ||
|
||
|
||
if __name__ == '__main__': | ||
logging.basicConfig(format='%(asctime)s %(levelname)s: Apps Fetcher: %(module)s: %(message)s', level=logging.INFO) | ||
args = get_args() | ||
sys.exit(main(args)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env bash | ||
# Copyright (c) 2024 Foundries.io | ||
# SPDX-License-Identifier: Apache-2.0 | ||
set -euo pipefail | ||
|
||
FACTORY=$1 | ||
TOKEN_FILE=$2 | ||
TARGETS_FILE=$3 | ||
FETCH_DIR=$4 | ||
DST_DIR=$5 | ||
APPS_SHORTLIST=${6-""} | ||
TUF_TARGETS_FILE=$7 | ||
API_HOST=${8-"api.foundries.io"} | ||
|
||
CMD=./apps/fetch.py | ||
PARAMS="\ | ||
--factory=${FACTORY} \ | ||
--targets-file=${TARGETS_FILE} \ | ||
--token-file=${TOKEN_FILE} \ | ||
--fetch-dir=/fetched-apps \ | ||
--apps-shortlist=${APPS_SHORTLIST} \ | ||
--dst-dir=/dst-dir \ | ||
--tuf-targets=${TUF_TARGETS_FILE} \ | ||
" | ||
|
||
docker run -v -it --rm \ | ||
-e PYTHONPATH=. \ | ||
-e H_RUN_URL="https://${API_HOST}" \ | ||
-v "${PWD}":/ci-scripts \ | ||
-v "${FETCH_DIR}":/fetched-apps \ | ||
-v "${DST_DIR}":/dst-dir \ | ||
-v "${TOKEN_FILE}":"${TOKEN_FILE}" \ | ||
-v "${TARGETS_FILE}":"${TARGETS_FILE}" \ | ||
-v "${TUF_TARGETS_FILE}":"${TUF_TARGETS_FILE}" \ | ||
-w /ci-scripts \ | ||
foundries/lmp-image-tools ${CMD} ${PARAMS} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double checking that we don't need an
else
fetch_restorable_appsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No
else
is needed. A set of apps fetched for offline update in the publish run can differ from a set of apps for preloading.So, the current implementation reuses the publish run apps only if it is a sub-set of the apps for preloading. So, we still need to call the fetch to pull the diff. If the sets are the same then we could avoid the fetch here, but I decided it's not worth of additional
if previously_fetched_apps == apps_to_fetch then skip fetching
becauseskopeo
is smart enough not to pull blobs if they already present locally.When/If I move
ci-scripts
fromskopeo
tocomposectl
then I'll improve this logic, so the publish run apps are re-used even if its set is not subset of apps for preloading. Withskopeo
it's a bit cumbersome to implement.