-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathazure-pipelines-e2e.yml
More file actions
229 lines (203 loc) · 8.75 KB
/
azure-pipelines-e2e.yml
File metadata and controls
229 lines (203 loc) · 8.75 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
name: snomio-e2e-$(Date:yyyyMMdd)$(Rev:.r)_$(Build.SourceBranchName)
trigger: none
variables:
mavenCache: $(Pipeline.Workspace)/.m2/repository
mavenOptions: '-Dmaven.repo.local=$(mavenCache) -Dmaven.settings.security=never'
# resources:
# repositories:
# - repository: sergio
# type: github
# name: aehrc/sergio
# endpoint: aehrc
# ref: rabbit-snomio-image-as-cli-entity-refactor
pool:
vmImage: ubuntu-latest
jobs:
- job: set_image_tag
displayName: Set Image Tag
steps:
- script: |
if [[ "$(Build.SourceBranch)" =~ refs/heads/(.+) ]]; then
# Direct branch build
postfix=""
elif [[ "$(Build.SourceBranch)" =~ refs/pull/[0-9]+/merge ]]; then
postfix="_${SYSTEM_PULLREQUEST_SOURCEBRANCH#refs/heads/}"
elif [[ "$(Build.SourceBranch)" =~ refs/tags/(.+) ]]; then
postfix="_${BASH_REMATCH[1]}"
else
postfix="_unknown"
fi
imageTag="$(Build.BuildNumber)$postfix"
imageTag=${imageTag//\//-}
imageTag=${imageTag//#/}
echo "##vso[task.setvariable variable=imageTag]$imageTag"
echo "$imageTag" > branchInfo.txt
displayName: 'Set Image Tag and Save to File'
- task: CopyFiles@2
displayName: 'Copy branchInfo.txt to Artifacts Dir'
inputs:
contents: 'branchInfo.txt'
targetFolder: '$(Build.ArtifactStagingDirectory)'
- publish: $(Build.ArtifactStagingDirectory)
displayName: Publish branchInfo.txt
artifact: branchInfo
- job: snomio_build
dependsOn: set_image_tag
displayName: Build, run integration test and publish
timeoutInMinutes: 60
steps:
- download: current
artifact: branchInfo
- script: |
imageTag=$(cat $(Pipeline.Workspace)/branchInfo/branchInfo.txt)
if [[ -z "$imageTag" || "$imageTag" == *unknown* ]]; then
echo "Invalid imageTag: $imageTag"
exit 1
fi
echo "##vso[task.setvariable variable=buildInfo]$imageTag"
if [ "$(Build.SourceBranch)" = "refs/heads/main" ]; then
imageTag="$imageTag,latest"
fi
echo "##vso[task.setvariable variable=imageTag]$imageTag"
echo "Using imageTag: $imageTag"
displayName: 'Read imageTag from branchInfo.txt'
- task: MavenAuthenticate@0
inputs:
artifactsFeeds: 'snomio'
- task: Docker@2
displayName: 'Login to ACR'
inputs:
command: login
containerRegistry: $(containerRegistry)
- task: Cache@2
displayName: Cache Maven local repo
inputs:
key: 'maven | "$(Agent.OS)" | **/pom.xml'
restoreKeys: |
maven | "$(Agent.OS)"
maven
path: $(mavenCache)
- task: Cache@2
displayName: Cache node_modules
inputs:
key: 'npm | "$(Agent.OS)" | $(Build.SourcesDirectory)/ui/package.json'
path: $(Build.SourcesDirectory)/ui/node_modules
cacheHitVar: CACHE_RESTORED
- script: |
echo "*** Create Maven Local Repo at $(mavenCache)"
mkdir -p "$(mavenCache)"
echo "##vso[task.setvariable variable=M2_HOME]/opt/maven"
displayName: 'Create Maven Local Repo and set up M2_HOME'
- task: Maven@3
displayName: 'Build and run integration test'
inputs:
mavenPomFile: 'pom.xml'
options: '-DskipTests -Ddocker.registry.host=$(dockerRegistry) -Ddocker.repository=$(dockerRepository) -Djib.to.tags=$(imageTag) -DargLine="-Dims-username=$(imsUsername) -Dims-password=$(imsPassword)"'
mavenOptions: '$(mavenOptions) -Xmx5072m -Dbuildnumber=$(buildInfo)'
javaHomeOption: 'path'
jdkUserInputPath: '/usr/lib/jvm/java-17-openjdk-amd64'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'package -DskipTests'
- task: PublishCodeCoverageResults@1
displayName: Publish Code Coverage
inputs:
enabled: true
codeCoverageTool: 'JaCoCo'
summaryFileLocation: '**/target/site/jacoco/jacoco.xml'
reportDirectory: '**/target/site/jacoco'
additionalCodeCoverageFiles: '**/target/jacoco.exec'
# - script: |
# curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sudo sh -s -- -b /usr/local/bin v0.50.0
# trivy -v
# displayName: 'Download and install Trivy'
# - task: CmdLine@2
# displayName: "Run trivy scan on snomio"
# inputs:
# script: |
# trivy image --exit-code 0 --severity LOW,MEDIUM --scanners vuln --timeout 15m $(dockerRegistry)/$(dockerRepository):$(buildInfo)
# trivy image --exit-code 1 --severity HIGH,CRITICAL --scanners vuln --timeout 15m $(dockerRegistry)/$(dockerRepository):$(buildInfo)
# - task: Maven@3
# inputs:
# mavenPomFile: 'pom.xml'
# mavenOptions: '$(mavenOptions)'
# javaHomeOption: 'path'
# jdkUserInputPath: '/usr/lib/jvm/java-17-openjdk-amd64'
# jdkArchitectureOption: 'x64'
# publishJUnitResults: false
# goals: 'deploy -pl .,common,auth'
- job: e2e_tests
displayName: Run e2e Tests
timeoutInMinutes: 60
pool:
name: 'highmemory-pool'
dependsOn:
- set_image_tag
- snomio_build_test_publish
steps:
- download: current
artifact: branchInfo
- script: |
imageTag=$(cat $(Pipeline.Workspace)/branchInfo/branchInfo.txt)
if [[ -z "$imageTag" || "$imageTag" == *unknown* ]]; then
echo "Invalid imageTag: $imageTag"
exit 1
fi
echo "##vso[task.setvariable variable=buildInfo]$imageTag"
if [ "$(Build.SourceBranch)" = "refs/heads/main" ]; then
imageTag="$imageTag,latest"
fi
echo "##vso[task.setvariable variable=imageTag]$imageTag"
echo "Using imageTag: $imageTag"
displayName: 'Read imageTag from branchInfo.txt'
- task: Docker@2
displayName: 'Login to ACR'
inputs:
command: login
containerRegistry: $(containerRegistry)
- script: |
# Modify docker compose
sed -i 's/nctsacr.azurecr.io\/snomio:latest/nctsacr.azurecr.io\/snomio:$(imageTag)/' ui/cypress/docker/docker-compose.yaml
sed -i 's/ims-username=.*/ims-username=$(imsUsername)/' ui/cypress/docker/docker-compose.yaml
sed -i "s|ims-password=.*|ims-password=$(printf '%s\n' "$(imsPassword)" | sed 's|[&/]|\\&|g')|" ui/cypress/docker/docker-compose.yaml
sed -i 's/snomio.jira.users=.*/snomio.jira.users=$(imsUsername)/' ui/cypress/docker/docker-compose.yaml
cat ui/cypress/docker/docker-compose.yaml
# Create nginx directory if it doesn't exist
mkdir -p ui/cypress/docker/nginx
# Generate SSL certificates
openssl req -x509 -nodes -newkey rsa:2048 -keyout ui/cypress/docker/nginx/key.pem -out ui/cypress/docker/nginx/cert.pem -days 365 -subj "/C=AU/ST=QLD/L=Brisbane/O=CSIRO/OU=CSIRO Department/CN=snomio"
- task: DockerCompose@1
inputs:
containerregistrytype: 'Azure Container Registry'
azureContainerRegistry: $(dockerRegistry)
dockerComposeFile: 'ui/cypress/docker/docker-compose.yaml'
action: 'Run services'
projectName: snomio
buildImages: false
abortOnContainerExit: false
detached: true
- script: |
# Add entry to hosts file
echo "127.0.0.1 local-snomio.ihtsdotools.org" | sudo tee -a /etc/hosts
cat /etc/hosts
cd ui
npm install cypress --save-dev
npm install dotenv
export CYPRESS_BASE_URL="https://local-snomio.ihtsdotools.org:443"
export cypress_frontend_url="https://local-snomio.ihtsdotools.org:443"
export cypress_ims_username=$(imsUsername)
export cypress_ims_password=$(imsPassword)
export cypress_ims_url="https://dev-ims.ihtsdotools.org"
export cypress_apUrl="https://dev-snowstorm.ihtsdotools.org"
export cypress_apProjectKey="AUAMT"
export cypress_apDefaultBranch="MAIN/SNOMEDCT-AU/AUAMT"
npx cypress run --spec "cypress/e2e/ProductCreation.cy.ts"
displayName: 'Set environment variables and run Cypress tests'
# - task: PublishPipelineArtifact@1
# condition: succeededOrFailed()
# inputs:
# targetPath: $(Build.SourcesDirectory)/ui/cypress/screenshots
# artifact: cypress-screenshots
# publishLocation: pipeline
# displayName: 'Publish Cypress screenshots'