forked from toolshed/abra
Fix loads of bugs and generate apps JSON again
This commit is contained in:
104
bin/app-json.py
104
bin/app-json.py
@ -21,6 +21,16 @@ from requests import get
|
||||
HOME_PATH = expanduser("~/")
|
||||
CLONES_PATH = Path(f"{HOME_PATH}/.abra/apps").absolute()
|
||||
SCRIPT_PATH = Path(__file__).absolute().parent
|
||||
REPOS_TO_SKIP = (
|
||||
"abra",
|
||||
"backup-bot",
|
||||
"cloud.autonomic.zone",
|
||||
"docs.cloud.autonomic.zone",
|
||||
"example",
|
||||
"organising",
|
||||
"pyabra",
|
||||
"stack-ssh-deploy",
|
||||
)
|
||||
|
||||
log = getLogger(__name__)
|
||||
basicConfig()
|
||||
@ -47,8 +57,6 @@ def clone_all_apps():
|
||||
"""Clone all Co-op Cloud apps to ~/.abra/apps."""
|
||||
if not exists(CLONES_PATH):
|
||||
mkdir(CLONES_PATH)
|
||||
|
||||
skips = ("organising", "cloud.autonomic.zone", "docs.cloud.autonomic.zone", "abra")
|
||||
url = "https://git.autonomic.zone/api/v1/orgs/coop-cloud/repos"
|
||||
|
||||
log.info(f"Retrieving {url}")
|
||||
@ -62,7 +70,7 @@ def clone_all_apps():
|
||||
repos = [[p["name"], p["ssh_url"]] for p in response.json()]
|
||||
|
||||
for name, url in repos:
|
||||
if name in skips:
|
||||
if name in REPOS_TO_SKIP:
|
||||
continue
|
||||
|
||||
if not exists(f"{CLONES_PATH}/{name}"):
|
||||
@ -71,7 +79,7 @@ def clone_all_apps():
|
||||
chdir(f"{CLONES_PATH}/{name}")
|
||||
if not int(_run_cmd("git branch --list | wc -l", shell=True)):
|
||||
log.info(f"Guessing main branch is HEAD for {name}")
|
||||
run(split("git checkout main"))
|
||||
_run_cmd("git checkout main")
|
||||
|
||||
|
||||
def generate_apps_json():
|
||||
@ -79,33 +87,34 @@ def generate_apps_json():
|
||||
apps_json = {}
|
||||
|
||||
for app in listdir(CLONES_PATH):
|
||||
if app in REPOS_TO_SKIP:
|
||||
log.info(f"Skipping {app}")
|
||||
continue
|
||||
|
||||
app_path = f"{CLONES_PATH}/{app}"
|
||||
chdir(app_path)
|
||||
|
||||
tags = _run_cmd("git tag --list").split()
|
||||
|
||||
if not tags:
|
||||
log.info(f"No tags discovered for {app}, moving on")
|
||||
continue
|
||||
|
||||
for tag in tags:
|
||||
log.info(f"Processing {tag} for {app}")
|
||||
apps_json[app] = {
|
||||
"category": "apps",
|
||||
"repository": f"https://git.autonomic.zone/coop-cloud/{app}.git",
|
||||
"features": get_app_features(app_path, tag),
|
||||
"versions": get_app_versions(app_path, tag),
|
||||
}
|
||||
log.info(f"Processing {app}")
|
||||
apps_json[app] = {
|
||||
"category": "apps",
|
||||
"repository": f"https://git.autonomic.zone/coop-cloud/{app}.git",
|
||||
# Note(decentral1se): please note that the app features do not
|
||||
# correspond to version tags. We simply parse the latest features
|
||||
# list from HEAD. This may lead to unexpected situations where
|
||||
# users believe X feature is available under Y version but it is
|
||||
# not.
|
||||
"features": get_app_features(app_path),
|
||||
"versions": get_app_versions(app_path),
|
||||
}
|
||||
|
||||
return apps_json
|
||||
|
||||
|
||||
def get_app_features(app_path, tag):
|
||||
def get_app_features(app_path):
|
||||
"""Parse features from app repo README files."""
|
||||
features = {}
|
||||
|
||||
chdir(app_path)
|
||||
_run_cmd(f"git checkout {tag}")
|
||||
|
||||
with open(f"{app_path}/README.md", "r") as handle:
|
||||
log.info(f"{app_path}/README.md")
|
||||
@ -133,34 +142,47 @@ def get_app_features(app_path, tag):
|
||||
return features
|
||||
|
||||
|
||||
def get_app_versions(app_path, tag):
|
||||
versions = []
|
||||
def get_app_versions(app_path):
|
||||
versions = {}
|
||||
|
||||
chdir(app_path)
|
||||
_run_cmd(f"git checkout {tag}")
|
||||
|
||||
services_cmd = "yq e '.services | keys | .[]' compose*.yml"
|
||||
services = _run_cmd(services_cmd, shell=True).split()
|
||||
for service in services:
|
||||
services_cmd = f"yq e '.services.{service}.image' compose*.yml"
|
||||
images = _run_cmd(services_cmd, shell=True).split()
|
||||
for image in images:
|
||||
if image in ("null", "---"):
|
||||
continue
|
||||
tags = _run_cmd("git tag --list").split()
|
||||
|
||||
images_cmd = f"skopeo inspect docker://{image} | jq '.Digest'"
|
||||
output = _run_cmd(images_cmd, shell=True)
|
||||
if not tags:
|
||||
log.info(f"No tags discovered, moving on")
|
||||
return {}
|
||||
|
||||
new_version_info = {
|
||||
service: {
|
||||
"image": image.split(":")[0],
|
||||
"tag": tag,
|
||||
"digest": output.split(":")[-1][:8],
|
||||
for tag in tags:
|
||||
_run_cmd(f"git checkout {tag}")
|
||||
|
||||
services_cmd = "yq e '.services | keys | .[]' compose*.yml"
|
||||
services = _run_cmd(services_cmd, shell=True).split()
|
||||
|
||||
service_versions = []
|
||||
for service in services:
|
||||
services_cmd = f"yq e '.services.{service}.image' compose*.yml"
|
||||
images = _run_cmd(services_cmd, shell=True).split()
|
||||
|
||||
for image in images:
|
||||
if image in ("null", "---"):
|
||||
continue
|
||||
|
||||
images_cmd = f"skopeo inspect docker://{image} | jq '.Digest'"
|
||||
output = _run_cmd(images_cmd, shell=True)
|
||||
|
||||
service_version_info = {
|
||||
service: {
|
||||
"image": image.split(":")[0],
|
||||
"tag": tag,
|
||||
"digest": output.split(":")[-1][:8],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
versions.append(new_version_info)
|
||||
log.info(f"Parsed {new_version_info}")
|
||||
log.info(f"Parsed {service_version_info}")
|
||||
service_versions.append(service_version_info)
|
||||
|
||||
versions[tag] = service_versions
|
||||
|
||||
_run_cmd("git checkout HEAD")
|
||||
|
||||
|
Reference in New Issue
Block a user