From 4b804cbaaeefe3f0beee2b1bcc067f017ef2b0bd Mon Sep 17 00:00:00 2001 From: Siva Naik Date: Fri, 9 Aug 2024 13:45:47 +0530 Subject: [PATCH] Seperated docker image workflow file --- .github/workflows/docker-image-stable.yml | 60 ++++++++++++++ .github/workflows/docker-image.yml | 97 ++++++++--------------- Jenkinsfile | 6 +- 3 files changed, 95 insertions(+), 68 deletions(-) create mode 100644 .github/workflows/docker-image-stable.yml diff --git a/.github/workflows/docker-image-stable.yml b/.github/workflows/docker-image-stable.yml new file mode 100644 index 0000000..4e3f686 --- /dev/null +++ b/.github/workflows/docker-image-stable.yml @@ -0,0 +1,60 @@ +# This GitHub workflow will automatically update docker image tags of fs-depl in the datakaveri/iudx-deployment repository files +# for the 5.5.0 release branch when a docker image with tag 5.5.0 is pushed. + +name: Update FS docker image tags for release branch + +# Trigger the workflow when a new package is published to the registry +on: + registry_package: + types: [published] + +permissions: + packages: read + +jobs: + + update-release: + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v3 + with: + repository: datakaveri/iudx-deployment + token: "${{ secrets.JENKINS_UPDATE }}" + fetch-depth: 0 + + - name: Update FS docker image tags for release branch + env: + GH_TOKEN: ${{ secrets.JENKINS_UPDATE}} + run: | + # Get the latest version of 5.5.0 tags from the container registry using GitHub API + export newtag5_5_0=$(head -n1 <(curl -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/orgs/datakaveri/packages/container/fs-depl/versions | jq ' .[].metadata.container.tags[0]' | grep 5.5.0 | grep -v alpha | sed -e 's/^"//' -e 's/"$//')) + + # Get the old tag from the YAML file + export oldtag5_5_0=$(yq -r .services.file-server.image Docker-Swarm-deployment/single-node/file-server/file-server-stack.yaml | cut -d : -f 2) + + # Set Git user + git config --global user.name 'jenkins-datakaveri' + git config --global user.email "96175780+jenkins-datakaveri@users.noreply.github.com" + + if [ "$newtag5_5_0" != "$oldtag5_5_0" ]; then + git checkout 5.5.0 + git checkout -b fs-5.5.0-automatic-updates/$newtag5_5_0 + + # Update the YAML file with the new tag + sed -i s/$oldtag5_5_0/$newtag5_5_0/g Docker-Swarm-deployment/single-node/file-server/file-server-stack.yaml + + # Update application version in the Helm chart files + export oldappversion=$(yq -r .version K8s-deployment/Charts/file-server/Chart.yaml) + export newappversion=$(yq -r .version K8s-deployment/Charts/file-server/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/file-server/Chart.yaml + sed -i s/$oldtag5_5_0/$newtag5_5_0/g K8s-deployment/Charts/file-server/values.yaml + + git add Docker-Swarm-deployment/single-node/file-server/file-server-stack.yaml K8s-deployment/Charts/file-server/values.yaml K8s-deployment/Charts/file-server/Chart.yaml + git commit --allow-empty -m "updated FS docker image tag to $newtag5_5_0" + git push --set-upstream origin fs-5.5.0-automatic-updates/$newtag5_5_0 + + # Create 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 diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index d8e67f8..de5a06e 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,93 +1,60 @@ -# This github workflow will automatically update docker image tags of fs-depl in the datakaveri/iudx-deployment repository files, whenever docker image is pushed to ghcr.io/datakaveri/fs-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 FS docker image tags +# This GitHub workflow will automatically update docker image tags of fs-depl in the datakaveri/iudx-deployment repository files +# for the master/main branch when a docker image with tag 5.6.0-alpha is pushed. -# This trigger will run the workflow whenever a new package is published to the registry +name: Update FS docker image tags for master branch + +# Trigger the workflow when 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: + update-master: 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 + repository: datakaveri/iudx-deployment + token: "${{ secrets.JENKINS_UPDATE }}" + fetch-depth: 0 - # This step updates the FS Server docker image tags - - name: Update FS docker image tags - env: + - name: Update FS docker image tags for master/main branch + 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/fs-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/fs-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.file-server.image Docker-Swarm-deployment/single-node/file-server/file-server-stack.yaml | cut -d : -f 2` - git checkout 5.5.0 - export oldtag5_5_0=$(yq -r .services.file-server.image Docker-Swarm-deployment/single-node/file-server/file-server-stack.yaml | cut -d : -f 2) + run: | + # Get the latest version of 5.6.0-alpha tags from the container registry using GitHub API + export newtag5_6_0_alpha=$(head -n1 <(curl -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/orgs/datakaveri/packages/container/fs-depl/versions | jq ' .[].metadata.container.tags[0]' | grep 5.6.0-alpha | sed -e 's/^"//' -e 's/"$//')) + # Get the old tag from the YAML file + export oldtag5_6_0_alpha=$(yq -r .services.file-server.image Docker-Swarm-deployment/single-node/file-server/file-server-stack.yaml | cut -d : -f 2) + # Set Git user git config --global user.name 'jenkins-datakaveri' git config --global user.email "96175780+jenkins-datakaveri@users.noreply.github.com" + if [ "$newtag5_6_0_alpha" != "$oldtag5_6_0_alpha" ]; then + git checkout master + git checkout -b fs-automatic-updates/$newtag5_6_0_alpha - # Update the YAML files and create a new branch for each tag update - if [ "$newtag5_5_0" != "$oldtag5_5_0" ] - then - git checkout -b fs-5.5.0-automatic-updates/$newtag5_5_0 + # Update the YAML file with the new tag + sed -i s/$oldtag5_6_0_alpha/$newtag5_6_0_alpha/g Docker-Swarm-deployment/single-node/file-server/file-server-stack.yaml - # Uses sed to find and replace $oldtag5_5_0 with $newtag5_5_0 in Docker-Swarm-deployment/single-node/file-server/file-server-stack.yaml file - sed -i s/$oldtag5_5_0/$newtag5_5_0/g Docker-Swarm-deployment/single-node/file-server/file-server-stack.yaml + # Update application version in the Helm chart files + export oldappversion=$(yq -r .version K8s-deployment/Charts/file-server/Chart.yaml) + export newappversion=$(yq -r .version K8s-deployment/Charts/file-server/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}') - # Exports the current version of the application from K8s-deployment/Charts/file-server/Chart.yaml file - export oldappversion=`yq -r .version K8s-deployment/Charts/file-server/Chart.yaml` + sed -i s/$oldappversion/$newappversion/g K8s-deployment/Charts/file-server/Chart.yaml + sed -i s/$oldtag5_6_0_alpha/$newtag5_6_0_alpha/g K8s-deployment/Charts/file-server/values.yaml - # Uses awk to increment the version number in K8s-deployment/Charts/file-server/Chart.yaml file - export newappversion=`yq -r .version K8s-deployment/Charts/file-server/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/file-server/Chart.yaml and K8s-deployment/Charts/file-server/values.yaml files - sed -i s/$oldappversion/$newappversion/g K8s-deployment/Charts/file-server/Chart.yaml - sed -i s/$oldtag5_5_0/$newtag5_5_0/g K8s-deployment/Charts/file-server/values.yaml - git add Docker-Swarm-deployment/single-node/file-server/file-server-stack.yaml K8s-deployment/Charts/file-server/values.yaml K8s-deployment/Charts/file-server/Chart.yaml - git commit --allow-empty -m "updated FS docker image tag to $newtag5_5_0" - git push --set-upstream origin fs-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 fs-automatic-updates/$newtag5_5_1 + git add Docker-Swarm-deployment/single-node/file-server/file-server-stack.yaml K8s-deployment/Charts/file-server/values.yaml K8s-deployment/Charts/file-server/Chart.yaml + git commit --allow-empty -m "updated FS docker image tag to $newtag5_6_0_alpha" + git push --set-upstream origin fs-automatic-updates/$newtag5_6_0_alpha - # Uses sed to find and replace $oldtag5_5_1 with $newtag5_5_1 in Docker-Swarm-deployment/single-node/file-server/file-server-stack.yaml file - sed -i s/$oldtag5_5_1/$newtag5_5_1/g Docker-Swarm-deployment/single-node/file-server/file-server-stack.yaml - - # Exports the current version of the application from K8s-deployment/Charts/file-server/Chart.yaml file - export oldappversion=`yq -r .version K8s-deployment/Charts/file-server/Chart.yaml` - - # Uses awk to increment the version number in K8s-deployment/Charts/file-server/Chart.yaml file - export newappversion=`yq -r .version K8s-deployment/Charts/file-server/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/file-server/Chart.yaml and K8s-deployment/Charts/file-server/values.yaml files - sed -i s/$oldappversion/$newappversion/g K8s-deployment/Charts/file-server/Chart.yaml - sed -i s/$oldtag5_5_1/$newtag5_5_1/g K8s-deployment/Charts/file-server/values.yaml - git add Docker-Swarm-deployment/single-node/file-server/file-server-stack.yaml K8s-deployment/Charts/file-server/values.yaml K8s-deployment/Charts/file-server/Chart.yaml - git commit --allow-empty -m "updated FS docker image tag to $newtag5_5_1" - git push --set-upstream origin fs-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 + # Create 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 diff --git a/Jenkinsfile b/Jenkinsfile index c266af7..77bf79e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -142,8 +142,8 @@ pipeline { steps { script { docker.withRegistry( registryUri, registryCredential ) { - devImage.push("5.5.0-alpha-${env.GIT_HASH}") - deplImage.push("5.5.0-alpha-${env.GIT_HASH}") + devImage.push("5.6.0-alpha-${env.GIT_HASH}") + deplImage.push("5.6.0-alpha-${env.GIT_HASH}") } } } @@ -151,7 +151,7 @@ pipeline { stage('Docker Swarm deployment') { steps { script { - sh "ssh azureuser@docker-swarm 'docker service update file-server_file-server --image ghcr.io/datakaveri/fs-depl:5.5.0-alpha-${env.GIT_HASH}'" + sh "ssh azureuser@docker-swarm 'docker service update file-server_file-server --image ghcr.io/datakaveri/fs-depl:5.6.0-alpha-${env.GIT_HASH}'" sh 'sleep 20' } }