app-json: use parsed app category, cache repo list..
.. and add icons
This commit is contained in:
parent
762d12b61e
commit
6cb6ee6952
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
# Gather metadata from Co-op Cloud apps in $ABRA_DIR/apps (default
|
# Gather metadata from Co-op Cloud apps in $ABRA_DIR/apps (default
|
||||||
# ~/.abra/apps), and format it as JSON so that it can be hosted here:
|
# ~/.abra/apps), and format it as JSON so that it can be hosted here:
|
||||||
# https://abra-apps.cloud.autonomic.zone
|
# https://apps.coopcloud.tech
|
||||||
|
|
||||||
from json import dump
|
from json import dump
|
||||||
from logging import DEBUG, basicConfig, getLogger
|
from logging import DEBUG, basicConfig, getLogger
|
||||||
@ -55,9 +55,23 @@ def _run_cmd(cmd, shell=False, **kwargs):
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def get_repos_json():
|
||||||
|
""" Retrieve repo list from Gitea """
|
||||||
|
|
||||||
|
url = "https://git.autonomic.zone/api/v1/orgs/coop-cloud/repos"
|
||||||
|
|
||||||
|
log.info(f"Retrieving {url}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
return get(url, timeout=10).json()
|
||||||
|
except Exception as exception:
|
||||||
|
log.error(f"Failed to retrieve {url}, saw {str(exception)}")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def get_published_apps_json():
|
def get_published_apps_json():
|
||||||
"""Retrieve already published apps json."""
|
"""Retrieve already published apps json."""
|
||||||
url = "https://abra-apps.cloud.autonomic.zone"
|
url = "https://apps.coopcloud.tech"
|
||||||
|
|
||||||
log.info(f"Retrieving {url}")
|
log.info(f"Retrieving {url}")
|
||||||
|
|
||||||
@ -68,23 +82,15 @@ def get_published_apps_json():
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
def clone_all_apps():
|
def clone_all_apps(repos_json):
|
||||||
"""Clone all Co-op Cloud apps to ~/.abra/apps."""
|
"""Clone all Co-op Cloud apps to ~/.abra/apps."""
|
||||||
if not exists(CLONES_PATH):
|
if not exists(CLONES_PATH):
|
||||||
mkdir(CLONES_PATH)
|
mkdir(CLONES_PATH)
|
||||||
url = "https://git.autonomic.zone/api/v1/orgs/coop-cloud/repos"
|
|
||||||
|
|
||||||
log.info(f"Retrieving {url}")
|
repos = [[p["name"], p["ssh_url"]] for p in repos_json]
|
||||||
|
|
||||||
try:
|
|
||||||
response = get(url, timeout=10)
|
|
||||||
except Exception as exception:
|
|
||||||
log.error(f"Failed to retrieve {url}, saw {str(exception)}")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
repos = [[p["name"], p["ssh_url"]] for p in response.json()]
|
|
||||||
|
|
||||||
for name, url in repos:
|
for name, url in repos:
|
||||||
|
continue
|
||||||
if name in REPOS_TO_SKIP:
|
if name in REPOS_TO_SKIP:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -102,7 +108,7 @@ def clone_all_apps():
|
|||||||
_run_cmd("git fetch -a")
|
_run_cmd("git fetch -a")
|
||||||
|
|
||||||
|
|
||||||
def generate_apps_json():
|
def generate_apps_json(repos_json):
|
||||||
"""Generate the abra-apps.json application versions file."""
|
"""Generate the abra-apps.json application versions file."""
|
||||||
apps_json = {}
|
apps_json = {}
|
||||||
cached_apps_json = get_published_apps_json()
|
cached_apps_json = get_published_apps_json()
|
||||||
@ -112,20 +118,25 @@ def generate_apps_json():
|
|||||||
log.info(f"Skipping {app}")
|
log.info(f"Skipping {app}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
repo_details = next(filter(lambda x: x['name'] == app, repos_json), {})
|
||||||
|
|
||||||
app_path = f"{CLONES_PATH}/{app}"
|
app_path = f"{CLONES_PATH}/{app}"
|
||||||
chdir(app_path)
|
chdir(app_path)
|
||||||
|
|
||||||
|
features = get_app_features(app_path)
|
||||||
|
|
||||||
log.info(f"Processing {app}")
|
log.info(f"Processing {app}")
|
||||||
apps_json[app] = {
|
apps_json[app] = {
|
||||||
"category": "apps",
|
"category": features.get("category", ""),
|
||||||
"repository": f"https://git.autonomic.zone/coop-cloud/{app}.git",
|
"repository": f"https://git.autonomic.zone/coop-cloud/{app}.git",
|
||||||
# Note(decentral1se): please note that the app features do not
|
# Note(decentral1se): please note that the app features do not
|
||||||
# correspond to version tags. We simply parse the latest features
|
# correspond to version tags. We simply parse the latest features
|
||||||
# list from HEAD. This may lead to unexpected situations where
|
# list from HEAD. This may lead to unexpected situations where
|
||||||
# users believe X feature is available under Y version but it is
|
# users believe X feature is available under Y version but it is
|
||||||
# not.
|
# not.
|
||||||
"features": get_app_features(app_path),
|
"features": features,
|
||||||
"versions": get_app_versions(app_path, cached_apps_json),
|
"versions": get_app_versions(app_path, cached_apps_json),
|
||||||
|
"icon": repo_details.get("avatar_url", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
return apps_json
|
return apps_json
|
||||||
@ -241,11 +252,12 @@ def get_app_versions(app_path, cached_apps_json):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Run the script."""
|
"""Run the script."""
|
||||||
clone_all_apps()
|
repos_json = get_repos_json()
|
||||||
|
clone_all_apps(repos_json)
|
||||||
|
|
||||||
target = f"{SCRIPT_PATH}/../deploy/abra-apps.cloud.autonomic.zone/abra-apps.json"
|
target = f"{SCRIPT_PATH}/../deploy/apps.coopcloud.tech/abra-apps.json"
|
||||||
with open(target, "w", encoding="utf-8") as handle:
|
with open(target, "w", encoding="utf-8") as handle:
|
||||||
dump(generate_apps_json(), handle, ensure_ascii=False, indent=4)
|
dump(generate_apps_json(repos_json), handle, ensure_ascii=False, indent=4)
|
||||||
|
|
||||||
log.info(f"Successfully generated {target}")
|
log.info(f"Successfully generated {target}")
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user