mirror of
https://github.com/tubearchivist/tubearchivist-server.git
synced 2024-11-21 19:30:12 +00:00
implement sync_es task to update bbilly1/tubearchivist-es
This commit is contained in:
parent
79bab9d9fb
commit
87a8fdb7ff
@ -24,6 +24,13 @@ class WebhookBase:
|
|||||||
"-t", "bbilly1/tubearchivist:unstable",
|
"-t", "bbilly1/tubearchivist:unstable",
|
||||||
"-t", "bbilly1/tubearchivist:$VERSION", "--push"
|
"-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_unstable_hook": environ.get("DOCKER_UNSTABLE_HOOK_URL"),
|
||||||
"discord_release_hook": environ.get("GITHUB_RELEASE_HOOK_URL"),
|
"discord_release_hook": environ.get("GITHUB_RELEASE_HOOK_URL"),
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ class GithubHook(WebhookBase):
|
|||||||
print("commit not on master")
|
print("commit not on master")
|
||||||
return
|
return
|
||||||
|
|
||||||
self._check_roadmap()
|
self._check_readme()
|
||||||
|
|
||||||
build_message = self.check_commit_message()
|
build_message = self.check_commit_message()
|
||||||
if not build_message:
|
if not build_message:
|
||||||
@ -85,14 +85,16 @@ class GithubHook(WebhookBase):
|
|||||||
first_line = message.split("\n")[0]
|
first_line = message.split("\n")[0]
|
||||||
return first_line.endswith(self.repo_conf["unstable_keyword"])
|
return first_line.endswith(self.repo_conf["unstable_keyword"])
|
||||||
|
|
||||||
def _check_roadmap(self):
|
def _check_readme(self):
|
||||||
"""check if roadmap update needed"""
|
"""check readme if roadmap or es update needed"""
|
||||||
modified = [i["modified"] for i in self.hook["commits"]]
|
modified = [i["modified"] for i in self.hook["commits"]]
|
||||||
for i in modified:
|
for i in modified:
|
||||||
if "README.md" in i:
|
if "README.md" in i:
|
||||||
print("README updated, check roadmap")
|
print("README updated, check roadmap")
|
||||||
RoadmapHook(self.repo_conf, self.ROADMAP_HOOK_URL).update()
|
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):
|
def process_release_hook(self):
|
||||||
"""build and process for new release"""
|
"""build and process for new release"""
|
||||||
@ -327,6 +329,52 @@ class RoadmapHook:
|
|||||||
handler.db_close()
|
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:
|
class RedisBase:
|
||||||
"""connection base for redis"""
|
"""connection base for redis"""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user