Skip to content

Instantly share code, notes, and snippets.

@wshino
Last active December 13, 2018 09:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wshino/e0473c3c390d7aee27e9c5912fcdc1c6 to your computer and use it in GitHub Desktop.
Save wshino/e0473c3c390d7aee27e9c5912fcdc1c6 to your computer and use it in GitHub Desktop.
#!/bin/bash
function usage {
echo " Description"
echo " this shell script uses for when updating lots of images."
echo ""
echo " Usage:"
echo " $ ./set-image.sh SEARCH_NAME SEARCH_VERSION TARGET_VERSION"
echo " * SEARCH_NAME: query for container image name"
echo " * SEARCH_VERSION: query for container image tag"
echo " * TARGET_VERSION: target tag for set image command"
exit 1
}
[ -z $1 ] && { usage; }
SEARCH_NAME=$1
SEARCH_VERSION=$2
TARGET_VERSION=$3
TARGETS=`kubectl get deployment --output=json | jq ".items[] | select(.spec.template.spec.containers[].image | test(\"${SEARCH_NAME}:${SEARCH_VERSION}\")) | .metadata.name" -r`
for target in ${TARGETS[@]}; do
"kubectl set image deployment.v1.apps/$target ${SEARCH_NAME}=${SEARCH_NAME}:${TARGET_VERSION} --record"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment