-
Notifications
You must be signed in to change notification settings - Fork 11
/
Jenkinsfile
346 lines (316 loc) · 12.7 KB
/
Jenkinsfile
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
#!/usr/bin/env groovy
@Library("product-pipelines-shared-library") _
// Automated release, promotion and dependencies
properties([
// Include the automated release parameters for the build
release.addParams(),
// Dependencies of the project that should trigger builds
dependencies([
'conjur-enterprise/conjur-opentelemetry-tracer',
'conjur-enterprise/conjur-authn-k8s-client',
'conjur-enterprise/conjur-api-go',
'conjur-enterprise/conjur'
])
])
// Performs release promotion. No other stages will be run
if (params.MODE == "PROMOTE") {
release.promote(params.VERSION_TO_PROMOTE) { infrapool, sourceVersion, targetVersion, assetDirectory ->
// Any assets from sourceVersion Github release are available in assetDirectory
// Any version number updates from sourceVersion to targetVersion occur here
// Any publishing of targetVersion artifacts occur here
// Anything added to assetDirectory will be attached to the Github Release
// Pull existing images from internal registry in order to promote
infrapool.agentSh """
export PATH="release-tools/bin:${PATH}"
docker pull registry.tld/secrets-provider-for-k8s:${sourceVersion}
docker pull registry.tld/secrets-provider-for-k8s-redhat:${sourceVersion}
# Promote source version to target version.
summon ./bin/publish --promote --source ${sourceVersion} --target ${targetVersion}
"""
}
// Copy Github Enterprise release to Github
release.copyEnterpriseRelease(params.VERSION_TO_PROMOTE)
return
}
pipeline {
agent { label 'conjur-enterprise-common-agent' }
options {
timestamps()
// We want to avoid running in parallel.
// When we have 2 build running on the same environment (gke env only) in parallel,
// we get the error "gcloud crashed : database is locked"
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '30'))
timeout(time: 3, unit: 'HOURS')
}
triggers {
cron(getDailyCronString())
}
environment {
// Sets the MODE to the specified or autocalculated value as appropriate
MODE = release.canonicalizeMode()
}
parameters {
booleanParam(name: 'TEST_OCP_NEXT', defaultValue: false, description: 'Run DAP tests against our running "next version" of Openshift')
booleanParam(name: 'TEST_OCP_OLDEST', defaultValue: false, description: 'Run DAP tests against our running "oldest version" of Openshift')
booleanParam(name: 'TEST_E2E', defaultValue: false, description: 'Run E2E tests on a branch')
}
stages {
stage('Scan for internal URLs') {
steps {
script {
detectInternalUrls()
}
}
}
stage('Get InfraPool ExecutorV2 Agent') {
steps {
script {
// Request ExecutorV2 agents for 1 hour(s)
INFRAPOOL_EXECUTORV2_AGENT_0 = getInfraPoolAgent.connected(type: "ExecutorV2", quantity: 1, duration: 2)[0]
}
}
}
// Aborts any builds triggered by another project that wouldn't include any changes
stage ("Skip build if triggering job didn't create a release") {
when {
expression {
MODE == "SKIP"
}
}
steps {
script {
currentBuild.result = 'ABORTED'
error("Aborting build because this build was triggered from upstream, but no release was built")
}
}
}
stage('Validate') {
parallel {
stage('Changelog') {
steps { script { parseChangelog(INFRAPOOL_EXECUTORV2_AGENT_0) } }
}
stage('Log messages') {
steps {
validateLogMessages()
}
}
}
}
// Generates a VERSION file based on the current build number and latest version in CHANGELOG.md
stage('Validate Changelog and set version') {
steps {
updateVersion(INFRAPOOL_EXECUTORV2_AGENT_0, "CHANGELOG.md", "${BUILD_NUMBER}")
}
}
stage('Get latest upstream dependencies') {
steps {
script {
updatePrivateGoDependencies("${WORKSPACE}/go.mod")
// Copy the vendor directory onto infrapool
INFRAPOOL_EXECUTORV2_AGENT_0.agentPut from: "vendor", to: "${WORKSPACE}"
INFRAPOOL_EXECUTORV2_AGENT_0.agentPut from: "go.*", to: "${WORKSPACE}"
INFRAPOOL_EXECUTORV2_AGENT_0.agentPut from: "/root/go", to: "/var/lib/jenkins/"
}
}
}
stage('Build and test Secrets Provider') {
when {
// Run tests only when EITHER of the following is true:
// 1. A non-markdown file has changed.
// 2. It's the main branch.
// 3. It's a version tag, typically created during a release
anyOf {
// Note: You cannot use "when"'s changeset condition here because it's
// not powerful enough to express "_only_ md files have changed".
// Dropping down to a git script was the easiest alternative.
expression {
0 == sh(
returnStatus: true,
// A non-markdown file has changed.
script: '''
git diff origin/main --name-only |
grep -v "^.*\\.md$" > /dev/null
'''
)
}
// Always run the full pipeline on main branch
branch 'main'
// Always run the full pipeline on a version tag created during release
buildingTag()
}
}
stages {
stage('Build client Docker image') {
steps {
script {
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh './bin/build'
}
}
}
stage('Scan Docker Image') {
parallel {
stage("Scan Docker Image for fixable issues") {
steps {
// Adding the false parameter to scanAndReport causes trivy to
// ignore vulnerabilities for which no fix is available. We'll
// only fail the build if we can actually fix the vulnerability
// right now.
scanAndReport(INFRAPOOL_EXECUTORV2_AGENT_0, 'secrets-provider-for-k8s:latest', "HIGH", false)
}
}
stage("Scan Docker image for total issues") {
steps {
// By default, trivy includes vulnerabilities with no fix. We
// want to know about that ASAP, but they shouldn't cause a
// build failure until we can do something about it. This call
// to scanAndReport should always be left as "NONE"
scanAndReport(INFRAPOOL_EXECUTORV2_AGENT_0, "secrets-provider-for-k8s:latest", "NONE", true)
}
}
stage('Scan RedHat image for fixable issues') {
steps {
scanAndReport(INFRAPOOL_EXECUTORV2_AGENT_0, "secrets-provider-for-k8s-redhat:latest", "HIGH", false)
}
}
stage('Scan RedHat image for all issues') {
steps {
scanAndReport(INFRAPOOL_EXECUTORV2_AGENT_0, "secrets-provider-for-k8s-redhat:latest", "NONE", true)
}
}
}
}
stage('Run Unit Tests') {
steps {
script {
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh './bin/test_unit'
}
}
post {
always {
script {
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh './bin/coverage'
INFRAPOOL_EXECUTORV2_AGENT_0.agentStash name: 'coverage', includes: '*.xml'
unstash 'coverage'
junit 'junit.xml'
cobertura autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: 'coverage.xml', conditionalCoverageTargets: '70, 0, 0', failUnhealthy: false, failUnstable: false, maxNumberOfBuilds: 0, lineCoverageTargets: '70, 0, 0', methodCoverageTargets: '70, 0, 0', onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false
codacy action: 'reportCoverage', filePath: "coverage.xml"
}
}
}
}
stage ("DAP Integration Tests on GKE") {
when { anyOf {
branch 'main'
expression { params.TEST_E2E == true }
} }
steps {
script {
def tasks = [:]
tasks["Kubernetes GKE, DAP"] = {
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh "./bin/start --docker --dap --gke"
}
parallel tasks
}
}
}
stage ("DAP Integration Tests on OpenShift") {
when {
// Run integration tests against OpenShift only on the main branch
//
// There's been a lot of flakiness around OpenShift, which has the negative effect of impeding developer velocity.
// Generally speaking the integration tests for this repository interact with the generic Kubernetes API, for
// scheduling and giving identity to workloads. There is no platform-specifc functionality within the secrets provider.
// We can reasonably assume that if a branch is green in GKE then it will likely be green for OpenShift.
// With that in mind, for now we have chosen to run Openshift integration tests only on the main branch while we figure
// out a better way to address the flakiness.
branch 'main'
}
steps {
script {
def tasks = [:]
if ( params.TEST_OCP_OLDEST ) {
tasks["Openshift (Oldest), DAP"] = {
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh "./bin/start --docker --dap --oldest"
}
}
tasks["Openshift (Current), DAP"] = {
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh "./bin/start --docker --dap --current"
}
if ( params.TEST_OCP_NEXT ) {
tasks["Openshift (Next), DAP"] = {
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh "./bin/start --docker --dap --next"
}
}
parallel tasks
}
}
}
// We want to avoid running in parallel.
// When we have 2 build running on the same environment (gke env only) in parallel,
// we get the error "gcloud crashed : database is locked"
stage ("OSS Integration Tests on GKE") {
when { anyOf {
branch 'main'
expression { params.TEST_E2E == true }
} }
steps {
script {
def tasks = [:]
tasks["Kubernetes GKE, oss"] = {
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh "./bin/start --docker --oss --gke"
}
parallel tasks
}
}
}
// Allows for the promotion of images.
stage('Push images to internal registry') {
steps {
script {
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh './bin/publish --internal'
}
}
}
stage('Release') {
when {
expression {
MODE == "RELEASE"
}
}
parallel {
stage('Push Images') {
steps {
script {
release(INFRAPOOL_EXECUTORV2_AGENT_0) { billOfMaterialsDirectory, assetDirectory, toolsDirectory ->
// Publish release artifacts to all the appropriate locations
// Copy any artifacts to assetDirectory to attach them to the Github release
// Create Go application SBOM using the go.mod version for the golang container image
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh """export PATH="${toolsDirectory}/bin:${PATH}" && go-bom --tools "${toolsDirectory}" --go-mod ./go.mod --image "golang" --main "cmd/secrets-provider/" --output "${billOfMaterialsDirectory}/go-app-bom.json" """
// Create Go module SBOM
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh """export PATH="${toolsDirectory}/bin:${PATH}" && go-bom --tools "${toolsDirectory}" --go-mod ./go.mod --image "golang" --output "${billOfMaterialsDirectory}/go-mod-bom.json" """
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh 'summon ./bin/publish --edge'
}
}
}
}
stage('Package artifacts') {
steps {
script {
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh 'ci/jenkins_build'
INFRAPOOL_EXECUTORV2_AGENT_0.agentArchiveArtifacts artifacts: "helm-artifacts/"
}
}
}
}
}
}
}
}
post {
always {
archiveArtifacts artifacts: "deploy/output/*.txt", fingerprint: false, allowEmptyArchive: true
releaseInfraPoolAgent(".infrapool/release_agents")
}
}
}