This commit is contained in:
@@ -7,31 +7,21 @@ def git_diff():
|
|||||||
res = subprocess.run(f"git diff --name-only {args[1]} {args[2]}", capture_output=True, shell=True, text=True)
|
res = subprocess.run(f"git diff --name-only {args[1]} {args[2]}", capture_output=True, shell=True, text=True)
|
||||||
return [x for x in res.stdout.strip().split("\n") if "tasks/" in x or "roles/" in x]
|
return [x for x in res.stdout.strip().split("\n") if "tasks/" in x or "roles/" in x]
|
||||||
|
|
||||||
def construct_command(tag = None, host = None):
|
def construct_command(tags = []):
|
||||||
command = f"ANSIBLE_CONFIG=ansible.cfg /usr/bin/ansible-playbook main.yml --vault-password-file ~/.vault_pass.txt"
|
command = f"ANSIBLE_CONFIG=ansible.cfg /usr/bin/ansible-playbook main.yml --vault-password-file ~/.vault_pass.txt"
|
||||||
|
command += f" --tags {",".join(tags)}"
|
||||||
if host:
|
|
||||||
command += f" -l {host}"
|
|
||||||
if tag:
|
|
||||||
command += f" --tags {tag}_deploy"
|
|
||||||
|
|
||||||
return command
|
return command
|
||||||
|
|
||||||
def deploy(tag = None, host = None):
|
def deploy(tags):
|
||||||
command = construct_command(tag, host)
|
print(f"[MAIN] Deploying...")
|
||||||
|
command = construct_command(tags)
|
||||||
if tag:
|
|
||||||
print(f"[MAIN] Deploying {tag}...")
|
|
||||||
else:
|
|
||||||
print(f"[MAIN] Deploying host {host}...")
|
|
||||||
res = subprocess.run(command, shell=True)
|
res = subprocess.run(command, shell=True)
|
||||||
|
|
||||||
return res.returncode == 0
|
return res.returncode == 0
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
dir_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../')
|
dir_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../')
|
||||||
diff = git_diff()
|
diff = git_diff()
|
||||||
print(diff)
|
|
||||||
|
|
||||||
# containers that need special treatment
|
# containers that need special treatment
|
||||||
removed_containers = []
|
removed_containers = []
|
||||||
@@ -39,10 +29,10 @@ def main():
|
|||||||
"tasks/qbittorrent.yml",
|
"tasks/qbittorrent.yml",
|
||||||
"tasks/jackett.yml"
|
"tasks/jackett.yml"
|
||||||
]
|
]
|
||||||
managed_roles = [
|
ignore_deploys_for = [
|
||||||
"roles/fivem",
|
"tasks/runner",
|
||||||
"roles/gitea-runner",
|
"templates/runner",
|
||||||
"roles/traefik"
|
"roles/docker"
|
||||||
]
|
]
|
||||||
|
|
||||||
# special actions
|
# special actions
|
||||||
@@ -55,35 +45,22 @@ def main():
|
|||||||
# clean up the diff
|
# clean up the diff
|
||||||
new_diff = []
|
new_diff = []
|
||||||
for file in diff:
|
for file in diff:
|
||||||
task_name = f"{file.split('/')[0]}/{file.split('/')[1]}"
|
split_string = file.split("/")
|
||||||
|
service_name = split_string[1].split(".")[0] + "_deploy" if "." in split_string[1] else split_string[1] + "_deploy"
|
||||||
|
|
||||||
# i'm not proud of this either
|
# i'm not proud of this either
|
||||||
if not os.path.exists(os.path.join(dir_path, file)):
|
if not os.path.exists(os.path.join(dir_path, file)):
|
||||||
if "roles" in file and not os.path.exists(os.path.join(dir_path, task_name)) and task_name in managed_roles:
|
if "roles" in file and not os.path.exists(os.path.join(dir_path, service_name)):
|
||||||
print(f"[MAIN] '{task_name}' role removed, marking for cleanup..")
|
print(f"[MAIN] '{task_name}' role removed, marking for cleanup..")
|
||||||
removed_containers.append(task_name)
|
removed_containers.append(service_name)
|
||||||
elif "tasks" in task_name:
|
elif "tasks" in task_name:
|
||||||
print(f"[MAIN] '{task_name}' non-existent, marking for cleanup..")
|
print(f"[MAIN] '{task_name}' non-existent, marking for cleanup..")
|
||||||
removed_containers.append(task_name)
|
removed_containers.append(service_name)
|
||||||
elif "roles" in file:
|
|
||||||
if task_name in managed_roles:
|
|
||||||
if task_name not in new_diff:
|
|
||||||
new_diff.append(task_name)
|
|
||||||
elif "tasks" in file:
|
|
||||||
new_diff.append(file.split(".")[0])
|
|
||||||
else:
|
else:
|
||||||
new_diff.append(file)
|
if service_name not in ignore_deploys_for and service_name not in new_diff:
|
||||||
|
new_diff.append(service_name)
|
||||||
|
|
||||||
deployed = []
|
deployed = deploy(tag=",".join(new_diff))
|
||||||
failed = []
|
|
||||||
|
|
||||||
for task in new_diff:
|
|
||||||
deployment = deploy(tag=task.split("/")[1])
|
|
||||||
|
|
||||||
if not deployment:
|
|
||||||
failed.append(task)
|
|
||||||
else:
|
|
||||||
deployed.append(task)
|
|
||||||
|
|
||||||
for task in removed_containers:
|
for task in removed_containers:
|
||||||
print(f"[MAIN] Attempting to remove containers related to '{task}'...")
|
print(f"[MAIN] Attempting to remove containers related to '{task}'...")
|
||||||
@@ -101,20 +78,19 @@ def main():
|
|||||||
subprocess.run("/usr/bin/docker image prune -f", shell=True)
|
subprocess.run("/usr/bin/docker image prune -f", shell=True)
|
||||||
subprocess.run("/usr/bin/docker container prune -f", shell=True)
|
subprocess.run("/usr/bin/docker container prune -f", shell=True)
|
||||||
|
|
||||||
if len(failed) <= 0 and len(deployed) > 0:
|
if deployed:
|
||||||
print("\n---------------------")
|
print("\n---------------------")
|
||||||
print(" Deployment succeeded!")
|
print(" Deployment succeeded!")
|
||||||
print(f" All tasks: {', '.join(deployed)}")
|
print(f" All tasks: {', '.join(new_diff)}")
|
||||||
print("---------------------\n")
|
print("---------------------\n")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
elif len(failed) > 0:
|
elif not deployed:
|
||||||
print("\n---------------------")
|
print("\n---------------------")
|
||||||
print(" Deployment failed!")
|
print(" Deployment failed!")
|
||||||
print(f" Failed tasks: {', '.join(failed)}")
|
print(f" All tasks: {', '.join(new_diff)}")
|
||||||
print(f" All tasks: {', '.join(deployed)}")
|
|
||||||
print("---------------------\n")
|
print("---------------------\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif len(deployed) <= 0:
|
elif len(new_diff) <= 0:
|
||||||
print("[MAIN] Successfully executed, no tasks required execution")
|
print("[MAIN] Successfully executed, no tasks required execution")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ scrape_configs:
|
|||||||
- targets: ["monitoring_prometheus:9090"]
|
- targets: ["monitoring_prometheus:9090"]
|
||||||
- job_name: "node-exporter"
|
- job_name: "node-exporter"
|
||||||
static_configs:
|
static_configs:
|
||||||
- targets: ["172.16.0.25:9100"]
|
- targets: ["172.16.0.44:9100"]
|
||||||
- job_name: "cadvisor"
|
- job_name: "cadvisor"
|
||||||
static_configs:
|
static_configs:
|
||||||
- targets: ["monitoring_cadvisor:8080"]
|
- targets: ["monitoring_cadvisor:8080"]
|
||||||
Reference in New Issue
Block a user