reload caddy for caddyfile on deployment
Some checks failed
Deploy Containers / Prepare (push) Failing after 4s
Some checks failed
Deploy Containers / Prepare (push) Failing after 4s
This commit is contained in:
6
main.yml
6
main.yml
@@ -7,6 +7,9 @@
|
|||||||
tags: gitea-runner_deploy
|
tags: gitea-runner_deploy
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
|
- name: Generate Caddyfile
|
||||||
|
import_tasks: roles/caddy/tasks/create.yml
|
||||||
|
tags: caddyfile_deploy
|
||||||
- name: Deploy Glance
|
- name: Deploy Glance
|
||||||
import_tasks: tasks/glance.yml
|
import_tasks: tasks/glance.yml
|
||||||
tags: glance_deploy
|
tags: glance_deploy
|
||||||
@@ -84,6 +87,9 @@
|
|||||||
tags: caddy_deploy
|
tags: caddy_deploy
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
|
- name: Generate Caddyfile
|
||||||
|
import_tasks: roles/caddy/tasks/create.yml
|
||||||
|
tags: caddyfile_deploy
|
||||||
- name: Deploy Gitea
|
- name: Deploy Gitea
|
||||||
import_tasks: tasks/gitea.yml
|
import_tasks: tasks/gitea.yml
|
||||||
tags: gitea_deploy
|
tags: gitea_deploy
|
||||||
|
5
roles/caddy/tasks/create.yml
Normal file
5
roles/caddy/tasks/create.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- name: Create Caddyfile
|
||||||
|
template:
|
||||||
|
src: roles/caddy/templates/Caddyfile.j2
|
||||||
|
dest: "{{ data_dir }}/caddy/Caddyfile"
|
@@ -8,11 +8,6 @@
|
|||||||
- "{{ data_dir }}/caddy/data"
|
- "{{ data_dir }}/caddy/data"
|
||||||
- "{{ data_dir }}/caddy/certs"
|
- "{{ data_dir }}/caddy/certs"
|
||||||
|
|
||||||
- name: Create Caddyfile
|
|
||||||
template:
|
|
||||||
src: Caddyfile.j2
|
|
||||||
dest: "{{ data_dir }}/caddy/Caddyfile"
|
|
||||||
|
|
||||||
- name: Create Dockerfile
|
- name: Create Dockerfile
|
||||||
template:
|
template:
|
||||||
src: Dockerfile.j2
|
src: Dockerfile.j2
|
||||||
|
@@ -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)
|
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")
|
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"
|
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:
|
if tag:
|
||||||
command += f" --tags {tag}"
|
command += f" --tags {tag}"
|
||||||
|
|
||||||
return command
|
return command
|
||||||
|
|
||||||
def run_deployment(server_name = None, tag = None):
|
def run_deployment(tag = None):
|
||||||
if tag:
|
if tag:
|
||||||
print(f"Deploying task '{tag}'..")
|
|
||||||
command = construct_ansible_command(tag=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)
|
res = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
lines = res.stdout.decode(encoding='utf-8').split("\n")
|
lines = res.stdout.decode(encoding='utf-8').split("\n")
|
||||||
|
|
||||||
@@ -55,13 +54,6 @@ def main():
|
|||||||
|
|
||||||
success = True
|
success = True
|
||||||
for file in diff:
|
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:
|
if "tasks" in file:
|
||||||
task_name = file.split("/")[1].split(".")[0] + "_deploy"
|
task_name = file.split("/")[1].split(".")[0] + "_deploy"
|
||||||
state = run_deployment(tag=task_name)
|
state = run_deployment(tag=task_name)
|
||||||
|
Reference in New Issue
Block a user