-
Notifications
You must be signed in to change notification settings - Fork 1
269 lines (243 loc) · 9.03 KB
/
maven.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
name: Java CI with Maven
on: [push]
# branches:
# - '*'
#[ master ]
# pull_request:
# branches: [ master ]
# repository_dispatch:
# types: [invoke_build_deploy]
#deployment: development
jobs:
secret-scan:
name: Repo Secret Scan
#runs-on: [self-hosted, 'Windows', 'X64']
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v2
- uses: max/secret-scan@master
analyze:
name: Analyze Source Code
#runs-on: ['self-hosted', 'Windows', 'X64']
runs-on: ubuntu-latest
needs: [secret-scan]
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Initializes the CodeQL tools for scanning.
# - name: Initialize CodeQL
# uses: github/codeql-action/init@v1
# with:
# languages: javascript
# - name: Perform CodeQL Analysis
# uses: github/codeql-action/analyze@v1
analyze_dockerfile:
name: Analyze Dockerfile
runs-on: ubuntu-latest
needs: [secret-scan]
continue-on-error: true
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Dockerfile validation - Docker Hadolint Linter
run: docker run --rm -i hadolint/hadolint < sm-shop/Dockerfile
build:
name: Build Code
runs-on: ubuntu-latest
needs: [secret-scan, analyze, analyze_dockerfile]
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Cache the Maven packages to speed up build
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build with Maven
#run: mvn -B package --file pom.xml
run: mvn -B clean verify --file pom.xml
#- run: ls -lart ${GITHUB_WORKSPACE}/sm-shop/target
- run: ls -lart ${GITHUB_WORKSPACE}/sm-shop/target/site
- run: ls -lart ${GITHUB_WORKSPACE}/sm-shop/target/site/jacoco
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOVE_TOKEN }}
files: ./sm-shop/target/site/jacoco/jacoco.xml
#directory: ${GITHUB_WORKSPACE}/sm-shop/target/site/jacoco/
flags: unittests
#env_vars: OS,PYTHON
name: codecov-umbrella
fail_ci_if_error: true
#path_to_write_report: ./coverage/codecov_report.txt
verbose: true
publish-job:
name: Package Code as war
runs-on: ubuntu-latest
#defaults:
# #run:
# #shell: bash
# #working-directory: build
needs: [secret-scan, analyze, analyze_dockerfile, build]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: 1.8
- uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
#- run: pwd
#- run: ls -lart
#- run: mvn -B package --file /build/pom.xml -DskipTests
- run: mvn -B package --file ${GITHUB_WORKSPACE}/pom.xml -DskipTests
- run: mkdir staging && cp ${GITHUB_WORKSPACE}/sm-shop/target/*.war staging
- uses: actions/upload-artifact@v1
with:
name: Shopizer-Package
path: staging
containerize_n_push_to_registry:
name: Build Docker image and push to GitHub Container Registry
runs-on: ubuntu-latest
needs: [secret-scan, analyze, analyze_dockerfile, build, publish-job]
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Download built artifact
#uses: actions/download-artifact@master
uses: actions/download-artifact@v1
with:
name: Shopizer-Package
#path: staging
- name: Move the artifact to target
run: |
pwd
ls -lart
mkdir -p ${GITHUB_WORKSPACE}/sm-shop/target
mv ${GITHUB_WORKSPACE}/Shopizer-Package/ROOT.war ${GITHUB_WORKSPACE}/sm-shop/target
# # docker build -t de.rieckpil.blog/github-actions-sample github-actions-java-maven
- name: Push to GitHub Packages
uses: docker/build-push-action@v1
with:
username: ${{ secrets.CR_Username }}
password: ${{ secrets.CR_Password }}
registry: ghcr.io
#repository: githubteamuser2/shopizer
repository: githubdevopsdemo/githubteamuser2/shopizer
#tags: ${{ github.sha }}
tags: latest
path: sm-shop/
#dockerfile: Dockerfile
file: sm-shop/Dockerfile
scan-image:
name: Scan Docker Image
runs-on: ubuntu-latest
needs: [secret-scan, analyze, analyze_dockerfile, build, publish-job, containerize_n_push_to_registry]
steps:
- name: Login to Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.CR_Username }}
password: ${{ secrets.CR_Password }}
- name: Scan Docker Image
uses: anchore/scan-action@v2
id: scan
with:
image: "ghcr.io/githubdevopsdemo/githubteamuser2/shopizer:latest"
acs-report-enable: true
fail-build: false
- name: upload Anchore scan SARIF report
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
- name: Inspect SARIF Report
run: cat ${{ steps.scan.outputs.sarif }}
# Provision-env:
# name: Provision QA Environment
# runs-on: ubuntu-latest
# needs: [secret-scan, analyze, analyze_dockerfile, build, publish-job, containerize_n_push_to_registry, scan-image]
# steps:
# - name: Provision QA Environment
# uses: actions/checkout@v2
Deploy:
name: Deploy shopizer image to AKS cluster dev namespace
runs-on: ubuntu-latest
needs: [secret-scan, analyze, analyze_dockerfile, build, publish-job, containerize_n_push_to_registry, scan-image] #, Provision-env]
steps:
- name: Check out the repo
uses: actions/checkout@v2
# Set the target AKS cluster.
- uses: Azure/aks-set-context@v1
with:
creds: '${{ secrets.AZURE_CREDENTIALS }}'
#updated with API-Demo RG from Kushal's account
#Updated the AKS cluster with JK's account
#Updated the AKS with Singha's account
#cluster-name: github_shopizer
#resource-group: RG_Shopizer_AKS
#cluster-name: shopizer #shopizer_ondemand_k8scluster #shopizer
#resource-group: ShopizerOnDemandCluster #rg_shopizer_ondemand_k8scluster
#Cluster from pravin's account
cluster-name: apidemocluster #shopizer #shopizer_ondemand_k8scluster #shopizer
resource-group: API-Demo #RG_Shopizer #rg_shopizer_ondemand_k8scluster
# Set the image secret
- uses: Azure/k8s-create-secret@v1
with:
container-registry-url: ghcr.io
container-registry-username: ${{ secrets.CR_Username }}
container-registry-password: ${{ secrets.CR_Password }}
secret-name: k8s-secret
namespace: dev
# Deploy
- uses: Azure/k8s-deploy@v1
with:
manifests: |
shopizer.yaml
shopizer-service.yaml
images: |
ghcr.io/githubdevopsdemo/githubteamuser2/shopizer:latest
imagepullsecrets: |
k8s-secret
namespace: dev
#DAST:
#name: Perform DAST scan
#runs-on: ubuntu-latest
#needs: [secret-scan, analyze, analyze_dockerfile, build, publish-job, containerize_n_push_to_registry, scan-image, Deploy]
#steps:
#- name: ZAP Scan
#uses: zaproxy/[email protected]
#with:
#target: 'https://www.zaproxy.org/'
Run-Test-Automation:
name: Run Test Automation
runs-on: ubuntu-latest
needs: [Deploy]
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v1
with:
#token: ${{ secrets.TEST_ACCESS_TOKEN }}
token: ${{ secrets.ACCESS_TOKEN }}
repository: "GitHubDevOpsDemo/cima-integration-test"
event-type: invoke_test
Run-Performance:
name: Invoke Performance Test
runs-on: ubuntu-latest
# #needs: [secret-scan, analyze, analyze_dockerfile, build, publish-job, containerize_n_push_to_registry, scan-image, Provision-env, Deploy, Run-Test-Automation]
needs: [Run-Test-Automation]
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v1
with:
#token: ${{ secrets.TEST_ACCESS_TOKEN }}
token: ${{ secrets.PERF_TEST_ACCESS_TOKEN }}
repository: "GitHubDevOpsDemo/perfTest"
event-type: invoke_perftest