-
Notifications
You must be signed in to change notification settings - Fork 1
353 lines (321 loc) · 14.8 KB
/
Processors_CI_CD_Workflow.yaml
File metadata and controls
353 lines (321 loc) · 14.8 KB
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
name: Processors_CI_CD_Workflow # Define the name of the workflow
# Define when the workflow should trigger
on:
workflow_dispatch:
inputs:
knowhow_common_branch:
description: 'Type the Branch to use from knowhow-common repo'
required: true
default: 'develop'
type: string
test:
description: 'Run tests'
required: true
default: 'true'
type: choice
options:
- "false"
- "true"
env:
description: 'Environment to deploy'
required: true
default: 'dev'
type: choice
options:
- dev
- dev1
- qa
- stage
processor:
description: 'Processor to build and deploy'
required: true
default: 'all'
type: choice
options:
- all
- jira
- azureboard
- azurepipelines
- devops
- rally-processor
- scm-processor
# Define environment variables
env:
JIRA_IMAGE_NAME: knowhow-jira-processor
DEVOPS_IMAGE_NAME: knowhow-devops-processor
AZUREBOARD_IMAGE_NAME: knowhow-azure-board-processor
AZUREPIPELINE_IMAGE_NAME: knowhow-azure-pipeline-repo
SCM_IMAGE_NAME: knowhow-scm-processor
ACR_NAME: ${{ secrets.SPEEDTOOLS_ACR_NAME }} # without .azurecr.io
ACR_LOGIN_SERVER: ${{ secrets.SPEEDTOOLS_ACR_LOGIN_SERVER }} # e.g. myacr.azurecr.io
BITBUCKET_HELM_REPO: ${{ secrets.SPEEDTOOLS_BITBUCKET_HELM_REPO }} # HTTPS clone URL (without creds)
GITHUB_HEAD_NAME: $GITHUB_HEAD_REF # Store the head branch name
sonartoken: ${{ secrets.SONARQUBE_TOKEN }} # Secret for SonarQube authentication
sonarurl: ${{ secrets.SONARURL }} # SonarQube URL stored in secrets
jobs:
# ✅ Building & Testing Processors
build:
runs-on: ubuntu-latest
timeout-minutes: 40
steps:
- name: Set IMAGE_TAG and values file
id: set_env
run: |
ENV="${{ github.event.inputs.env }}"
if [[ "$ENV" == "qa" ]]; then
echo "IMAGE_TAG=qa-${GITHUB_SHA::8}" >> $GITHUB_ENV
echo "VALUES_FILE=values-qa.yaml" >> $GITHUB_ENV
elif [[ "$ENV" == "stage" ]]; then
echo "IMAGE_TAG=master-${GITHUB_SHA::8}" >> $GITHUB_ENV
echo "VALUES_FILE=values-stage.yaml" >> $GITHUB_ENV
elif [[ "$ENV" == "dev1" ]]; then
echo "IMAGE_TAG=dev1-${GITHUB_SHA::8}" >> $GITHUB_ENV
echo "VALUES_FILE=values-dev1.yaml" >> $GITHUB_ENV
else
echo "IMAGE_TAG=dev-${GITHUB_SHA::8}" >> $GITHUB_ENV
echo "VALUES_FILE=values-dev.yaml" >> $GITHUB_ENV
fi
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set Up Java
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '17'
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Configure Maven to use GitHub Packages
run: |
mkdir -p ~/.m2
cat > ~/.m2/settings.xml <<EOF
<settings>
<servers>
<server>
<id>github</id>
<username>${{ github.actor }}</username>
<password>${{ secrets.MAVEN_TOKEN }}</password>
</server>
</servers>
<profiles>
<profile>
<id>github</id>
<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/PublicisSapient/knowhow-retro-notifications-lib</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>github</activeProfile>
</activeProfiles>
</settings>
EOF
- name: Clone & Build knowhow-common dependency
run: |
BRANCH_TO_CLONE="${{ github.event.inputs.knowhow_common_branch }}"
git clone --branch $BRANCH_TO_CLONE https://github.com/PublicisSapient/knowhow-common.git
cd knowhow-common
mvn clean install -Ddockerfile.skip=true
- name: Get common version using Maven Help Plugin
run: |
cd knowhow-common
COMMON_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "COMMON_VERSION=$COMMON_VERSION"
echo "COMMON_VERSION=$COMMON_VERSION" >> $GITHUB_ENV
- name: Updating the common version in processor project
run: |
mvn versions:use-dep-version \
-Dincludes=com.publicissapient.kpidashboard:common \
-DdepVersion=$COMMON_VERSION \
-DforceVersion=true
- name: Build & Skip Test Processor
if: ${{ github.event.inputs.test == 'false' }}
run: |
mvn clean install -Ddockerfile.skip=true -DskipTests
- name: Build & Test Processor
if: ${{ github.event.inputs.test == 'true' }}
run: |
mvn clean install -Ddockerfile.skip=true
- name: SonarQube Analysis - Processors
if: ${{ github.event.inputs.test == 'true' }}
run: |
mvn sonar:sonar -Dsonar.projectKey=ENGINEERING.KPIDASHBOARD.PROCESSORS \
-Dsonar.projectName=ENGINEERING.KPIDASHBOARD.PROCESSORS \
-Dsonar.branch.name=${{ env.GITHUB_HEAD_NAME }} \
-Dsonar.host.url=${{ secrets.SONARQUBE_HOST }} \
-Dsonar.login=${{ secrets.SONARQUBE_TOKEN }} -f pom.xml
- name: Check SonarQube Quality Gate
if: ${{ github.event.inputs.test == 'true' }}
run: |
chmod +x SonarQG.sh
./SonarQG.sh ./target/sonar/report-task.txt
- name: Build & Push Jira Docker Image
if: ${{ github.event.inputs.processor == 'all' || github.event.inputs.processor == 'jira' }}
run: |
docker login $ACR_LOGIN_SERVER --username ${{ secrets.SPEEDTOOLS_ACR_USERNAME }} --password ${{ secrets.SPEEDTOOLS_ACR_PASSWORD }}
docker build -t $ACR_LOGIN_SERVER/$JIRA_IMAGE_NAME:$IMAGE_TAG jira/.
docker push $ACR_LOGIN_SERVER/$JIRA_IMAGE_NAME:$IMAGE_TAG
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
- name: Build & Push DevOps Docker Image
if: ${{ github.event.inputs.processor == 'all' || github.event.inputs.processor == 'devops' }}
run: |
docker login $ACR_LOGIN_SERVER --username ${{ secrets.SPEEDTOOLS_ACR_USERNAME }} --password ${{ secrets.SPEEDTOOLS_ACR_PASSWORD }}
docker build -t $ACR_LOGIN_SERVER/$DEVOPS_IMAGE_NAME:$IMAGE_TAG -f devops-processor-startup/Dockerfile .
docker push $ACR_LOGIN_SERVER/$DEVOPS_IMAGE_NAME:$IMAGE_TAG
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
- name: Build & Push AzureBoard Docker Image
if: ${{ github.event.inputs.processor == 'all' || github.event.inputs.processor == 'azureboard' }}
run: |
docker login $ACR_LOGIN_SERVER --username ${{ secrets.SPEEDTOOLS_ACR_USERNAME }} --password ${{ secrets.SPEEDTOOLS_ACR_PASSWORD }}
docker build -t $ACR_LOGIN_SERVER/$AZUREBOARD_IMAGE_NAME:$IMAGE_TAG azure-boards/.
docker push $ACR_LOGIN_SERVER/$AZUREBOARD_IMAGE_NAME:$IMAGE_TAG
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
- name: Build & Push Azure Pipeline repo Docker Image
if: ${{ github.event.inputs.processor == 'all' || github.event.inputs.processor == 'azurepipelines' }}
run: |
docker login $ACR_LOGIN_SERVER --username ${{ secrets.SPEEDTOOLS_ACR_USERNAME }} --password ${{ secrets.SPEEDTOOLS_ACR_PASSWORD }}
docker build -t $ACR_LOGIN_SERVER/$AZUREPIPELINE_IMAGE_NAME:$IMAGE_TAG -f azure-pipeline-repo-processor-startup/Dockerfile .
docker push $ACR_LOGIN_SERVER/$AZUREPIPELINE_IMAGE_NAME:$IMAGE_TAG
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
- name: Build & Push SCM Processor Docker Image
if: ${{ github.event.inputs.processor == 'all' || github.event.inputs.processor == 'scm-processor' }}
run: |
docker login $ACR_LOGIN_SERVER --username ${{ secrets.SPEEDTOOLS_ACR_USERNAME }} --password ${{ secrets.SPEEDTOOLS_ACR_PASSWORD }}
docker build -t $ACR_LOGIN_SERVER/$SCM_IMAGE_NAME:$IMAGE_TAG .
docker push $ACR_LOGIN_SERVER/$SCM_IMAGE_NAME:$IMAGE_TAG
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
- name: Checkout jira Helm charts from Bitbucket
if: ${{ github.event.inputs.processor == 'all' || github.event.inputs.processor == 'jira' }}
run: |
git clone ${{ secrets.SPEEDTOOLS_BITBUCKET_HELM_REPO }}
cd build-configurations/KnowHOW-Deploy/knowhow-jira-processor
# Update values.yaml image tag
yq -i ".image.tag = \"${IMAGE_TAG}\"" $VALUES_FILE
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add $VALUES_FILE
git diff --cached --quiet || git commit -m "Update image tag values to ${IMAGE_TAG}"
git push origin HEAD
- name: Checkout devops Helm charts from Bitbucket
if: ${{ github.event.inputs.processor == 'all' || github.event.inputs.processor == 'devops' }}
run: |
git clone ${{ secrets.SPEEDTOOLS_BITBUCKET_HELM_REPO }}
cd build-configurations/KnowHOW-Deploy/devops-processor
# Update values.yaml image tag
yq -i ".image.tag = \"${IMAGE_TAG}\"" $VALUES_FILE
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add $VALUES_FILE
git diff --cached --quiet || git commit -m "Update image tag values to ${IMAGE_TAG}"
git push origin HEAD
- name: Checkout azure board Helm charts from Bitbucket
if: ${{ github.event.inputs.processor == 'all' || github.event.inputs.processor == 'azureboard' }}
run: |
git clone ${{ secrets.SPEEDTOOLS_BITBUCKET_HELM_REPO }}
cd build-configurations/KnowHOW-Deploy/knowhow-azure-board-processor
# Update values.yaml image tag
yq -i ".image.tag = \"${IMAGE_TAG}\"" $VALUES_FILE
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add $VALUES_FILE
git diff --cached --quiet || git commit -m "Update image tag values to ${IMAGE_TAG}"
git push origin HEAD
- name: Checkout azure Pipeline Helm charts from Bitbucket
if: ${{ github.event.inputs.processor == 'all' || github.event.inputs.processor == 'azurepipelines' }}
run: |
git clone ${{ secrets.SPEEDTOOLS_BITBUCKET_HELM_REPO }}
cd build-configurations/KnowHOW-Deploy/knowhow-azure-pipeline-repo
# Update values.yaml image tag
yq -i ".image.tag = \"${IMAGE_TAG}\"" $VALUES_FILE
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add $VALUES_FILE
git diff --cached --quiet || git commit -m "Update image tag values to ${IMAGE_TAG}"
git push origin HEAD
- name: Checkout scm Helm charts from Bitbucket
if: ${{ github.event.inputs.processor == 'all' || github.event.inputs.processor == 'scm-processor' }}
run: |
git clone ${{ secrets.SPEEDTOOLS_BITBUCKET_HELM_REPO }}
cd build-configurations/KnowHOW-Deploy/knowhow-scm-processor
# Update values.yaml image tag
yq -i ".image.tag = \"${IMAGE_TAG}\"" $VALUES_FILE
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add $VALUES_FILE
git diff --cached --quiet || git commit -m "Update image tag values to ${IMAGE_TAG}"
git push origin HEAD
argocd-setup:
runs-on: github-actions-self-hosted-runner
timeout-minutes: 30
needs: build
steps:
- name: Install ArgoCD CLI
run: |
export ARGO_PATH="$HOME/bin"
mkdir -p $ARGO_PATH
curl -sSL -o "$ARGO_PATH/argocd" https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
chmod +x "$ARGO_PATH/argocd"
echo "$ARGO_PATH" >> $GITHUB_PATH
- name: ArgoCD CLI Login
run: |
argocd login argocd-server \
--username ${{ secrets.SPEEDTOOLS_ARGOCD_USERNAME}} \
--password ${{ secrets.SPEEDTOOLS_ARGOCD_PASSWORD }} \
--plaintext
deploy-jira:
runs-on: github-actions-self-hosted-runner
timeout-minutes: 30
needs: [build, argocd-setup]
steps:
- name: Deploy Jira Processor
if: ${{ github.event.inputs.processor == 'all' || github.event.inputs.processor == 'jira' }}
run: |
argocd app sync knh-jira-processor-${{ github.event.inputs.env }}
argocd app wait knh-jira-processor-${{ github.event.inputs.env }} --health --timeout 300
deploy-az-board:
runs-on: github-actions-self-hosted-runner
timeout-minutes: 30
needs: [build, argocd-setup]
steps:
- name: Deploy Azure Board Processor
if: ${{ github.event.inputs.processor == 'all' || github.event.inputs.processor == 'azureboard' }}
run: |
argocd app sync knh-azure-board-${{ github.event.inputs.env }}
argocd app wait knh-azure-board-${{ github.event.inputs.env }} --health --timeout 300
deploy-az-pipeline:
runs-on: github-actions-self-hosted-runner
timeout-minutes: 30
needs: [build, argocd-setup]
steps:
- name: Deploy Azure Pipeline Processor
if: ${{ github.event.inputs.processor == 'all' || github.event.inputs.processor == 'azurepipelines' }}
run: |
argocd app sync knh-azure-pipeline-repo-${{ github.event.inputs.env }}
argocd app wait knh-azure-pipeline-repo-${{ github.event.inputs.env }} --health --timeout 300
deploy-scm-processor:
runs-on: github-actions-self-hosted-runner
timeout-minutes: 30
needs: [build, argocd-setup]
steps:
- name: Deploy SCM Processor
if: ${{ github.event.inputs.processor == 'all' || github.event.inputs.processor == 'scm-processor' }}
run: |
argocd app sync knh-scm-processor-${{ github.event.inputs.env }}
argocd app wait knh-scm-processor-${{ github.event.inputs.env }} --health --timeout 300
deploy-devops:
runs-on: github-actions-self-hosted-runner
timeout-minutes: 30
needs: [build, argocd-setup]
steps:
- name: Deploy DevOps Processor
if: ${{ github.event.inputs.processor == 'all' || github.event.inputs.processor == 'devops' }}
run: |
argocd app sync knh-devops-processor-${{ github.event.inputs.env }}
argocd app wait knh-devops-processor-${{ github.event.inputs.env }} --health --timeout 600