Update GIS docker image tags on master/main branch #24
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
# This github workflow will automatically update docker image tags of gis-depl in the datakaveri/iudx-deployment repository files, whenever docker image is pushed to ghcr.io/datakaveri/gis-depl .Based on tag it will update the master/latest branch (if its 5.5.1-alpha-) or 5.5.0 stable branch (if its 5.5.0-) | |
name: Update GIS docker image tags | |
# This trigger will run the workflow whenever a new package is published to the registry | |
on: | |
registry_package: | |
types: [published] | |
# This is needed to read the registry packages | |
permissions: | |
packages: read | |
jobs: | |
build: | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
repository: datakaveri/iudx-deployment | |
# Jenkins token to perform git operations | |
token: "${{ secrets.JENKINS_UPDATE }}" | |
fetch-depth: 0 | |
# This step updates the GIS Server docker image tags | |
- name: Update GIS docker image tags | |
env: | |
GH_TOKEN: ${{ secrets.JENKINS_UPDATE}} | |
run: | | |
# Get the latest version of 5.5.0 and 5.5.1-alpha tags from the container registry using GitHub API | |
export newtag5_5_0=`(head -n 1 <(curl -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/orgs/datakaveri/packages/container/gis-depl/versions | jq ' .[].metadata.container.tags[0]' | grep 5.5.0 | grep -v alpha | sed -e 's/^"//' -e 's/"$//'))` | |
export newtag5_5_1=`(head -n 1 <(curl -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/orgs/datakaveri/packages/container/gis-depl/versions | jq ' .[].metadata.container.tags[0]' | grep 5.5.1-alpha | sed -e 's/^"//' -e 's/"$//'))` | |
# Get the old tags from the YAML files | |
export oldtag5_5_1=`yq -r .services.gis.image Docker-Swarm-deployment/single-node/gis/gis-stack.yaml | cut -d : -f 2` | |
git checkout 5.5.0 | |
export oldtag5_5_0=$(yq -r .services.gis.image Docker-Swarm-deployment/single-node/gis/gis-stack.yaml | cut -d : -f 2) | |
# Set Git user | |
git config --global user.name 'jenkins-datakaveri' | |
git config --global user.email "[email protected]" | |
# Update the YAML files and create a new branch for each tag update | |
if [ "$newtag5_5_0" != "$oldtag5_5_0" ] | |
then | |
git checkout -b gis-5.5.0-automatic-updates/$newtag5_5_0 | |
# Uses sed to find and replace $oldtag5_5_0 with $newtag5_5_0 in Docker-Swarm-deployment/single-node/gis/gis-stack.yaml file | |
sed -i s/$oldtag5_5_0/$newtag5_5_0/g Docker-Swarm-deployment/single-node/gis/gis-stack.yaml | |
# Exports the current version of the application from K8s-deployment/Charts/gis-interface/Chart.yaml file | |
export oldappversion=`yq -r .version K8s-deployment/Charts/gis-interface/Chart.yaml` | |
# Uses awk to increment the version number in K8s-deployment/Charts/gis-server/Chart.yaml file | |
export newappversion=`yq -r .version K8s-deployment/Charts/gis-interface/Chart.yaml | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}' ` | |
# Uses sed to find and replace $oldappversion with $newappversion in K8s-deployment/Charts/gis-interface/Chart.yaml and K8s-deployment/Charts/gis-interface/values.yaml files | |
sed -i s/$oldappversion/$newappversion/g K8s-deployment/Charts/gis-interface/Chart.yaml | |
sed -i s/$oldtag5_5_0/$newtag5_5_0/g K8s-deployment/Charts/gis-interface/values.yaml | |
git add Docker-Swarm-deployment/single-node/gis/gis-stack.yaml K8s-deployment/Charts/gis-interface/values.yaml K8s-deployment/Charts/gis-interface/Chart.yaml | |
git commit --allow-empty -m "updated GIS docker image tag to $newtag5_5_0" | |
git push --set-upstream origin gis-5.5.0-automatic-updates/$newtag5_5_0 | |
# Creates a new pull request on the datakaveri/iudx-deployment repository with the base branch 5.5.0 | |
gh pr create -R datakaveri/iudx-deployment --base 5.5.0 --fill | |
fi | |
if [ "$newtag5_5_1" != "$oldtag5_5_1" ] | |
then | |
git checkout master | |
git checkout -b gis-automatic-updates/$newtag5_5_1 | |
# Uses sed to find and replace $oldtag5_5_1 with $newtag5_5_1 in Docker-Swarm-deployment/single-node/gis/gis-stack.yaml file | |
sed -i s/$oldtag5_5_1/$newtag5_5_1/g Docker-Swarm-deployment/single-node/gis/gis-stack.yaml | |
# Exports the current version of the application from K8s-deployment/Charts/gis-interface/Chart.yaml file | |
export oldappversion=`yq -r .version K8s-deployment/Charts/gis-interface/Chart.yaml` | |
# Uses sed to find and replace $oldappversion with $newappversion in K8s-deployment/Charts/gis-interface/Chart.yaml and K8s-deployment/Charts/gis-interface/values.yaml files | |
export newappversion=`yq -r .version K8s-deployment/Charts/gis-interface/Chart.yaml | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}' ` | |
sed -i s/$oldappversion/$newappversion/g K8s-deployment/Charts/gis-interface/Chart.yaml | |
sed -i s/$oldtag5_5_1/$newtag5_5_1/g K8s-deployment/Charts/gis-interface/values.yaml | |
git add Docker-Swarm-deployment/single-node/gis/gis-stack.yaml K8s-deployment/Charts/gis-interface/values.yaml K8s-deployment/Charts/gis-interface/Chart.yaml | |
git commit --allow-empty -m "updated GIS docker image tag to $newtag5_5_1" | |
git push --set-upstream origin gis-automatic-updates/$newtag5_5_1 | |
# Creates a new pull request on the datakaveri/iudx-deployment repository with the base branch master | |
gh pr create -R datakaveri/iudx-deployment --base master --fill | |
fi | |