-
Notifications
You must be signed in to change notification settings - Fork 43
109 lines (93 loc) · 3.47 KB
/
TEST-Api-V2-image-deploy.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# GitHub Actions workflow for deploying API image to TEST env
name: EXPRESS API-TEST Deploy
on:
workflow_dispatch:
inputs:
image_tag:
description: 'Image Tag to deploy'
required: true
env:
IMAGE_TAG: ${{ github.event.inputs.image_tag }}
ENVIRONMENT: 'test'
OPENSHIFT_TOKEN: ${{ secrets.OPENSHIFT_SA_TEST_TOKEN }}
jobs:
# Job to deploy API image to OpenShift
Deploy-To-OpenShift:
name: Deploy to OpenShift
runs-on: ubuntu-latest
steps:
# Install yaml Parser
- name: Install yaml Parser (yq)
run: |
curl -Lo yq "https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64"
chmod +x yq
mv yq /home/runner/bin
# Add deploy key to runner
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.MANIFEST_REPO_DEPLOY_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
# Make changes to image tag in values.yaml within GitOps repo
- name: Clone, Update, and Commit Changes
run: |
git clone git@github.com:bcgov-c/tenant-gitops-354028.git
cd tenant-gitops-354028
FILE_PATH="pims-v2/values-test.yaml"
NEW_TAG="${{ env.IMAGE_TAG }}"
yq e ".backend.image.tag = \"$NEW_TAG\"" -i "$FILE_PATH"
git config user.email "manish.sihag@gov.bc.ca"
git config user.name "ManishSihag"
git pull origin main
git add "$FILE_PATH"
git commit -m "Update backend image tag to $NEW_TAG"
# Retry push with rebase to handle conflicts from simultaneous frontend/backend updates
RETRY_COUNT=2
RETRY_DELAY=15
for ((i=0; i<=$RETRY_COUNT; i++)); do
git push && break || {
echo "Push failed. Retrying in $RETRY_DELAY seconds..."
sleep $RETRY_DELAY
git pull --rebase origin main
git add "$FILE_PATH"
git commit --amend --no-edit
}
done
# Job to update the wiki with deployed image tag information
Update_Wiki_Tags:
needs: [ Deploy-To-OpenShift]
name: Update table in wiki
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
steps:
# Checkout the repository
- name: Checkout
uses: actions/checkout@v3
# Clone wiki repository
- name: Clone wiki repository
run: |
echo "Cloning wiki repo https://github.com/$GITHUB_REPOSITORY.wiki.git"
git clone "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$GITHUB_REPOSITORY.wiki.git" ./wiki
# Setup Python
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
# Run update wiki python script
- name: Run update wiki python script
run: python ./.github/helpers/update-wiki-table.py ./wiki/Image-tags.md "API V2" "Deployed Image Tag in TEST" "${{ env.IMAGE_TAG }}"
# Commit and push changes to wiki
- name: Commit and push changes to wiki
run: |
cd ./wiki
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
git add .
if git diff-index --quiet HEAD; then
echo "Nothing changed"
exit 0
fi
echo "Pushing changes to wiki"
git commit -m "Value populated at Deploy API" && git push "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$GITHUB_REPOSITORY.wiki.git"