-
Notifications
You must be signed in to change notification settings - Fork 43
143 lines (126 loc) · 4.82 KB
/
DEV-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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# GitHub Actions workflow for deploying API image on PR merge to main branch
name: EXPRESS API-DEV Deploy
on:
pull_request:
types:
- closed
branches: [main]
paths:
- 'express-api/**' # Triggers on changes to files in the express-api/ directory.
workflow_dispatch:
inputs:
image_tag:
description: 'Image Tag to deploy'
required: true
env:
IMAGE_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.image_tag || github.event.pull_request.number }}
jobs:
# Job to deploy API image to OpenShift
Deploy-To-OpenShift:
if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged }}
name: Deploy to OpenShift
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Login to OpenShift
uses: redhat-actions/oc-login@v1
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }}
openshift_token: ${{ secrets.OPENSHIFT_SA_DEV_TOKEN }}
namespace: ${{ secrets.OPENSHIFT_DEV_NAMESPACE }}
# Process and Apply API DeploymentConfig
- name: Process and Apply API DeploymentConfig
env:
NAMESPACE: '${{ secrets.OPENSHIFT_DEV_NAMESPACE }}'
DC_TEMPLATE: 'api-v2-dc-template.yaml'
IMAGE_TAG: ${{ env.IMAGE_TAG }}
ENVIRONMENT: 'dev'
APPLICATION_NAME: 'pims-api-v2'
LICENSE_PLATE: '${{ secrets.LICENSE_PLATE }}'
run: |
./.github/helpers/deploy.sh
# Job to check the health of the deployed API
Health-Check:
name: Check Deployment Health
runs-on: ubuntu-latest
needs: [Deploy-To-OpenShift]
steps:
# Login to OpenShift
- name: Login to OpenShift
uses: redhat-actions/oc-login@v1
env:
OPENSHIFT_USER: github-actions
OPENSHIFT_PROJECT: ${{ secrets.OPENSHIFT_DEV_NAMESPACE }}
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }}
openshift_token: ${{ secrets.OPENSHIFT_SA_DEV_TOKEN }}
namespace: ${{ secrets.OPENSHIFT_DEV_NAMESPACE }}
# Check Deployment Status
- name: Check Deployment Status
run: |
oc rollout status -n ${{ secrets.OPENSHIFT_DEV_NAMESPACE }} dc/pims-api-v2 --watch
# Job to clean up previous objects in OpenShift
Clean-Up:
name: Clean Up
runs-on: ubuntu-latest
needs: [Health-Check]
steps:
# Login to OpenShift
- name: Login to OpenShift
uses: redhat-actions/oc-login@v1
env:
OPENSHIFT_USER: github-actions
OPENSHIFT_PROJECT: ${{ secrets.OPENSHIFT_DEV_NAMESPACE }}
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }}
openshift_token: ${{ secrets.OPENSHIFT_SA_DEV_TOKEN }}
namespace: ${{ secrets.OPENSHIFT_DEV_NAMESPACE }}
# Remove previous objects
- name: Remove previous objects
run: |
oc delete pod -n ${{ secrets.OPENSHIFT_DEV_NAMESPACE }} --field-selector status.phase=Succeeded
# Remove previous replication controllers
- name: Remove previous replication controllers
run: |
oc delete rc -n ${{ secrets.OPENSHIFT_DEV_NAMESPACE }} --field-selector status.replicas=0
# Job to update the wiki with deployed image tag information
Update_Wiki_Tags:
needs: [Health-Check, 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:[email protected]/$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 DEV" "${{ 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 "[email protected]"
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:[email protected]/$GITHUB_REPOSITORY.wiki.git"