Created
August 23, 2019 13:32
-
-
Save lkebin/95266ddb6a7c53d4e2418f444fdb5836 to your computer and use it in GitHub Desktop.
Run command after Docker image update, but nothing to do if no update
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/sh | |
script=$(basename $0) | |
image=$1 | |
arg=$@ | |
function current() { | |
local a=$(docker inspect ${image} -f '{{index .RepoDigests 0}}') | |
echo ${a#*@} | |
} | |
function latest() { | |
docker pull ${image} | grep Digest | awk '{print $2}' | |
} | |
function usage() { | |
echo "Usage: ${script} name[:tag|@digest] [-- cmd [arguments]]" | |
} | |
function cmd() { | |
echo ${arg#*--} | |
} | |
function main() { | |
if [[ "$image" == "" ]]; then | |
usage | |
exit 1 | |
fi | |
# Get current first | |
currentHash=$(current) | |
# Get latest second | |
latestHash=$(latest) | |
echo "OLD:[$latestHash]" | |
echo "NEW:[$currentHash]" | |
if [[ "$latestHash" != "$currentHash" ]]; then | |
exec $(cmd) | |
fi | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment