Created
December 26, 2022 20:49
-
-
Save korynewton/f3eb33facbba21f5d8c66ff22eac4b12 to your computer and use it in GitHub Desktop.
recreate docker pods if local diverges from remote
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
#!/usr/bin/env bash | |
# abort the script if a command returns with a non-zero exit code | |
set -o errexit | |
# abort script when accessing an unset variable | |
set -o nounset | |
# pipeline command is treated as failed, even if one command in the pipeline fails | |
set -o pipefail | |
if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace; fi | |
# get flags | |
while getopts u:b: flag | |
do | |
case "${flag}" in | |
u) REPO_URL=${OPTARG};; | |
b) BRANCH=${OPTARG};; | |
*) echo "usage: $0 [-u <repo url>] [-b <branch name>]" >&2 | |
exit 1 ;; | |
esac | |
done | |
# hash of last commit of remote origin | |
REMOTE_HASH=$(git ls-remote "$REPO_URL" --heads "refs/heads/$BRANCH" | awk '{print $1}') | |
# hash of last commit of local | |
LOCAL_HASH=$(git rev-parse HEAD) | |
echo "REMOTE_HASH=${REMOTE_HASH-}" | |
echo "LOCAL_HASH=${LOCAL_HASH-}" | |
if [[ "$REMOTE_HASH" == "$LOCAL_HASH" ]] | |
then | |
echo "no changes" | |
exit 0 | |
fi | |
# if so recreate new pods | |
echo "building and redeploying pods" | |
git pull | |
docker-compose up --force-recreate --build -d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment