78 lines
2.2 KiB
Bash
Executable File
78 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
|
echo "Script directory: $SCRIPT_DIR"
|
|
|
|
### Functions
|
|
usage()
|
|
{
|
|
echo "usage: $0 [-m docker_image -t tag -r repolist] | [-h]"
|
|
}
|
|
|
|
main()
|
|
{
|
|
local IMAGE=$1
|
|
local IMAGE_TAG=$2
|
|
local REPOLIST=$3
|
|
|
|
KUST_FILES_LINES=$(grep -e "$IMAGE\s" $REPOLIST)
|
|
if [ -z "$KUST_FILES_LINES" ]
|
|
then
|
|
echo "Nothing to update";
|
|
exit;
|
|
fi
|
|
|
|
while IFS= read -r KUST_FILES_LINE; do
|
|
KUST_PATH=$(echo "$KUST_FILES_LINE" | tr -s " " | cut -d " " -f 2)
|
|
#Need to add $ after ${IMAGE} so partial names don't get matched. (Eg: z5-edge shoudln't match z5-edge-socket)
|
|
#In the kustomization file, the name "repo2.hub.gmetri.io/repo-name" might end with either a space OR and endline character. Handline both cases.
|
|
LINE_N1=$(grep -n -e "${IMAGE}$" -e "${IMAGE}\s" ${KUST_PATH} | cut -d ":" -f 1)
|
|
LINE_N2=$(expr "$LINE_N1" + "1")
|
|
|
|
#Replace repo verion in kustomization.yaml. -n is true only if the following argument is non empty
|
|
if [ -n "$LINE_N2" ]
|
|
then
|
|
echo "Replacement Op: sed -i -e \"${LINE_N2}s/newTag: .*/newTag: ${IMAGE_TAG}/\" \"$KUST_PATH\""
|
|
sed -i -e "${LINE_N2}s/newTag: .*/newTag: ${IMAGE_TAG}/" "$KUST_PATH"
|
|
|
|
git add $KUST_PATH;
|
|
fi
|
|
done <<< "$KUST_FILES_LINES"
|
|
|
|
source $SCRIPT_DIR/repo_to_cs_basetag.sh;
|
|
# cat $NEW_TAG > version; #To always allow a commit
|
|
# git add version;
|
|
git commit -m "$NEW_TAG: $IMAGE updated to $IMAGE_TAG";
|
|
git tag -a $NEW_TAG -m "$NEW_TAG: $IMAGE updated to $IMAGE_TAG"
|
|
}
|
|
|
|
### Starts here
|
|
while [ "$1" != "" ]; do
|
|
case $1 in
|
|
-m | --image ) shift
|
|
IMAGE=$1
|
|
;;
|
|
-t | --tag ) shift
|
|
IMAGE_TAG=$1
|
|
;;
|
|
-r | --repolist ) shift
|
|
REPOLIST=$1
|
|
;;
|
|
-h | --help ) usage
|
|
exit
|
|
;;
|
|
* ) usage
|
|
exit 1
|
|
esac
|
|
shift
|
|
done
|
|
|
|
if [[ -z $IMAGE || -z $IMAGE_TAG || -z $REPOLIST ]]
|
|
then
|
|
echo "Not enough arguments"
|
|
usage
|
|
exit
|
|
fi
|
|
|
|
main "$IMAGE" "$IMAGE_TAG" "$REPOLIST"
|