-
Notifications
You must be signed in to change notification settings - Fork 9
/
bitbucket-pipelines.yml
268 lines (228 loc) · 9.38 KB
/
bitbucket-pipelines.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
clone:
depth: full
image: atlassian/default-image:2
definitions:
export_image_env_vars: &export_image_env_vars |
export IMAGE_TAGGED="${DOCKERHUB_REPO_OWNER}/loancalculator:bitbucket-$(git log -1 --pretty=%h)"
export IMAGE_LATEST="${DOCKERHUB_REPO_OWNER}/loancalculator:bitbucket-latest"
export_merkely_fingerprint_env_vars: &export_merkely_fingerprint_env_vars |
export IMAGE_TAGGED="${DOCKERHUB_REPO_OWNER}/loancalculator:bitbucket-$(git log -1 --pretty=%h)"
docker pull ${IMAGE_TAGGED}
export SHA256=$(docker inspect --format='{{index .RepoDigests 0}}' ${IMAGE_TAGGED} | cut -d ':' -f 2)
export MERKELY_FINGERPRINT="sha256://${SHA256}/${IMAGE_TAGGED}"
export MERKELY_OWNER=compliancedb
export MERKELY_PIPELINE=bitbucket-loancalculator
export_merkely_pipeline_env_vars: &export_merkely_pipeline_env_vars
export MERKELY_OWNER=compliancedb
export MERKELY_PIPELINE=bitbucket-loancalculator
export MERKELY_PIPE_PATH="${PWD}/Merkelypipe.json"
steps:
- step: &merkely-declare-pipeline
name: Declare Merkely Pipeline
services: [ docker ]
script:
- *export_merkely_pipeline_env_vars
- pipe: docker://merkely/change:latest
variables:
MERKELY_COMMAND: declare_pipeline
MERKELY_OWNER: ${MERKELY_OWNER}
MERKELY_PIPELINE: ${MERKELY_PIPELINE}
MERKELY_PIPE_PATH: ${MERKELY_PIPE_PATH}
MERKELY_API_TOKEN: ${MERKELY_API_TOKEN}
- step: &build-and-publish-docker-image
name: Build and publish Docker image
services: [ docker ]
script:
- *export_image_env_vars
- docker build --file ${PWD}/Dockerfile --tag ${IMAGE_TAGGED} ${PWD}
- docker tag ${IMAGE_TAGGED} ${IMAGE_LATEST}
- echo ${DOCKERHUB_DEPLOY_TOKEN} | docker login --username ${DOCKERHUB_DEPLOY_USERNAME} --password-stdin
- docker push ${IMAGE_TAGGED}
- docker push ${IMAGE_LATEST}
- step: &merkely-log-docker-image
name: Log Docker image in Merkely
services: [ docker ]
script:
- *export_merkely_fingerprint_env_vars
- pipe: docker://merkely/change:latest
variables:
MERKELY_COMMAND: log_artifact
MERKELY_FINGERPRINT: ${MERKELY_FINGERPRINT}
MERKELY_IS_COMPLIANT: "TRUE"
MERKELY_OWNER: ${MERKELY_OWNER}
MERKELY_PIPELINE: ${MERKELY_PIPELINE}
MERKELY_API_TOKEN: ${MERKELY_API_TOKEN}
- step: &run-unit-tests
name: Run units tests
services: [ docker ]
script:
- *export_image_env_vars
- docker run
--name container
--entrypoint ./entrypoint-unit_test.sh
${IMAGE_TAGGED}
- mkdir -p build/test
- docker cp container:/code/build/test/ ${PWD}/build
- docker rm container
artifacts:
- build/test/**
- step: &merkely-log-unit-test-results
name: Log unit test results in Merkely
services: [ docker ]
script:
- *export_merkely_fingerprint_env_vars
- pipe: docker://merkely/change:latest
variables:
MERKELY_COMMAND: log_test
MERKELY_FINGERPRINT: ${MERKELY_FINGERPRINT}
MERKELY_EVIDENCE_TYPE: unit_test
MERKELY_TEST_RESULTS_DIR: ${PWD}/build/test/
MERKELY_OWNER: ${MERKELY_OWNER}
MERKELY_PIPELINE: ${MERKELY_PIPELINE}
MERKELY_API_TOKEN: ${MERKELY_API_TOKEN}
- step: &run-security-tests
name: Run security tests
services: [ docker ]
script:
- *export_image_env_vars
- mkdir -p build/security
- docker run
--rm
--volume ${PWD}/build:/code/build
--entrypoint ./entrypoint-security.sh
${IMAGE_TAGGED}
artifacts:
- build/security/**
- step: &merkely-log-security-test-results
name: Log security test results in Merkely
services: [ docker ]
script:
- *export_merkely_fingerprint_env_vars
- pipe: docker://merkely/change:latest
variables:
MERKELY_COMMAND: log_test
MERKELY_FINGERPRINT: ${MERKELY_FINGERPRINT}
MERKELY_EVIDENCE_TYPE: security
MERKELY_TEST_RESULTS_DIR: ${PWD}/build/security/
MERKELY_OWNER: ${MERKELY_OWNER}
MERKELY_PIPELINE: ${MERKELY_PIPELINE}
MERKELY_API_TOKEN: ${MERKELY_API_TOKEN}
- step: &run-coverage-analysis
name: Run coverage analysis
services: [ docker ]
script:
- *export_image_env_vars
- mkdir -p build/coverage
- docker run
--entrypoint ./entrypoint-coverage.sh
--rm
--volume ${PWD}/build:/code/build
${IMAGE_TAGGED}
artifacts:
- build/coverage/**
- step: &merkely-log-coverage-analysis
name: Log coverage analysis results in Merkely
services: [ docker ]
script:
- source build/coverage/coverage_summary.sh
- *export_merkely_fingerprint_env_vars
- pipe: docker://merkely/change:latest
variables:
MERKELY_COMMAND: log_evidence
MERKELY_FINGERPRINT: ${MERKELY_FINGERPRINT}
MERKELY_EVIDENCE_TYPE: coverage
MERKELY_IS_COMPLIANT: "TRUE"
MERKELY_DESCRIPTION: ${COVERAGE_SUMMARY}
MERKELY_OWNER: ${MERKELY_OWNER}
MERKELY_PIPELINE: ${MERKELY_PIPELINE}
MERKELY_API_TOKEN: ${MERKELY_API_TOKEN}
- step: &deploy-to-staging
name: Deploy to staging
script:
- echo YOUR DEPLOYMENT COMMAND HERE
- step: &merkely-log-deployment-to-staging
name: Log deployment to staging in Merkely
services: [ docker ]
script:
- *export_merkely_fingerprint_env_vars
- pipe: docker://merkely/change:latest
variables:
MERKELY_COMMAND: log_deployment
MERKELY_FINGERPRINT: ${MERKELY_FINGERPRINT}
MERKELY_DESCRIPTION: "Deployed to staging in bitbucket pipeline"
MERKELY_ENVIRONMENT: staging
MERKELY_OWNER: ${MERKELY_OWNER}
MERKELY_PIPELINE: ${MERKELY_PIPELINE}
MERKELY_API_TOKEN: ${MERKELY_API_TOKEN}
- step: &merkely-request-approval-for-deployment
name: Request approval for deployment in Merkely
services: [ docker ]
script:
- *export_merkely_fingerprint_env_vars
- pipe: docker://merkely/change:latest
variables:
MERKELY_COMMAND: request_approval
MERKELY_FINGERPRINT: ${MERKELY_FINGERPRINT}
MERKELY_OLDEST_SRC_COMMITISH: "origin/production"
MERKELY_NEWEST_SRC_COMMITISH: ${BITBUCKET_COMMIT}
MERKELY_DESCRIPTION: "Production release requested from bitbucket pipeline"
MERKELY_SRC_REPO_ROOT: ${PWD}
MERKELY_OWNER: ${MERKELY_OWNER}
MERKELY_PIPELINE: ${MERKELY_PIPELINE}
MERKELY_API_TOKEN: ${MERKELY_API_TOKEN}
- step: &merkely-check-deployment-approved
name: Trigger when deployment approved in Merkely
services: [ docker ]
trigger: manual
script:
- *export_merkely_fingerprint_env_vars
- pipe: docker://merkely/change:latest
variables:
MERKELY_COMMAND: control_deployment
MERKELY_FINGERPRINT: ${MERKELY_FINGERPRINT}
MERKELY_OWNER: ${MERKELY_OWNER}
MERKELY_PIPELINE: ${MERKELY_PIPELINE}
MERKELY_API_TOKEN: ${MERKELY_API_TOKEN}
- step: &deploy-to-production
name: Deploy to Production
script:
- echo YOUR DEPLOYMENT COMMAND HERE
- step: &merkely-log-deployment-to-production
name: Log deploy to Production in Merkely
services: [ docker ]
script:
- *export_merkely_fingerprint_env_vars
- pipe: docker://merkely/change:latest
variables:
MERKELY_COMMAND: log_deployment
MERKELY_FINGERPRINT: ${MERKELY_FINGERPRINT}
MERKELY_DESCRIPTION: "Deployed to production in bitbucket pipeline"
MERKELY_ENVIRONMENT: production
MERKELY_OWNER: ${MERKELY_OWNER}
MERKELY_PIPELINE: ${MERKELY_PIPELINE}
MERKELY_API_TOKEN: ${MERKELY_API_TOKEN}
- step: &update-tracking-branch
name: Update tracking branch
script:
- git checkout --track origin/production
- git merge ${BITBUCKET_COMMIT}
- git push origin production
pipelines:
branches:
main:
- step: *merkely-declare-pipeline
- step: *build-and-publish-docker-image
- step: *merkely-log-docker-image
- step: *run-unit-tests
- step: *merkely-log-unit-test-results
- step: *run-security-tests
- step: *merkely-log-security-test-results
- step: *run-coverage-analysis
- step: *merkely-log-coverage-analysis
- step: *deploy-to-staging
- step: *merkely-log-deployment-to-staging
- step: *merkely-request-approval-for-deployment
- step: *merkely-check-deployment-approved
- step: *deploy-to-production
- step: *merkely-log-deployment-to-production
- step: *update-tracking-branch