From 87a8fdb7ffcb25507a4ef52ddd00a4b3ca9f9de5 Mon Sep 17 00:00:00 2001 From: simon Date: Sun, 3 Jul 2022 13:11:35 +0700 Subject: [PATCH] implement sync_es task to update bbilly1/tubearchivist-es --- tubearchivist/web/src/webhook_base.py | 7 ++++ tubearchivist/web/src/webhook_github.py | 56 +++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/tubearchivist/web/src/webhook_base.py b/tubearchivist/web/src/webhook_base.py index 7442cd3..05b280d 100644 --- a/tubearchivist/web/src/webhook_base.py +++ b/tubearchivist/web/src/webhook_base.py @@ -24,6 +24,13 @@ class WebhookBase: "-t", "bbilly1/tubearchivist:unstable", "-t", "bbilly1/tubearchivist:$VERSION", "--push" ], + "sync_es": [ + "docker", "image", "pull", "elasticsearch:$VERSION", "&&", + "docker", "tag", "elasticsearch:$VERSION", "bbilly1/tubearchivist-es", "&&", + "docker", "tag", "elasticsearch:$VERSION", "bbilly1/tubearchivist-es:$VERSION", "&&", + "docker", "push", "bbilly1/tubearchivist-es", "&&", + "docker", "push", "bbilly1/tubearchivist-es:$VERSION" + ], "discord_unstable_hook": environ.get("DOCKER_UNSTABLE_HOOK_URL"), "discord_release_hook": environ.get("GITHUB_RELEASE_HOOK_URL"), } diff --git a/tubearchivist/web/src/webhook_github.py b/tubearchivist/web/src/webhook_github.py index 4bb278e..4095e23 100644 --- a/tubearchivist/web/src/webhook_github.py +++ b/tubearchivist/web/src/webhook_github.py @@ -62,7 +62,7 @@ class GithubHook(WebhookBase): print("commit not on master") return - self._check_roadmap() + self._check_readme() build_message = self.check_commit_message() if not build_message: @@ -85,14 +85,16 @@ class GithubHook(WebhookBase): first_line = message.split("\n")[0] return first_line.endswith(self.repo_conf["unstable_keyword"]) - def _check_roadmap(self): - """check if roadmap update needed""" + def _check_readme(self): + """check readme if roadmap or es update needed""" modified = [i["modified"] for i in self.hook["commits"]] for i in modified: if "README.md" in i: print("README updated, check roadmap") RoadmapHook(self.repo_conf, self.ROADMAP_HOOK_URL).update() - break + if "docker-compose.yml" in i: + print("docker-compose updated, check es version") + EsVersionSync(self.repo_conf).run() def process_release_hook(self): """build and process for new release""" @@ -327,6 +329,52 @@ class RoadmapHook: handler.db_close() +class EsVersionSync: + """check if bbilly1/tubearchivist-es needs updating""" + + REPO = "repos/tubearchivist/tubearchivist" + COMPOSE = f"https://api.github.com/{REPO}/contents/docker-compose.yml" + IMAGE = "bbilly1/tubearchivist-es" + TAGS = f"https://hub.docker.com/v2/repositories/{IMAGE}/tags" + + def __init__(self, repo_conf): + self.repo_conf = repo_conf + self.expected = False + self.current = False + + def run(self): + """run check, send task if needed""" + self.get_expected() + self.get_current() + + if self.expected == self.current: + print(f"{self.IMAGE} on expected {self.expected}") + else: + print(f"bump {self.IMAGE} {self.current} - {self.expected}") + self.build_task() + + def get_expected(self): + """get expected es version from readme""" + response = requests.get(self.COMPOSE).json() + content = base64.b64decode(response["content"]).decode() + line = [i for i in content.split("\n") if self.IMAGE in i][0] + self.expected = line.split()[-1] + + def get_current(self): + """get current version from docker hub""" + response = requests.get(self.TAGS).json() + all_tags = [i.get("name") for i in response["results"]] + all_tags.pop(0) + all_tags.sort() + + self.current = all_tags[-1] + + def build_task(self): + """build task for builder""" + task = TaskHandler(self.repo_conf, tag_name=self.expected) + task.create_task("sync_es") + + class RedisBase: """connection base for redis"""