diff --git a/build.py b/build.py index f25468f..9fb42d7 100644 --- a/build.py +++ b/build.py @@ -30,6 +30,22 @@ def get_webhook(): return None +def update_portainer_stack(webhook_id: str): + print("Updating portainer stack...") + resp = post(f"https://docker.cnml.de/api/stacks/webhooks/{webhook_id}") + if not resp.ok: + try: + try: + error = resp.json() + except Exception: + error = resp.content.decode() + raise Exception(error) + raise Exception(f"{error['message']} ({error['details']})") + except Exception as e: + print("Failed to update:", e) + else: + print("Stack successfully updated!") + if __name__ == '__main__': output_path = Path("dist") if output_path.exists(): @@ -42,22 +58,14 @@ if __name__ == '__main__': stdout=PIPE, check=True).stdout.decode().strip() short_sha = run(["git", "rev-parse", "--short", "HEAD"], stdout=PIPE, check=True).stdout.decode().strip() + tags = [branch, short_sha] + if branch == 'main': + default_branch_tag = "latest" + print(f"On default branch, also building {default_branch_tag} tag!") + tags.append(default_branch_tag) platforms = ['linux/amd64', 'linux/arm/v6', 'linux/arm/v7', 'linux/arm64/v8', 'linux/386', 'linux/ppc64le', 'linux/s390x'] - buildx("chenio/code2dfd", [branch, short_sha], platforms, dockerfile=dockerfile) + buildx("chenio/code2dfd", tags, platforms, dockerfile=dockerfile) webhook_id = get_webhook() if webhook_id is not None: - print("Updating portainer stack...") - resp = post(f"https://docker.cnml.de/api/stacks/webhooks/{webhook_id}") - if not resp.ok: - try: - try: - error = resp.json() - except Exception: - error = resp.content.decode() - raise Exception(error) - raise Exception(f"{error['message']} ({error['details']})") - except Exception as e: - print("Failed to update:", e) - else: - print("Stack successfully updated!") + update_portainer_stack(webhook_id) diff --git a/createreadmes.py b/createreadmes.py index 712e8ca..d4952e3 100644 --- a/createreadmes.py +++ b/createreadmes.py @@ -266,7 +266,7 @@ properties: items: type: integer""") -def check_security_rules(security_rules: dict[Any, Any] | None) -> dict[int, SecurityRule]: +def check_security_rules(model_id: str, security_rules: dict[Any, Any] | None) -> dict[int, SecurityRule]: if security_rules is None: raise Exception("Security rules file is empty!") for n in range(1, 19): @@ -276,7 +276,7 @@ def check_security_rules(security_rules: dict[Any, Any] | None) -> dict[int, Sec jsonschema.validate(rule, rule_schema) rule: SecurityRule if rule["status"] == "unknown": - warning(f"Rule {n} is still unknown!") + warning(f"In model {model_id}: Rule {n} is still unknown!") except jsonschema.ValidationError as e: warning("Not checking further rules!") raise Exception("Security rule {n}: {msg} at $.{n}.{path}".format(n=n, msg=e.message, path=e.json_path)) from e @@ -421,7 +421,7 @@ def write_model_readmes(dataset: Dataset): security_rules = None try: with security_rules_file.open('r') as f: - security_rules = check_security_rules(yaml.safe_load(f)) + security_rules = check_security_rules(model_id, yaml.safe_load(f)) except FileNotFoundError: warning("Security rules file not found at {}".format(security_rules_file)) except Exception as e: @@ -429,7 +429,7 @@ def write_model_readmes(dataset: Dataset): dir.mkdir(exist_ok=True) write_file_if_changed(readme, f"""--- title: {slug} -keywords: model TODO +keywords: model tags: [{', '.join(get_tag_slug(tech) for tech in info['tech'])}] sidebar: datasetdoc_sidebar permalink: {model_id}.html @@ -492,7 +492,6 @@ keywords: code2DFD introduction tags: [overview] sidebar: datasetdoc_sidebar permalink: index.html -summary: Dataset of dataflow diagrams of microservice applications. toc: false ---