Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions root/app/lsio_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def get_repos():

def get_file(repo, branch, path, is_yaml=False):
try:
content = repo.get_contents(path, ref=branch).decoded_content
return yaml.load(content, Loader=yaml.CLoader) if is_yaml else content
return repo.get_contents(path, ref=branch).decoded_content.decode("utf-8")
except:
return None

Expand All @@ -27,12 +26,30 @@ def get_last_stable_release(repo):
return release.tag_name, str(release.published_at)
return "latest", str(repo.pushed_at)

def get_readme_vars(repo):
return (get_file(repo, "master", "readme-vars.yml", is_yaml=True) or
def get_readme_vars(repo, project_name):
readme_vars_str = (get_file(repo, "master", "readme-vars.yml", is_yaml=True) or
get_file(repo, "main", "readme-vars.yml", is_yaml=True) or
get_file(repo, "develop", "readme-vars.yml", is_yaml=True) or
get_file(repo, "nightly", "readme-vars.yml", is_yaml=True))

if not readme_vars_str:
return None

replace_map = {
"[{{ project_name|capitalize }}]": project_name,
"{{ project_name|capitalize }}": project_name,
"[{{ project_name }}]": project_name,
"{{ project_name }}": project_name,
"({{ project_url }})": "",
"{{ project_url }}": "",
"{{ arch_x86_64 }}": "x86_64",
"{{ arch_arm64 }}": "arm64",
}
for expression, value in replace_map.items():
readme_vars_str = readme_vars_str.replace(expression, value)

return yaml.load(readme_vars_str, Loader=yaml.CLoader)

def print_rate_limit():
ratelimit = GH.get_rate_limit().core
print(f"Github ratelimit - {ratelimit.remaining}/{ratelimit.limit} resets at {ratelimit.reset}")
4 changes: 2 additions & 2 deletions root/app/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pydantic import BaseModel

# Increment when updating schema
IMAGES_SCHEMA_VERSION = 1
# Increment when updating schema or forcing an update on start
IMAGES_SCHEMA_VERSION = 2


class Tag(BaseModel):
Expand Down
16 changes: 6 additions & 10 deletions root/app/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def get_tags(readme_vars):

def get_architectures(readme_vars):
if "available_architectures" not in readme_vars:
return [Architecture(arch="arch_x86_64", tag="amd64-latest")]
return [Architecture(arch="x86_64", tag="amd64-latest")]
archs = []
for item in readme_vars["available_architectures"]:
archs.append(Architecture(arch=item["arch"][8:-3], tag=item["tag"]))
archs.append(Architecture(arch=item["arch"], tag=item["tag"]))
return archs

def get_changelogs(readme_vars):
Expand All @@ -42,11 +42,6 @@ def get_changelogs(readme_vars):
def get_description(readme_vars):
description = readme_vars.get("project_blurb", "No description")
description = description.replace("\n", " ").strip(" \t\n\r")
if "project_name" in readme_vars:
description = description.replace("[{{ project_name|capitalize }}]", readme_vars["project_name"])
description = description.replace("[{{ project_name }}]", readme_vars["project_name"])
if "project_url" in readme_vars:
description = description.replace("({{ project_url }})", "")
return description

def get_env_vars(readme_vars):
Expand Down Expand Up @@ -130,7 +125,7 @@ def get_hostname(readme_vars):
if not include_hostname:
return None
optional = include_hostname == "optional"
hostname = readme_vars.get("param_hostname", False).replace("{{ project_name }}", readme_vars["project_name"])
hostname = readme_vars.get("param_hostname", False)
return Hostname(hostname=hostname, desc=readme_vars.get("param_hostname_desc", ""), optional=optional)

def get_mac_address(readme_vars):
Expand All @@ -145,7 +140,8 @@ def get_image(repo):
print(f"Processing {repo.name}")
if not repo.name.startswith("docker-") or repo.name.startswith("docker-baseimage-"):
return None
readme_vars = gh.get_readme_vars(repo)
project_name = repo.name.replace("docker-", "")
readme_vars = gh.get_readme_vars(repo, project_name)
if not readme_vars:
return None
categories = readme_vars.get("project_categories", "")
Expand Down Expand Up @@ -174,7 +170,7 @@ def get_image(repo):
caps=get_caps(readme_vars),
)
return Image(
name=repo.name.replace("docker-", ""),
name=project_name,
github_url=repo.html_url,
stars=repo.stargazers_count,
project_url=readme_vars.get("project_url", None),
Expand Down