Last active
September 16, 2021 18:01
-
-
Save realies/261e7dbd2ca9f658ef3ee9eab0bb2aab to your computer and use it in GitHub Desktop.
posix compliant script to upgrade all subfolder docker compose services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -ex | |
if [ -z "$1" ]; then | |
for dir in */; do [ -e "$dir" ] || continue; ./upgrade.sh "$dir"; done | |
exit 0 | |
fi | |
cwd="$(pwd)" | |
cd "$1" | |
if [ -f Dockerfile ]; then | |
image=$(cat Dockerfile | awk 'tolower($1) == "from" { print $2 }') | |
elif [ -f docker-compose.y*ml ]; then | |
image=$(cat docker-compose.y*ml | awk 'tolower($1) == "image:" { print $2 }') | |
else | |
echo "Subfolder $1 must contain a docker-compose.y*ml" | |
exit 1 | |
fi | |
docker pull $(echo $image) | grep -i 'image is up to date' && exit 0 | |
docker-compose down | |
docker-compose up -d | |
docker system prune -f | |
cd "$cwd" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment