implement build list of commands

This commit is contained in:
simon 2022-07-03 19:21:46 +07:00
parent d63e5bc407
commit 8124c63efb
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 37 additions and 17 deletions

View File

@ -57,6 +57,15 @@ class Monitor(RedisBase):
subprocess.run(base + ["use", "tubearchivist"], check=True)
subprocess.run(base + ["inspect", "--bootstrap"], check=True)
def check_stored(self):
"""check for any stored task since last watch"""
task = self.get_tasks()
if task["tasks"]:
print("found stored task:")
for task_name in task["tasks"]:
print(task_name)
Builder(task_name).run()
def watch(self):
"""watch for messages"""
print("waiting for tasks")
@ -110,13 +119,16 @@ class Builder(RedisBase):
def build(self):
"""build the container"""
if not self.task_detail["clone"]:
build_command = self.task_detail["build"]
command_list = self.task_detail["build"]
if all(isinstance(i, list) for i in command_list):
for command in command_list:
print(f"running: {command}")
subprocess.run(command, check=True)
else:
build_command = ["docker", "buildx"] + self.task_detail["build"]
build_command.append(os.path.join(self.CLONE_BASE, self.task))
subprocess.run(build_command, check=True)
command = ["docker", "buildx"] + self.task_detail["build"]
command.append(os.path.join(self.CLONE_BASE, self.task))
print(f"running: {command}")
subprocess.run(command, check=True)
def remove_task(self):
"""remove task from redis queue"""
@ -127,6 +139,7 @@ class Builder(RedisBase):
if __name__ == "__main__":
handler = Monitor()
handler.bootstrap()
handler.check_stored()
try:
handler.watch()
except KeyboardInterrupt:

View File

@ -25,11 +25,11 @@ class WebhookBase:
"-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"
["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"),

View File

@ -437,13 +437,20 @@ class TaskHandler(RedisBase):
if not self.tag_name:
return self.repo_conf.get(task_name)
command = self.repo_conf.get(task_name)
for idx, command_part in enumerate(command):
if "$VERSION" in command_part:
subed = command_part.replace("$VERSION", self.tag_name)
command[idx] = subed
all_commands = self.repo_conf.get(task_name)
return command
if all(isinstance(i, list) for i in all_commands):
to_build_commands = []
for command in all_commands:
to_build_commands.append(self._replace_version(command))
else:
to_build_commands = self._replace_version(all_commands)
return to_build_commands
def _replace_version(self, command):
"""replace version in str"""
return [i.replace("$VERSION", self.tag_name) for i in command]
def set_pub(self):
"""set message to pub"""