From 8ae14800d1ee97e13e469d4b4de8f39e2d5b44fb Mon Sep 17 00:00:00 2001 From: Alex Frantz Date: Fri, 1 Aug 2025 11:27:33 -0400 Subject: [PATCH] reload caddy for caddyfile on deployment --- main.yml | 6 ++++++ roles/caddy/tasks/create.yml | 5 +++++ roles/caddy/tasks/main.yml | 5 ----- scripts/deploy_containers.py | 22 +++++++--------------- 4 files changed, 18 insertions(+), 20 deletions(-) create mode 100644 roles/caddy/tasks/create.yml diff --git a/main.yml b/main.yml index 63eaf46..41bbdf2 100644 --- a/main.yml +++ b/main.yml @@ -7,6 +7,9 @@ tags: gitea-runner_deploy tasks: + - name: Generate Caddyfile + import_tasks: roles/caddy/tasks/create.yml + tags: caddyfile_deploy - name: Deploy Glance import_tasks: tasks/glance.yml tags: glance_deploy @@ -84,6 +87,9 @@ tags: caddy_deploy tasks: + - name: Generate Caddyfile + import_tasks: roles/caddy/tasks/create.yml + tags: caddyfile_deploy - name: Deploy Gitea import_tasks: tasks/gitea.yml tags: gitea_deploy diff --git a/roles/caddy/tasks/create.yml b/roles/caddy/tasks/create.yml new file mode 100644 index 0000000..2f10541 --- /dev/null +++ b/roles/caddy/tasks/create.yml @@ -0,0 +1,5 @@ +--- +- name: Create Caddyfile + template: + src: roles/caddy/templates/Caddyfile.j2 + dest: "{{ data_dir }}/caddy/Caddyfile" diff --git a/roles/caddy/tasks/main.yml b/roles/caddy/tasks/main.yml index cf87ae9..f5a0151 100644 --- a/roles/caddy/tasks/main.yml +++ b/roles/caddy/tasks/main.yml @@ -8,11 +8,6 @@ - "{{ data_dir }}/caddy/data" - "{{ data_dir }}/caddy/certs" -- name: Create Caddyfile - template: - src: Caddyfile.j2 - dest: "{{ data_dir }}/caddy/Caddyfile" - - name: Create Dockerfile template: src: Dockerfile.j2 diff --git a/scripts/deploy_containers.py b/scripts/deploy_containers.py index 3e175a9..d8d1cc6 100644 --- a/scripts/deploy_containers.py +++ b/scripts/deploy_containers.py @@ -10,24 +10,23 @@ def git_diff(): res = subprocess.run(f"git diff --name-only {args[1]} {args[2]}", capture_output=True, shell=True, text=True) return res.stdout.strip().split("\n") -def construct_ansible_command(server_name = None, tag = None): +def construct_ansible_command(tag = None): command = "ANSIBLE_CONFIG=ansible.cfg /usr/bin/ansible-playbook main.yml --vault-password-file ~/.vault_pass.txt" - if server_name: - command += f" -l {server_name}" if tag: command += f" --tags {tag}" return command -def run_deployment(server_name = None, tag = None): +def run_deployment(tag = None): if tag: - print(f"Deploying task '{tag}'..") command = construct_ansible_command(tag=tag) - elif server_name: - print(f"Deploying caddy on server '{server_name}'..") - command = construct_ansible_command(server_name, "caddy_server") + print("Reloading Caddyfile..") + subprocess.run(construct_ansible_command(tag="caddyfile_deploy")) + subprocess.run("docker exec -w /etc/caddy caddy caddy reload", shell=True) + + print(f"Running deployment for {tag}..") res = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) lines = res.stdout.decode(encoding='utf-8').split("\n") @@ -55,13 +54,6 @@ def main(): success = True for file in diff: - if "host_vars" in file: - server_name = file.split("/")[1].split(".")[0] - state = run_deployment(server_name=server_name) - - if not state: - success = False - break if "tasks" in file: task_name = file.split("/")[1].split(".")[0] + "_deploy" state = run_deployment(tag=task_name)