mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-11-01 02:33:10 +01:00
Added draft for update-docker
This commit is contained in:
parent
64d8098612
commit
f091721402
@ -1,4 +1,26 @@
|
||||
---
|
||||
- name: Wait in a loop until the service update-docker.service is inactive
|
||||
block:
|
||||
- name: Check the status of update-docker.service
|
||||
command: systemctl is-active update-docker.service
|
||||
register: service_status
|
||||
changed_when: false
|
||||
failed_when: service_status.stdout == 'active'
|
||||
|
||||
- name: Pause for 60 seconds if the service is still active
|
||||
pause:
|
||||
seconds: 60
|
||||
when: service_status.stdout == 'active'
|
||||
become: true
|
||||
until: service_status.stdout != 'active'
|
||||
retries: 720
|
||||
delay: 10
|
||||
|
||||
- name: Abort if the service is still active after the maximum attempts
|
||||
fail:
|
||||
msg: "The update-docker.service is still active after the maximum number of attempts."
|
||||
when: service_status.stdout == 'active' and service_status.attempts == 10
|
||||
|
||||
- name: docker & docker compose install
|
||||
pacman:
|
||||
name: ['docker','docker-compose']
|
||||
|
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- { role: system-pacman, when: ansible_distribution == 'Archlinux' }
|
||||
- { role: system-apt-update, when: ansible_distribution == "Debian" }
|
@ -1,4 +1,4 @@
|
||||
# role system-apt-update
|
||||
# role update-apt
|
||||
This role updates the packages
|
||||
|
||||
# upgrade
|
4
roles/update-docker/README.md
Normal file
4
roles/update-docker/README.md
Normal file
@ -0,0 +1,4 @@
|
||||
# update-docker
|
||||
script to update docker-compose instances
|
||||
## See
|
||||
- [ChatGPT: Docker --force-recreate vs. --build](https://chat.openai.com/share/4cbf76a0-878b-4ce4-ba43-08a7b6dfcd0b)
|
43
roles/update-docker/files/update-docker-compose-instances.sh
Normal file
43
roles/update-docker/files/update-docker-compose-instances.sh
Normal file
@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check if a path argument was provided
|
||||
if [ -z "$1" ]; then
|
||||
echo "Please provide the path to the parent directory as a parameter."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Iterate over all directories in the parent directory
|
||||
for dir in "$1"/*; do
|
||||
# Check if it is indeed a directory
|
||||
if [ -d "$dir" ]; then
|
||||
echo "Checking for updates in: $dir"
|
||||
cd "$dir"
|
||||
|
||||
# Check if directory is a Git repository
|
||||
if [ -d ".git" ]; then
|
||||
echo "Checking if the git repository is up to date."
|
||||
git fetch
|
||||
LOCAL=$(git rev-parse @)
|
||||
REMOTE=$(git rev-parse @{u})
|
||||
|
||||
# If local commit differs from remote, pull the changes
|
||||
if [ "$LOCAL" != "$REMOTE" ]; then
|
||||
echo "Repository is not up to date. Performing git pull."
|
||||
git pull || exit 3
|
||||
else
|
||||
echo "Repository is already up to date."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Pull the latest images and rebuild the containers
|
||||
echo "Pulling docker images and rebuilding containers."
|
||||
docker-compose pull && docker-compose up -d --build --force-recreate || exit 1
|
||||
|
||||
# Additional command for the 'nextcloud' directory
|
||||
if [ "$(basename "$dir")" == "nextcloud" ]; then
|
||||
echo "Updating Nextcloud apps."
|
||||
docker-compose exec -T -u www-data application /var/www/html/occ app:update --all || exit 2
|
||||
fi
|
||||
cd - > /dev/null
|
||||
fi
|
||||
done
|
2
roles/update/meta/README.md
Normal file
2
roles/update/meta/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
# update
|
||||
starts all of the different system update roles based on conditions
|
10
roles/update/meta/main.yml
Normal file
10
roles/update/meta/main.yml
Normal file
@ -0,0 +1,10 @@
|
||||
tasks:
|
||||
- name: "Check if {{path_docker_compose_files}} directory exists"
|
||||
stat:
|
||||
path: {{path_docker_compose_files}}
|
||||
register: docker_compose_directory_stat
|
||||
|
||||
roles:
|
||||
- { role: update-pacman, when: ansible_distribution == 'Archlinux' }
|
||||
- { role: update-apt, when: ansible_distribution == "Debian" }
|
||||
- { role: update-docker, when: docker_compose_directory_stat.stat.exists }
|
Loading…
Reference in New Issue
Block a user