Cleaner docker compose update script.
This commit is contained in:
parent
9683592cbc
commit
c23040b417
1 changed files with 65 additions and 72 deletions
137
update.sh
137
update.sh
|
@ -2,89 +2,82 @@
|
||||||
|
|
||||||
|
|
||||||
services=(coturn element etebase nginx-www searxng synapse syncthing vw)
|
services=(coturn element etebase nginx-www searxng synapse syncthing vw)
|
||||||
|
needs_backup=(etebase synapse vw)
|
||||||
|
|
||||||
|
|
||||||
rel_path="$(dirname "$0")"
|
rel_path="$(dirname "$0")"
|
||||||
|
|
||||||
|
|
||||||
function compose_up {
|
function pull {
|
||||||
docker-compose -f "$rel_path/$1/docker-compose.yaml" pull
|
[[ "$1" == "coturn" ]] && local sudo="sudo"
|
||||||
docker-compose -f "$rel_path/$1/docker-compose.yaml" up -d
|
$sudo docker-compose -f "$rel_path/$1/docker-compose.yaml" pull
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function coturn_update {
|
# Runs compose up & eventually make a backup before
|
||||||
sudo docker-compose -f "$rel_path/coturn/docker-compose.yaml" pull
|
# $1 = project name
|
||||||
sudo docker-compose -f "$rel_path/coturn/docker-compose.yaml" up -d
|
function up {
|
||||||
}
|
if echo "${needs_backup[*]}" | grep -qP "\b$1\b" && has_update "$1"; then
|
||||||
|
sudo "$rel_path/backup.sh" "$1" --norestart
|
||||||
|
|
||||||
function element_update {
|
|
||||||
compose_up element
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function etebase_update {
|
|
||||||
if ! docker pull victorrds/etebase:alpine | grep -q 'Image is up to date' ; then
|
|
||||||
echo "Update available for etebase."
|
|
||||||
sudo "$rel_path/backup.sh" etebase --norestart
|
|
||||||
compose_up etebase
|
|
||||||
else
|
|
||||||
echo "No update available for etebase."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function nginx-www_update {
|
|
||||||
compose_up nginx-www
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function searxng_update {
|
|
||||||
compose_up searxng
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function synapse_update {
|
|
||||||
has_update=0
|
|
||||||
if ! docker pull postgres:alpine | grep -q 'Image is up to date' || ! docker pull matrixdotorg/synapse:latest | grep -q 'Image is up to date'; then
|
|
||||||
has_update=1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $has_update -eq 1 ]]; then
|
[[ "$1" == "coturn" ]] && local sudo="sudo"
|
||||||
echo "Update available for synapse and/or postgres."
|
$sudo docker-compose -f "$rel_path/$1/docker-compose.yaml" up -d
|
||||||
sudo "$rel_path/backup.sh" synapse --norestart
|
|
||||||
compose_up synapse
|
|
||||||
else
|
|
||||||
echo "No update available for synapse and postgres."
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function syncthing_update {
|
# To use after pulling latest images of project
|
||||||
compose_up syncthing
|
# Checks if at least one container can be updated
|
||||||
}
|
# $1 = project name
|
||||||
|
function has_update {
|
||||||
|
readarray -t cont_list < <(docker-compose -f "$1/docker-compose.yaml" ps -a | tail -n+3 | cut -d ' ' -f 1)
|
||||||
function vw_update {
|
for cont in "${cont_list[@]}"; do
|
||||||
sudo "$rel_path/backup.sh" vw
|
# Return true if container doesn't exist
|
||||||
compose_up vw
|
if ! docker ps -a --format='{{.Names}}' | grep -q "$cont"; then
|
||||||
}
|
return 0
|
||||||
|
fi
|
||||||
|
cont_image_id="$(docker inspect "$cont" --format='{{.Image}}')"
|
||||||
if [[ -z "$1" || ! $(echo "${services[*]} all" | grep -P "\b$1\b" ) ]]; then
|
repo_url="$(docker inspect "$cont" --format='{{.Config.Image}}')"
|
||||||
echo "Wrong argument."
|
repo_image_id="$(docker image inspect "$repo_url" --format='{{.Id}}')"
|
||||||
echo "Options: ${services[*]}"
|
if [[ "$cont_image_id" != "$repo_image_id" ]]; then
|
||||||
exit 1
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [[ "$1" != "all" ]]; then
|
|
||||||
echo "Running $1 update."
|
|
||||||
${1}_update
|
|
||||||
else
|
|
||||||
for service in "${services[@]}"; do
|
|
||||||
echo "Running $service update."
|
|
||||||
${service}_update
|
|
||||||
done
|
done
|
||||||
fi
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
service="$(echo "$2" | sed -E 's/[/ ]//g')"
|
||||||
|
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
pull)
|
||||||
|
if [[ -z "$service" ]]; then
|
||||||
|
for serv in "${services[@]}"; do
|
||||||
|
pull "$serv"
|
||||||
|
done
|
||||||
|
elif echo "${services[*]}" | grep -qP "\b$service\b"; then
|
||||||
|
pull "$service"
|
||||||
|
else
|
||||||
|
echo "invalid project name. it should be one of: ${services[*]}."
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
up)
|
||||||
|
if [[ -z "$service" ]]; then
|
||||||
|
for serv in "${services[@]}"; do
|
||||||
|
pull "$serv"
|
||||||
|
up "$serv"
|
||||||
|
done
|
||||||
|
elif echo "${services[*]}" | grep -qP "\b$service\b"; then
|
||||||
|
pull "$service"
|
||||||
|
up "$service"
|
||||||
|
else
|
||||||
|
echo "Invalid project name. It should be one of: ${services[*]}."
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Invalid action. It should be one of: pull, up."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
Loading…
Reference in a new issue