Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added docker tag workflow files #175

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/docker-image-stable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This GitHub workflow will automatically update docker image tags of geo server in the datakaveri/iudx-deployment repository files,
# whenever a docker image is pushed to ghcr.io/datakaveri/ogc-resource-server. Based on the tag, it will update the 1.0.0 stable branch (if it's 1.0.0-).
name: Update geo server docker image tags on release branch

# 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:
update-release:
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 geo server docker image tags for the release branch
- name: Update geo server docker image tags for release branch
env:
GH_TOKEN: ${{ secrets.JENKINS_UPDATE}}
run: |
# Get the latest version of 1.0.0 tags from the container registry using GitHub API
export newtag1_0_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/ogc-resource-server/versions | jq ' .[].metadata.container.tags[0]' | grep 1.0.0 | grep -v alpha | sed -e 's/^"//' -e 's/"$//'))`

# Get the old tags from the YAML files
export oldtag1_0_0=`yq -r .services.ogc-rs.image Docker-Swarm-deployment/single-node/ogc-rs/ogc-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 [ "$newtag1_0_0" != "$oldtag1_0_0" ]
then
git checkout 1.0.0
git checkout -b geo-server-1.0.0-automatic-updates/$newtag1_0_0

# Uses sed to find and replace $oldtag1_0_0 with $newtag1_0_0 in Docker-Swarm-deployment/single-node/ogc-rs/ogc-rs-stack.yaml file
sed -i s/$oldtag1_0_0/$newtag1_0_0/g Docker-Swarm-deployment/single-node/ogc-rs/ogc-rs-stack.yaml

# Exports the current version of the application from K8s-deployment/Charts/geo-server/Chart.yaml file
export oldappversion=`yq -r .version K8s-deployment/Charts/geo-server/Chart.yaml`

# Uses awk to increment the version number in K8s-deployment/Charts/geo-server/Chart.yaml file
export newappversion=`yq -r .version K8s-deployment/Charts/geo-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/geo-server/Chart.yaml and K8s-deployment/Charts/geo-server/values.yaml files
sed -i s/$oldappversion/$newappversion/g K8s-deployment/Charts/geo-server/Chart.yaml
sed -i s/$oldtag1_0_0/$newtag1_0_0/g K8s-deployment/Charts/geo-server/values.yaml
git add Docker-Swarm-deployment/single-node/ogc-rs/ogc-rs-stack.yaml K8s-deployment/Charts/geo-server/values.yaml K8s-deployment/Charts/geo-server/Chart.yaml
git commit --allow-empty -m "updated geo server docker image tag to $newtag1_0_0"
git push --set-upstream origin geo-server-1.0.0-automatic-updates/$newtag1_0_0

# Creates a new pull request on the datakaveri/iudx-deployment repository with the base branch 1.0.0
gh pr create -R datakaveri/iudx-deployment --base 1.0.0 --fill
fi
66 changes: 66 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# This github workflow will automatically update docker image tags of geo server in the datakaveri/iudx-deployment repository files, whenever docker image is pushed to ghcr.io/datakaveri/ogc-resource-server .Based on tag it will update the master/latest branch (if its 1.0.1-alpha-)
name: Update geo server 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 geo server docker image tags for the master/main branch
- name: Update geo server docker image tags for master/main
env:
GH_TOKEN: ${{ secrets.JENKINS_UPDATE}}
run: |
# Get the latest version of 1.0.1-alpha tags from the container registry using GitHub API
export newtag1_0_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/ogc-resource-server/versions | jq ' .[].metadata.container.tags[0]' | grep 1.0.1-alpha | sed -e 's/^"//' -e 's/"$//'))`

# Get the old tags from the YAML files
export oldtag1_0_1=`yq -r .services.ogc-rs.image Docker-Swarm-deployment/single-node/ogc-rs/ogc-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 [ "$newtag1_0_1" != "$oldtag1_0_1" ]
then
git checkout master
git checkout -b geo-server-automatic-updates/$newtag1_0_1

# Uses sed to find and replace $oldtag1_0_1 with $newtag1_0_1 in Docker-Swarm-deployment/single-node/ogc-rs/ogc-rs-stack.yaml file
sed -i s/$oldtag1_0_1/$newtag1_0_1/g Docker-Swarm-deployment/single-node/ogc-rs/ogc-rs-stack.yaml

# Exports the current version of the application from K8s-deployment/Charts/geo-server/Chart.yaml file
export oldappversion=`yq -r .version K8s-deployment/Charts/geo-server/Chart.yaml`

# Uses awk to increment the version number in K8s-deployment/Charts/geo-server/Chart.yaml file
export newappversion=`yq -r .version K8s-deployment/Charts/geo-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/geo-server/Chart.yaml and K8s-deployment/Charts/geo-server/values.yaml files
sed -i s/$oldappversion/$newappversion/g K8s-deployment/Charts/geo-server/Chart.yaml
sed -i s/$oldtag1_0_1/$newtag1_0_1/g K8s-deployment/Charts/geo-server/values.yaml
git add Docker-Swarm-deployment/single-node/ogc-rs/ogc-rs-stack.yaml K8s-deployment/Charts/geo-server/values.yaml K8s-deployment/Charts/geo-server/Chart.yaml
git commit --allow-empty -m "updated geo server docker image tag to $newtag1_0_1"
git push --set-upstream origin geo-server-automatic-updates/$newtag1_0_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