-
Notifications
You must be signed in to change notification settings - Fork 8
94 lines (72 loc) · 5.97 KB
/
docker-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# This github workflow will automatically update docker image tags of acl-apd-depl in the datakaveri/iudx-deployment repository files, whenever docker image is pushed to ghcr.io/datakaveri/acl-apd-depl .Based on tag it will update the master/latest branch (if its 1.0.2-alpha-) or 1.0.1 stable branch (if its 1.0.1-)
name: Update ACL APD 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 ACL APDServer docker image tags
- name: Update ACL APDdocker image tags
env:
GH_TOKEN: ${{ secrets.JENKINS_UPDATE}}
run: |
# Get the latest version of 1.0.1 and 1.0.2-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/acl-apd-depl/versions | jq ' .[].metadata.container.tags[0]' | grep 1.0.1 | grep -v alpha | sed -e 's/^"//' -e 's/"$//'))`
export newtag1_0_2=`(head -n 1 <(curl -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/orgs/datakaveri/packages/container/acl-apd-depl/versions | jq ' .[].metadata.container.tags[0]' | grep 1.0.2-alpha | sed -e 's/^"//' -e 's/"$//'))`
# Get the old tags from the YAML files
export oldtag1_0_2=`yq -r .services.acl-apd.image Docker-Swarm-deployment/single-node/acl-apd/acl-apd-stack.yaml | cut -d : -f 2`
git checkout 1.0.1
export oldtag1_0_1=$(yq -r .services.acl-apd.image Docker-Swarm-deployment/single-node/acl-apd/acl-apd-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 [ "$newtag1_0_1" != "$oldtag1_0_1" ]
then
git checkout -b cat-1.0.1-automatic-updates/$newtag1_0_1
# Uses sed to find and replace $oldtag1_0_1 with $newtag1_0_1 in Docker-Swarm-deployment/single-node/acl-apd/acl-apd-stack.yaml file
sed -i s/$oldtag1_0_1/$newtag1_0_1/g Docker-Swarm-deployment/single-node/acl-apd/acl-apd-stack.yaml
# Exports the current version of the application from K8s-deployment/Charts/acl-apd/Chart.yaml file
export oldappversion=`yq -r .version K8s-deployment/Charts/acl-apd/Chart.yaml`
# Uses awk to increment the version number in K8s-deployment/Charts/acl-apd/Chart.yaml file
export newappversion=`yq -r .version K8s-deployment/Charts/acl-apd/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/acl-apd/Chart.yaml and K8s-deployment/Charts/acl-apd/values.yaml files
sed -i s/$oldappversion/$newappversion/g K8s-deployment/Charts/acl-apd/Chart.yaml
sed -i s/$oldtag1_0_1/$newtag1_0_1/g K8s-deployment/Charts/acl-apd/values.yaml
git add Docker-Swarm-deployment/single-node/acl-apd/acl-apd-stack.yaml K8s-deployment/Charts/acl-apd/values.yaml K8s-deployment/Charts/acl-apd/Chart.yaml
git commit --allow-empty -m "updated ACL APD docker image tag to $newtag1_0_1"
git push --set-upstream origin cat-1.0.1-automatic-updates/$newtag1_0_1
# Creates a new pull request on the datakaveri/iudx-deployment repository with the base branch 1.0.1
gh pr create -R datakaveri/iudx-deployment --base 1.0.1 --fill
fi
if [ "$newtag1_0_2" != "$oldtag1_0_2" ]
then
git checkout master
git checkout -b cat-automatic-updates/$newtag1_0_2
# Uses sed to find and replace $oldtag1_0_2 with $newtag1_0_2 in Docker-Swarm-deployment/single-node/acl-apd/acl-apd-stack.yaml file
sed -i s/$oldtag1_0_2/$newtag1_0_2/g Docker-Swarm-deployment/single-node/acl-apd/acl-apd-stack.yaml
# Exports the current version of the application from K8s-deployment/Charts/acl-apd/Chart.yaml file
export oldappversion=`yq -r .version K8s-deployment/Charts/acl-apd/Chart.yaml`
# Uses awk to increment the version number in K8s-deployment/Charts/acl-apd/Chart.yaml file
export newappversion=`yq -r .version K8s-deployment/Charts/acl-apd/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/acl-apd/Chart.yaml and K8s-deployment/Charts/acl-apd/values.yaml files
sed -i s/$oldappversion/$newappversion/g K8s-deployment/Charts/acl-apd/Chart.yaml
sed -i s/$oldtag1_0_2/$newtag1_0_2/g K8s-deployment/Charts/acl-apd/values.yaml
git add Docker-Swarm-deployment/single-node/acl-apd/acl-apd-stack.yaml K8s-deployment/Charts/acl-apd/values.yaml K8s-deployment/Charts/acl-apd/Chart.yaml
git commit --allow-empty -m "updated ACL APDdocker image tag to $newtag1_0_2"
git push --set-upstream origin cat-automatic-updates/$newtag1_0_2
# 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