-
Notifications
You must be signed in to change notification settings - Fork 2
294 lines (280 loc) · 11.4 KB
/
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# Static Deploy On Openshift
# Builds and Deploys merged PR's to persistent pods/services/routes/etc in the OpenShift Dev environment.
name: Deploy on Openshift
on:
push:
branches:
- dev
- test
- prod
jobs:
#Print variables for logging and debugging purposes
checkEnv:
name: Check Env variables
runs-on: ubuntu-22.04
steps:
- name: Print Env Vars
run: |
echo Git Base Ref: ${{ github.base_ref }}
echo Git Build ID: ${{ github.event.number }}
echo Git Pull Request Ref: ${{ github.event.pull_request.head.sha }}
echo OC CLI Version: $(oc version)
echo Git Branch name: ${{ github.ref_name }}
#Build the app
build:
name: Build APP
runs-on: ubuntu-22.04
# if: ${{ github.event.pull_request.merged == true}}
if: github.ref_name == 'dev' || github.ref_name == 'test' || github.ref_name == 'prod'
env:
BUILD_ID: ${{ github.event.number }}
BUILD_NAMESPACE: 332842-tools
BRANCH: ${{ github.ref_name }}
BUILD_TAG: ${{ github.ref_name }}
APP: performance
steps:
# Checkout the PR branch
- name: Print env
run: |
echo BUILD ID: $BUILD_ID
echo BUILD NAMESPACE: $BUILD_NAMESPACE
echo BRANCH: $BRANCH
- name: Checkout Target Branch
uses: actions/checkout@v1
# Log in to OpenShift.
# Note: The secrets needed to log in are NOT available if the PR comes from a FORK.
# PR's must originate from a branch off the original repo or else all openshift `oc` commands will fail.
- name: Log in to OpenShift
run: |
oc login --token=${{ secrets.SA_TOKEN }} --server=https://api.silver.devops.gov.bc.ca:6443
# Build the app images
- name: Build App images
working-directory: "./openshift/app"
run: |
test -n "${BRANCH}"
test -n "${BUILD_NAMESPACE}"
echo "BUILIDING ${APP} with tag: ${BUILD_TAG}"
oc -n ${BUILD_NAMESPACE} process -f docker-build.yml \
-p TAG=${BUILD_TAG} -p SOURCE_REPOSITORY_REF=${BRANCH} \
-p BASE_IMAGE_NAME="php" -p BASE_IMAGE_TAG="8.0-apache" \
-p BASE_IMAGE_REPO="aro.jfrog.io/performance-app/" \
-p GITHUB_AUTH_TOKEN=${{secrets.AUTH_TOKEN}} \
-p SOURCE_CONTEXT_DIR=. \
-p NAME=${APP} | oc -n ${BUILD_NAMESPACE} apply -f -
oc -n ${BUILD_NAMESPACE} start-build bc/${APP} --no-cache --wait
# Deploy App images in Dev
deployDev:
name: Deploy APP to Dev environment
runs-on: ubuntu-22.04
if: github.ref_name == 'dev'
env:
BUILD_ID: ${{ github.event.number }}
NAMESPACE: 332842-dev
BUILD_NAMESPACE: 332842-tools
BRANCH: ${{ github.ref_name }}
APP: performance
APP_HOST: performance-332842-dev.apps.silver.devops.gov.bc.ca
DB_NAME: performance
needs:
- build
steps:
- name: Print env
run: |
echo BUILD ID: $BUILD_ID
echo BUILD NAMESPACE: $BUILD_NAMESPACE
echo BRANCH: $BRANCH
- name: Checkout Target Branch
uses: actions/checkout@v1
# Log in to OpenShift.
# Note: The secrets needed to log in are NOT available if the PR comes from a FORK.
# PR's must originate from a branch off the original repo or else all openshift `oc` commands will fail.
- name: Log in to OpenShift
run: |
oc login --token=${{ secrets.SA_TOKEN }} --server=https://api.silver.devops.gov.bc.ca:6443
- name: Deploy APP
run: |
test -n "${NAMESPACE}"
test -n "${BUILD_NAMESPACE}"
test -n "${BRANCH}"
echo "Current namespace is ${NAMESPACE}"
#oc -n ${BUILD_NAMESPACE} policy add-role-to-group system:image-puller system:serviceaccounts:${NAMESPACE}
oc -n ${NAMESPACE} process -f openshift/app/performance-dc.yml \
-p APP_NAME=${APP} \
-p SITE_URL=${APP_HOST} \
-p DB_HOST=mysql-0.mysql \
-p PERFORMANCE_MEMORY_LIMIT=4Gi \
-p REPLICA_COUNT=1 \
-p PROJECT_NAMESPACE=332842-dev \
-p DB_SERVICE_NAME=mysql-0.mysql \
-p PERFORMANCE_VOLUME_CAPACITY=10Gi \
-p DB_NAME=performance-db \
-p DB_USER=root\
-p HTTP_PORT=8000 \
-p DB_PORT=3306 \
-p SITE_NAME=Performance \
-p DB_PASSWORD="${{ secrets.DB_PASSWORD }}" \
-p GIT_PROJECT=performance \
-p BUILD_NAMESPACE="332842-tools" \
-p IMAGE_STREAM_TAG="performance:dev" \
-p GIT_URL="https://github.com/performance.git" \
-p GIT_TAG=openshift \
-p GITHUB_AUTH_TOKEN="${{ secrets.AUTH_TOKEN }}" | \
oc -n ${NAMESPACE} apply -f -
oc rollout latest dc/${APP} -n ${NAMESPACE}
# Check deployment rollout status every 10 seconds (max 10 minutes) until complete.
ATTEMPTS=0
ROLLOUT_STATUS_CMD="oc rollout status dc/${APP} -n ${NAMESPACE}"
until $ROLLOUT_STATUS_CMD || [ $ATTEMPTS -eq 60 ]; do
$ROLLOUT_STATUS_CMD
ATTEMPTS=$((attempts + 1))
sleep 10
done
oc project ${NAMESPACE}
echo "Listing pods.."
oc get pods|grep ${APP}
export ROUTE="$(oc get route ${APP} -o jsonpath='{.spec.host}')"
echo "${APP} is exposed at 'https://'${ROUTE}"
# Deploy App images in Test
deployTest:
name: Deploy APP to Test environment
runs-on: ubuntu-22.04
if: github.ref_name == 'test'
env:
BUILD_ID: ${{ github.event.number }}
NAMESPACE: 332842-test
BUILD_NAMESPACE: 332842-tools
BRANCH: ${{ github.ref_name }}
APP: performance
APP_HOST: performance-332842-test.apps.silver.devops.gov.bc.ca
DB_NAME: performance
needs:
- build
steps:
- name: Print env
run: |
echo BUILD ID: $BUILD_ID
echo BUILD NAMESPACE: $BUILD_NAMESPACE
echo BRANCH: $BRANCH
- name: Checkout Target Branch
uses: actions/checkout@v1
# Log in to OpenShift.
# Note: The secrets needed to log in are NOT available if the PR comes from a FORK.
# PR's must originate from a branch off the original repo or else all openshift `oc` commands will fail.
- name: Log in to OpenShift
run: |
oc login --token=${{ secrets.SA_TOKEN }} --server=https://api.silver.devops.gov.bc.ca:6443
- name: Deploy APP
run: |
test -n "${NAMESPACE}"
test -n "${BUILD_NAMESPACE}"
test -n "${BRANCH}"
echo "Current namespace is ${NAMESPACE}"
#oc -n ${BUILD_NAMESPACE} policy add-role-to-group system:image-puller system:serviceaccounts:${NAMESPACE}
oc -n ${NAMESPACE} process -f openshift/app/performance-dc.yml \
-p APP_NAME=${APP} \
-p SITE_URL=${APP_HOST} \
-p DB_HOST=mysql-0.mysql \
-p PERFORMANCE_MEMORY_LIMIT=4Gi \
-p REPLICA_COUNT=1 \
-p PROJECT_NAMESPACE=332842-test \
-p DB_SERVICE_NAME=mysql-0.mysql \
-p PERFORMANCE_VOLUME_CAPACITY=10Gi \
-p DB_NAME=performance-db \
-p DB_USER=root\
-p HTTP_PORT=8000 \
-p DB_PORT=3306 \
-p SITE_NAME=Performance \
-p DB_PASSWORD="${{ secrets.DB_PASSWORD }}" \
-p GIT_PROJECT=performance \
-p BUILD_NAMESPACE="332842-tools" \
-p IMAGE_STREAM_TAG="performance:test" \
-p GIT_URL="https://github.com/performance.git" \
-p GIT_TAG=openshift \
-p GITHUB_AUTH_TOKEN="${{ secrets.AUTH_TOKEN }}" | \
oc -n ${NAMESPACE} apply -f -
oc rollout latest dc/${APP} -n ${NAMESPACE}
# Check deployment rollout status every 10 seconds (max 10 minutes) until complete.
ATTEMPTS=0
ROLLOUT_STATUS_CMD="oc rollout status dc/${APP} -n ${NAMESPACE}"
until $ROLLOUT_STATUS_CMD || [ $ATTEMPTS -eq 60 ]; do
$ROLLOUT_STATUS_CMD
ATTEMPTS=$((attempts + 1))
sleep 10
done
oc project ${NAMESPACE}
echo "Listing pods.."
oc get pods|grep ${APP}
export ROUTE="$(oc get route ${APP} -o jsonpath='{.spec.host}')"
echo "${APP} is exposed at 'https://'${ROUTE}"
# Deploy App images in Prod
deployProd:
name: Deploy APP to Prod environment
runs-on: ubuntu-22.04
if: github.ref_name == 'prod'
env:
BUILD_ID: ${{ github.event.number }}
NAMESPACE: 332842-prod
BUILD_NAMESPACE: 332842-tools
BRANCH: ${{ github.ref_name }}
APP: performance
APP_HOST: performance.apps.silver.devops.gov.bc.ca
DB_NAME: performance
needs:
- build
steps:
- name: Print env
run: |
echo BUILD ID: $BUILD_ID
echo BUILD NAMESPACE: $BUILD_NAMESPACE
echo BRANCH: $BRANCH
- name: Checkout Target Branch
uses: actions/checkout@v1
# Log in to OpenShift.
# Note: The secrets needed to log in are NOT available if the PR comes from a FORK.
# PR's must originate from a branch off the original repo or else all openshift `oc` commands will fail.
- name: Log in to OpenShift
run: |
oc login --token=${{ secrets.SA_TOKEN }} --server=https://api.silver.devops.gov.bc.ca:6443
- name: Deploy APP
run: |
test -n "${NAMESPACE}"
test -n "${BUILD_NAMESPACE}"
test -n "${BRANCH}"
echo "Current namespace is ${NAMESPACE}"
#oc -n ${BUILD_NAMESPACE} policy add-role-to-group system:image-puller system:serviceaccounts:${NAMESPACE}
oc -n ${NAMESPACE} process -f openshift/app/performance-dc.yml \
-p APP_NAME=${APP} \
-p SITE_URL=${APP_HOST} \
-p DB_HOST=mysql-0.mysql \
-p PERFORMANCE_MEMORY_LIMIT=4Gi \
-p REPLICA_COUNT=2 \
-p PROJECT_NAMESPACE=332842-prod \
-p DB_SERVICE_NAME=mysql-0.mysql \
-p PERFORMANCE_VOLUME_CAPACITY=10Gi \
-p DB_NAME=performance-db \
-p DB_USER=root\
-p HTTP_PORT=8000 \
-p DB_PORT=3306 \
-p SITE_NAME=Performance \
-p DB_PASSWORD="${{ secrets.DB_PASSWORD }}" \
-p GIT_PROJECT=performance \
-p BUILD_NAMESPACE="332842-tools" \
-p IMAGE_STREAM_TAG="performance:prod" \
-p GIT_URL="https://github.com/performance.git" \
-p GIT_TAG=openshift \
-p GITHUB_AUTH_TOKEN="${{ secrets.AUTH_TOKEN }}" | \
oc -n ${NAMESPACE} apply -f -
#oc rollout latest dc/${APP} -n ${NAMESPACE}
# Check deployment rollout status every 10 seconds (max 10 minutes) until complete.
ATTEMPTS=0
ROLLOUT_STATUS_CMD="oc rollout status dc/${APP} -n ${NAMESPACE}"
until $ROLLOUT_STATUS_CMD || [ $ATTEMPTS -eq 60 ]; do
$ROLLOUT_STATUS_CMD
ATTEMPTS=$((attempts + 1))
sleep 10
done
oc project ${NAMESPACE}
echo "Listing pods.."
oc get pods|grep ${APP}
export ROUTE="$(oc get route ${APP} -o jsonpath='{.spec.host}')"
echo "${APP} is exposed at 'https://'${ROUTE}"