1
- @Library(['private-pipeline-library', 'jenkins-shared']) _
1
+ /*
2
+ * Copyright (c) 2011-present Sonatype, Inc. All rights reserved.
3
+ * Includes the third-party code listed at http://links.sonatype.com/products/clm/attributions.
4
+ * "Sonatype" is a trademark of Sonatype, Inc.
5
+ */
2
6
3
- import com.sonatype. jenkins.pipeline.OsTools
7
+ @Library(['private-pipeline-library', ' jenkins-shared']) _
4
8
5
9
import groovy.json.JsonSlurper
6
10
@@ -18,103 +22,6 @@ properties([
18
22
])
19
23
])
20
24
21
-
22
- node('ubuntu-zion') {
23
- def buildDir = "./.sbom-build/job-${env.BUILD_NUMBER}"
24
- def ubiImageName = ''
25
- def ubiImageVersion = ''
26
- def nexusVersion = ''
27
- def dockerImageVersion = ''
28
- def ubiSbomAvailable = true
29
-
30
- try {
31
- stage('Inspect Release Image') {
32
- // Get RedHat UBI version
33
- sh "docker pull sonatype/nexus3:${params.docker_nexus3_tag}"
34
-
35
- nexusVersion = sh(script: "docker inspect sonatype/nexus3:${params.docker_nexus3_tag} \
36
- | jq -r '.[0].Config.Labels.version' ",
37
- returnStdout: true).trim()
38
- dockerImageVersion = sh(script: "docker inspect sonatype/nexus3:${params.docker_nexus3_tag} \
39
- | jq -r '.[0].Config.Labels.release' ",
40
- returnStdout: true).trim()
41
-
42
- def ubiImageId = sh(script: "docker inspect sonatype/nexus3:${params.docker_nexus3_tag} \
43
- | jq -r '.[0].Config.Labels.\"base-image-ref\"' \
44
- | sed -En 's/^.+image=(.+)\$/\\1/p'",
45
- returnStdout: true).trim()
46
-
47
- ubiImageName = sh(script: "curl -s -X 'GET' '${REDHAT_CONTAINER_API_URL_BASE}/images/id/${ubiImageId}' -H 'accept: application/json' \
48
- | jq -r '.brew.build' \
49
- | sed -En 's/(ubi[0-9]+-minimal)-container-([0-9]+\\.[0-9]+-[0-9]+\\.?[0-9]*)/\\1-\\2/p'",
50
- returnStdout: true).trim()
51
-
52
- ubiImageVersion = sh(script: "curl -s -X 'GET' '${REDHAT_CONTAINER_API_URL_BASE}/images/id/${ubiImageId}' -H 'accept: application/json' \
53
- | jq -r '.brew.build' \
54
- | sed -En 's/ubi[0-9]+-minimal-container-([0-9]+\\.[0-9]+-[0-9]+\\.?[0-9]*)/\\1/p'",
55
- returnStdout: true).trim()
56
- }
57
- stage('Download SBOMs') {
58
- sh "mkdir -p ${buildDir}/spdx && mkdir -p ${buildDir}/cyclonedx"
59
-
60
- // Get nexus-internal SBOM
61
- getComponentSbom(buildDir, "nexus-internal", nexusVersion)
62
- // Get nxrm-db-migrator SBOM
63
- getComponentSbom(buildDir, "nxrm-db-migrator", nexusVersion)
64
- // Get docker-nexus3 SBOM
65
- getComponentSbom(buildDir, "docker-nexus3", dockerImageVersion)
66
- // Get UBI Minimal SBOM
67
- ubiSbomAvailable = getUbiImageSbom(buildDir, ubiImageName, ubiImageVersion)
68
-
69
- sh "echo 'Available SPDX SBOMS' && ls ${buildDir}/spdx"
70
- sh "echo 'Available CycloneDx SBOMS' && ls ${buildDir}/cyclonedx"
71
- }
72
-
73
- stage('Merge supported sboms') {
74
- def pythonEnvDir = "${buildDir}/.spdxmerge"
75
-
76
- sh """#!/bin/bash
77
- if ! [ -d "${buildDir}/SPDXMerge" ]; then
78
- git clone https://github.com/philips-software/SPDXMerge.git '${buildDir}/SPDXMerge'
79
- fi
80
- """
81
-
82
- sh """#!/bin/bash
83
- if mkdir -p '${pythonEnvDir}' && python3 -m venv '${pythonEnvDir}' && ls '${pythonEnvDir}' && . '${pythonEnvDir}/bin/activate'; then
84
- if python3 -m pip install -r '${buildDir}/SPDXMerge/requirements.txt' \
85
- && python3 -m pip install setuptools \
86
- && python3 '${buildDir}/SPDXMerge/spdxmerge/SPDXMerge.py' --docpath '${buildDir}/spdx' --outpath '${buildDir}/' \
87
- --name "docker-nexus3-aggregate" --mergetype "1" --author "Sonatype Inc." --email "
[email protected] " \
88
- --docnamespace "https://sonatype.sonatype.app/platform/ui/links/application/docker-nexus3/report/b0c5f7f12ac84b439ded3ff255bd5eef" \
89
- --filetype J \
90
- && mv '${buildDir}/merged-SBoM-deep.json' '${buildDir}/spdx/docker-nexus3-aggregate-${dockerImageVersion}-spdx.json'; then
91
- echo 'Merge completed!'
92
- else
93
- echo 'Merge failed!'
94
- FAILED=1
95
- fi
96
-
97
- deactivate
98
- fi
99
-
100
- exit \${FAILED:-0}
101
- """
102
- }
103
-
104
- stage('Publish SBOMs') {
105
- if (ubiSbomAvailable) {
106
- publishComponent(buildDir, "ubi-minimal", ubiImageVersion, false)
107
- }
108
- publishComponent(buildDir, "nexus-internal", nexusVersion)
109
- publishComponent(buildDir, "nxrm-db-migrator", nexusVersion)
110
- publishComponent(buildDir, "docker-nexus3", dockerImageVersion)
111
- publishComponent(buildDir, "docker-nexus3-aggregate", dockerImageVersion, false)
112
- }
113
- } finally {
114
- OsTools.runSafe(this, "rm -rf '${buildDir}'")
115
- }
116
- }
117
-
118
25
def getComponentSbom(String buildDir, String componentName, String componentVersion) {
119
26
def componentInfo = getComponentInfo(componentName)
120
27
def componentId = componentInfo.applications[0].id
@@ -192,4 +99,96 @@ def publishComponent(String buildDir, String componentName, String componentVers
192
99
]) {
193
100
sh(publishCommand)
194
101
}
195
- }
102
+ }
103
+
104
+ def mergeSpdxComponents(String buildDir, String finalComponentName, String finalComponentVersion, String finalNamespace) {
105
+ def pythonEnvDir = "${buildDir}/.spdxmerge"
106
+
107
+ sh """#!/bin/bash
108
+ if ! [ -d "${buildDir}/SPDXMerge" ]; then
109
+ git clone https://github.com/philips-software/SPDXMerge.git '${buildDir}/SPDXMerge'
110
+ fi
111
+ """
112
+
113
+ sh """#!/bin/bash
114
+ if mkdir -p '${pythonEnvDir}' && python3 -m venv '${pythonEnvDir}' && ls '${pythonEnvDir}' && . '${pythonEnvDir}/bin/activate'; then
115
+ if python3 -m pip install -r '${buildDir}/SPDXMerge/requirements.txt' \
116
+ && python3 -m pip install setuptools \
117
+ && python3 '${buildDir}/SPDXMerge/spdxmerge/SPDXMerge.py' --docpath '${buildDir}/spdx' --outpath '${buildDir}/' \
118
+ --name "docker-nexus3-aggregate" --mergetype "1" --author "Sonatype Inc." --email "
[email protected] " \
119
+ --docnamespace "${finalNamespace}" \
120
+ --filetype J \
121
+ && mv '${buildDir}/merged-SBoM-deep.json' '${buildDir}/spdx/${finalComponentName}-${finalComponentVersion}-spdx.json'; then
122
+ echo 'Merge completed!'
123
+ else
124
+ echo 'Merge failed!'
125
+ FAILED=1
126
+ fi
127
+
128
+ deactivate
129
+ fi
130
+
131
+ exit \${FAILED:-0}
132
+ """
133
+ }
134
+
135
+ dockerizedRunPipeline(
136
+ skipVulnerabilityScan: true,
137
+ pathToDockerfile: "./build-images/Dockerfile.sbom-deployer",
138
+ prepare: {
139
+ withSonatypeDockerRegistry() {
140
+ sh "docker pull sonatype/nexus3:${params.docker_nexus3_tag}"
141
+ env['nexusVersion'] = sh(script: "docker inspect sonatype/nexus3:${params.docker_nexus3_tag} \
142
+ | jq -r '.[0].Config.Labels.version' ",
143
+ returnStdout: true).trim()
144
+ env['dockerImageVersion'] = sh(script: "docker inspect sonatype/nexus3:${params.docker_nexus3_tag} \
145
+ | jq -r '.[0].Config.Labels.release' ",
146
+ returnStdout: true).trim()
147
+ env['ubiImageId'] = sh(script: "docker inspect sonatype/nexus3:${params.docker_nexus3_tag} \
148
+ | jq -r '.[0].Config.Labels.\"base-image-ref\"' \
149
+ | sed -En 's/^.+image=(.+)\$/\\1/p'",
150
+ returnStdout: true).trim()
151
+ }
152
+ },
153
+ run: {
154
+ def buildDir = "./.sbom-build/job-${env.BUILD_NUMBER}"
155
+ def ubiImageName = sh(script: "curl -s -X 'GET' '${REDHAT_CONTAINER_API_URL_BASE}/images/id/${env.ubiImageId}' -H 'accept: application/json' \
156
+ | jq -r '.brew.build' \
157
+ | sed -En 's/(ubi[0-9]+-minimal)-container-([0-9]+\\.[0-9]+-[0-9]+\\.?[0-9]*)/\\1-\\2/p'",
158
+ returnStdout: true).trim()
159
+ def ubiImageVersion = sh(script: "curl -s -X 'GET' '${REDHAT_CONTAINER_API_URL_BASE}/images/id/${env.ubiImageId}' -H 'accept: application/json' \
160
+ | jq -r '.brew.build' \
161
+ | sed -En 's/ubi[0-9]+-minimal-container-([0-9]+\\.[0-9]+-[0-9]+\\.?[0-9]*)/\\1/p'",
162
+ returnStdout: true).trim()
163
+
164
+ // Download SBOMs
165
+ sh "mkdir -p ${buildDir}/spdx && mkdir -p ${buildDir}/cyclonedx"
166
+
167
+ // Get nexus-internal SBOM
168
+ getComponentSbom(buildDir, "nexus-internal", env.nexusVersion)
169
+ // Get nxrm-db-migrator SBOM
170
+ getComponentSbom(buildDir, "nxrm-db-migrator", env.nexusVersion)
171
+ // Get docker-nexus3 SBOM
172
+ getComponentSbom(buildDir, "docker-nexus3", env.dockerImageVersion)
173
+ // Get UBI Minimal SBOM
174
+ def ubiSbomAvailable = getUbiImageSbom(buildDir, ubiImageName, ubiImageVersion)
175
+
176
+ sh "echo 'Available SPDX SBOMS' && ls ${buildDir}/spdx"
177
+ sh "echo 'Available CycloneDx SBOMS' && ls ${buildDir}/cyclonedx"
178
+
179
+ // Merge supported sboms
180
+ def dockerImageNamespace = sh(script: "cat ${buildDir}/spdx/docker-nexus3-${env.dockerImageVersion}-spdx.json | jq -r '.documentNamespace'", returnStdout: true).trim()
181
+ mergeSpdxComponents(buildDir, "docker-nexus3-aggregate", env.dockerImageVersion, dockerImageNamespace)
182
+
183
+ // Publish SBOMs
184
+ if (ubiSbomAvailable) {
185
+ publishComponent(buildDir, "ubi-minimal", ubiImageVersion, false)
186
+ }
187
+ publishComponent(buildDir, "nexus-internal", env.nexusVersion)
188
+ publishComponent(buildDir, "nxrm-db-migrator", env.nexusVersion)
189
+ publishComponent(buildDir, "docker-nexus3", env.dockerImageVersion)
190
+ publishComponent(buildDir, "docker-nexus3-aggregate", env.dockerImageVersion, false)
191
+
192
+ sh "rm -rf '${buildDir}'"
193
+ }
194
+ )
0 commit comments