mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-11-26 06:31:04 +01:00
optimized draft
This commit is contained in:
parent
7fdeb677de
commit
240dbac8dd
@ -3,11 +3,16 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
def run_command(command):
|
def run_command(command):
|
||||||
try:
|
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
|
|
||||||
except subprocess.CalledProcessError as e:
|
# Iterate over the output lines
|
||||||
print(e.output.decode())
|
for line in iter(process.stdout.readline, b''):
|
||||||
sys.exit(e.returncode)
|
sys.stdout.write(line.decode())
|
||||||
|
|
||||||
|
process.stdout.close()
|
||||||
|
return_code = process.wait()
|
||||||
|
if return_code:
|
||||||
|
raise subprocess.CalledProcessError(return_code, command)
|
||||||
|
|
||||||
def git_pull(directory):
|
def git_pull(directory):
|
||||||
os.chdir(directory)
|
os.chdir(directory)
|
||||||
@ -34,9 +39,17 @@ def update_docker(directory):
|
|||||||
os.chdir(directory)
|
os.chdir(directory)
|
||||||
before_digests = get_image_digests(directory)
|
before_digests = get_image_digests(directory)
|
||||||
print("Pulling docker images.")
|
print("Pulling docker images.")
|
||||||
run_command("docker-compose pull")
|
|
||||||
after_digests = get_image_digests(directory)
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
run_command("docker-compose pull")
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
if "pull access denied" in e.output.decode() or "must be built from source" in e.output.decode():
|
||||||
|
print("Need to build the image from source.")
|
||||||
|
else:
|
||||||
|
print("Failed to pull images with unexpected error.")
|
||||||
|
raise
|
||||||
|
|
||||||
|
after_digests = get_image_digests(directory)
|
||||||
if before_digests != after_digests:
|
if before_digests != after_digests:
|
||||||
print("Changes detected in image digests. Rebuilding containers.")
|
print("Changes detected in image digests. Rebuilding containers.")
|
||||||
run_command("docker-compose up -d --build --force-recreate")
|
run_command("docker-compose up -d --build --force-recreate")
|
12
roles/update-docker/handlers/main.yml
Normal file
12
roles/update-docker/handlers/main.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
- name: "reload disc-space-check.service"
|
||||||
|
systemd:
|
||||||
|
name: disc-space-check.service
|
||||||
|
state: reloaded
|
||||||
|
enabled: yes
|
||||||
|
daemon_reload: yes
|
||||||
|
- name: "restart disc-space-check.timer"
|
||||||
|
systemd:
|
||||||
|
name: disc-space-check.timer
|
||||||
|
state: restarted
|
||||||
|
enabled: yes
|
||||||
|
daemon_reload: yes
|
9
roles/update-docker/tasks/main.yml
Normal file
9
roles/update-docker/tasks/main.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
- name: configure docker-volume-backup-cleanup.service
|
||||||
|
template:
|
||||||
|
src: docker-volume-backup-cleanup.service.j2
|
||||||
|
dest: /etc/systemd/system/docker-volume-backup-cleanup.service
|
||||||
|
|
||||||
|
- name: create {{update_docker_script}}
|
||||||
|
copy:
|
||||||
|
src: update-docker.py
|
||||||
|
dest: "{{update_docker_script}}"
|
7
roles/update-docker/templates/update-docker.service.j2
Normal file
7
roles/update-docker/templates/update-docker.service.j2
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Updates Docker Instances
|
||||||
|
OnFailure=systemd-notifier@%n.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/bin/sh -c '/usr/bin/python {{update_docker_script}} {{docker_volume_backup_cleanup_trigger_directory}}'
|
1
roles/update-docker/vars/main.yml
Normal file
1
roles/update-docker/vars/main.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
update_docker_script: "{{path_administrator_scripts}}/update-docker.py"
|
Loading…
Reference in New Issue
Block a user