Skip to content

Commit

Permalink
Seperated docker image tag workflow file
Browse files Browse the repository at this point in the history
  • Loading branch information
sivanaikk committed Aug 9, 2024
1 parent d314514 commit 09022bd
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 73 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/docker-tag-stable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This GitHub workflow will automatically update docker image tags of rs-depl in the datakaveri/iudx-deployment repository files, whenever a docker image is pushed to ghcr.io/datakaveri/rs-depl for the release (5.5.0) branch.

name: Update RS docker image tags (Release 5.5.0)

# Trigger the workflow whenever a new package is published to the registry
on:
registry_package:
types: [published]

permissions:
packages: read

jobs:
build:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3
with:
repository: datakaveri/iudx-deployment
token: "${{ secrets.JENKINS_UPDATE }}"
fetch-depth: 0

# Update RS Server docker image tags for release branch 5.5.0
- name: Update RS docker image tags for release branch 5.5.0
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/rs-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.rs.image Docker-Swarm-deployment/single-node/resource-server/rs-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 the tag update
if [ "$newtag5_5_0" != "$oldtag5_5_0" ]
then
git checkout 5.5.0
git checkout -b rs-5.5.0-automatic-updates/$newtag5_5_0
# Replace old tag with new tag in the rs-stack.yaml file
sed -i s/$oldtag5_5_0/$newtag5_5_0/g Docker-Swarm-deployment/single-node/resource-server/rs-stack.yaml
# Update version in Chart.yaml and values.yaml
export oldappversion=$(yq -r .version K8s-deployment/Charts/resource-server/Chart.yaml)
export newappversion=$(yq -r .version K8s-deployment/Charts/resource-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/resource-server/Chart.yaml
sed -i s/$oldtag5_5_0/$newtag5_5_0/g K8s-deployment/Charts/resource-server/values.yaml
git add Docker-Swarm-deployment/single-node/resource-server/rs-stack.yaml K8s-deployment/Charts/resource-server/values.yaml K8s-deployment/Charts/resource-server/Chart.yaml
git commit --allow-empty -m "Updated RS docker image tag to $newtag5_5_0"
git push --set-upstream origin rs-5.5.0-automatic-updates/$newtag5_5_0
# Create a new pull request for the 5.5.0 branch
gh pr create -R datakaveri/iudx-deployment --base 5.5.0 --fill
fi
106 changes: 33 additions & 73 deletions .github/workflows/docker-tag.yml
Original file line number Diff line number Diff line change
@@ -1,101 +1,61 @@
# This github workflow will automatically update docker image tags of rs-depl in the datakaveri/iudx-deployment repository files, whenever docker image is pushed to ghcr.io/datakaveri/rs-depl .Based on tag it will update master/latest branch (if its 5.5.1-alpha-) or 5.5.0 stable branch (if its 5.5.0-)
# This GitHub workflow will automatically update docker image tags of rs-depl in the datakaveri/iudx-deployment repository files, whenever a docker image is pushed to ghcr.io/datakaveri/rs-depl for the master/main branch.

name: Update RS docker image tags
name: Update RS docker image tags (Master)

# This trigger will run the workflow whenever a new package is published to the registry
# Trigger 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 RS Server docker image tags
- name: Update RS docker image tags
env:
GH_TOKEN: ${{ secrets.JENKINS_UPDATE}}
run: |
repository: datakaveri/iudx-deployment
token: "${{ secrets.JENKINS_UPDATE }}"
fetch-depth: 0

# Update RS Server docker image tags for master/main branch
- name: Update RS docker image tags for master/main
env:
GH_TOKEN: ${{ secrets.JENKINS_UPDATE }}
run: |
# Get the latest version of 5.6.0-alpha tags from the container registry using GitHub API
export newtag5_6_0=$(head -n1 <(curl -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/orgs/datakaveri/packages/container/rs-depl/versions | jq ' .[].metadata.container.tags[0]' | grep 5.6.0-alpha | sed -e 's/^"//' -e 's/"$//'))
# 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/rs-depl/versions | jq ' .[].metadata.container.tags[0]' | grep 5.5.0 | grep -v alpha | sed -e 's/^"//' -e 's/"$//'))
export newtag5_5_1=`(head -n1 <(curl -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/orgs/datakaveri/packages/container/rs-depl/versions | jq ' .[].metadata.container.tags[0]' | grep 5.5.1 | sed -e 's/^"//' -e 's/"$//'))`
# Get the old tag from the YAML file
export oldtag5_6_0=$(yq -r .services.rs.image Docker-Swarm-deployment/single-node/resource-server/rs-stack.yaml | cut -d : -f 2)
# Get the old tags from the YAML files
export oldtag5_5_1=`yq -r .services.rs.image Docker-Swarm-deployment/single-node/resource-server/rs-stack.yaml | cut -d : -f 2`
git checkout 5.5.0
export oldtag5_5_0=$(yq -r .services.rs.image Docker-Swarm-deployment/single-node/resource-server/rs-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" ]
# Update the YAML files and create a new branch for the tag update
if [ "$newtag5_6_0" != "$oldtag5_6_0" ]
then
git checkout -b rs-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/resource-server/rs-stack.yaml file
sed -i s/$oldtag5_5_0/$newtag5_5_0/g Docker-Swarm-deployment/single-node/resource-server/rs-stack.yaml
# Exports the current version of the application from K8s-deployment/Charts/resource-server/Chart.yaml file
export oldappversion=`yq -r .version K8s-deployment/Charts/resource-server/Chart.yaml`
# Uses awk to increment the version number in K8s-deployment/Charts/resource-server/Chart.yaml file
export newappversion=`yq -r .version K8s-deployment/Charts/resource-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/resource-server/Chart.yaml and K8s-deployment/Charts/resource-server/values.yaml files
sed -i s/$oldappversion/$newappversion/g K8s-deployment/Charts/resource-server/Chart.yaml
sed -i s/$oldtag5_5_0/$newtag5_5_0/g K8s-deployment/Charts/resource-server/values.yaml
git add Docker-Swarm-deployment/single-node/resource-server/rs-stack.yaml K8s-deployment/Charts/resource-server/values.yaml K8s-deployment/Charts/resource-server/Chart.yaml
git commit --allow-empty -m "updated rs docker image tag to $newtag5_5_0"
git push --set-upstream origin rs-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 rs-automatic-updates/$newtag5_5_1
git checkout master
git checkout -b rs-5.6.0-alpha-automatic-updates/$newtag5_6_0
# Uses sed to find and replace $oldtag5_5_1 with $newtag5_5_1 in Docker-Swarm-deployment/single-node/resource-server/rs-stack.yaml file
sed -i s/$oldtag5_5_1/$newtag5_5_1/g Docker-Swarm-deployment/single-node/resource-server/rs-stack.yaml
# Exports the current version of the application from K8s-deployment/Charts/resource-server/Chart.yaml file
# Replace old tag with new tag in the rs-stack.yaml file
sed -i s/$oldtag5_6_0/$newtag5_6_0/g Docker-Swarm-deployment/single-node/resource-server/rs-stack.yaml
export oldappversion=`yq -r .version K8s-deployment/Charts/resource-server/Chart.yaml`
# Uses awk to increment the version number in K8s-deployment/Charts/resource-server/Chart.yaml file
export newappversion=`yq -r .version K8s-deployment/Charts/resource-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/resource-server/Chart.yaml and K8s-deployment/Charts/resource-server/values.yaml files
sed -i s/$oldappversion/$newappversion/g K8s-deployment/Charts/resource-server/Chart.yaml
sed -i s/$oldtag5_5_1/$newtag5_5_1/g K8s-deployment/Charts/resource-server/values.yaml
git add Docker-Swarm-deployment/single-node/resource-server/rs-stack.yaml K8s-deployment/Charts/resource-server/values.yaml K8s-deployment/Charts/resource-server/Chart.yaml
git commit --allow-empty -m "updated rs docker image tag to $newtag5_5_1"
git push --set-upstream origin rs-automatic-updates/$newtag5_5_1
# Update version in Chart.yaml and values.yaml
export oldappversion=$(yq -r .version K8s-deployment/Charts/resource-server/Chart.yaml)
export newappversion=$(yq -r .version K8s-deployment/Charts/resource-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}')
# Creates a new pull request on the datakaveri/iudx-deployment repository with the base branch master
sed -i s/$oldappversion/$newappversion/g K8s-deployment/Charts/resource-server/Chart.yaml
sed -i s/$oldtag5_6_0/$newtag5_6_0/g K8s-deployment/Charts/resource-server/values.yaml
git add Docker-Swarm-deployment/single-node/resource-server/rs-stack.yaml K8s-deployment/Charts/resource-server/values.yaml K8s-deployment/Charts/resource-server/Chart.yaml
git commit --allow-empty -m "Updated RS docker image tag to $newtag5_6_0"
git push --set-upstream origin rs-5.6.0-alpha-automatic-updates/$newtag5_6_0
gh pr create -R datakaveri/iudx-deployment --base master --fill
# Create a new pull request for the master branch
gh pr create -R datakaveri/iudx-deployment --base master --fill
fi

0 comments on commit 09022bd

Please sign in to comment.