You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -12,7 +12,7 @@ One of the benefits of buildpacks is they can also populate the app image with m
12
12
* The buildpacks were used to create the app image
13
13
* And more...!
14
14
15
-
You can find all of this information using `pack` via its `inspect-image` command.
15
+
You can find some of this information using `pack` via its `inspect-image` command. The bill-of-materials information will be available using `pack sbom download`.
16
16
17
17
<!-- test:exec -->
18
18
```bash
@@ -38,18 +38,77 @@ Processes:
38
38
39
39
Apart from the above standard metadata, buildpacks can also populate information about the dependencies they have provided in form of a `Bill-of-Materials`. Let's see how we can use this to populate information about the version of `ruby` that was installed in the output app image.
40
40
41
-
To add the `ruby` version to the output of `pack inspect-image`, we will have to provide a `Bill-of-Materials` (`BOM`) containing this information. You'll need to update the `launch.toml` created at the end of your `build` script:
41
+
To add the `ruby` version to the output of `pack download sbom`, we will have to provide a `Bill-of-Materials` (`BOM`) containing this information. There are three "standard" ways to report SBOM data. You'll need to choose to use on of CycloneDX, SPDX or Syft update the `ruby.sbom.<ext>` (where `<ext>` is the extension appropriate for your BOM standard, one of `cdx.json`, `spdx.json` or `syft.json`) at the end of your `build` script. Discussion of which BOM format to choose is outside the scope of this tutorial, but we will note that the SBOM format you choose to use is likely to be the output format of any BOM scanner (eg: [`syft cli`](https://github.com/anchore/syft)) you might choose to use. In this example we will use the CycloneDX json format.
42
+
43
+
First, annotate the `buildpack.toml` to specify that it emits CycloneDX:
Then, in our buildpack implemetnation we will generate the necessary BOM metadata:
42
62
43
63
```bash
44
64
# ...
45
65
46
66
# Append a Bill-of-Materials containing metadata about the provided ruby version
47
-
cat >>"$layersdir/launch.toml"<<EOL
48
-
[[bom]]
49
-
name = "ruby"
50
-
[bom.metadata]
51
-
version = "$ruby_version"
67
+
cat >>"$layersdir/ruby.sbom.cdx.json"<<EOL
68
+
{
69
+
"bomFormat": "CycloneDX",
70
+
"specVersion": "1.3",
71
+
"version": 1,
72
+
"components": [
73
+
{
74
+
"type": "library",
75
+
"name": "ruby",
76
+
"version": "$ruby_version"
77
+
}
78
+
]
79
+
}
80
+
EOL
81
+
```
82
+
83
+
We can also add an BOM entry for each dependency listed in `Gemfile.lock`. Here we use `jq` to add a new record to the `components` array in `bundler.sbom.cdx.json`:
84
+
85
+
```bash
86
+
crubybom="${layersdir}/ruby.sbom.cdx.json"
87
+
cat >>${rubybom}<<EOL
88
+
{
89
+
"bomFormat": "CycloneDX",
90
+
"specVersion": "1.3",
91
+
"version": 1,
92
+
"components": [
93
+
{
94
+
"type": "library",
95
+
"name": "ruby",
96
+
"version": "$ruby_version"
97
+
}
98
+
]
99
+
}
52
100
EOL
101
+
if [[ -f Gemfile.lock ]] ;then
102
+
forgemin$(gem dep -q | grep ^Gem | sed 's/^Gem //')
103
+
do
104
+
version=${gem##*-}
105
+
name=${gem%-${version}}
106
+
DEP=$(jq --arg name "${name}" --arg version "${version}" \
You should then be able to inspect your Ruby app for its Bill-of-Materials via:
227
+
Viewing your bill-of-materials requires first pushing the built image to a container registry and then querying the bill-of-materials. If you are a `docker` user, we can experiment with an OCI container registry by running an instance of Docker's `registry:2` (as an aside, the standard Docker daemon is a container registry, but is not fully [OCI compliant](https://opencontainers.org/)).
150
228
151
229
<!-- test:exec -->
152
230
```bash
153
-
pack inspect-image test-ruby-app --bom
231
+
docker run -d -p 5000:5000 registry:2
232
+
docker image tag test-ruby-app localhost:5000/test-ruby-app
233
+
docker push localhost:5000/test-ruby-app
234
+
pack sbom download localhost:5000/test-ruby-app
154
235
```
155
236
<!--+- "{{execute}}"+-->
156
237
238
+
The SBOM information is now downloaded to the local file system:
You should find that the included `ruby` version is `2.5.0` as expected.
158
246
159
-
<!-- test:assert=contains -->
247
+
<!-- test:assert=contains;ignore-lines=... -->
160
248
```text
249
+
{
250
+
"bomFormat": "CycloneDX",
251
+
"specVersion": "1.3",
252
+
"version": 1,
253
+
"components": [
161
254
{
255
+
"type": "library",
162
256
"name": "ruby",
163
-
"metadata": {
164
-
"version": "2.5.0"
165
-
},
166
-
"buildpacks": {
167
-
"id": "examples/ruby",
168
-
"version": "0.0.1"
169
-
}
170
-
}
257
+
"version": "2.5.0"
258
+
},
259
+
...
260
+
]
261
+
}
171
262
```
172
263
173
264
Congratulations! You’ve created your first configurable Cloud Native Buildpack that uses detection, image layers, and caching to create an introspectable and runnable OCI image.
@@ -9,7 +9,7 @@ One of the benefits of buildpacks is they can also populate the app image with m
9
9
* The buildpacks were used to create the app image
10
10
* And more...!
11
11
12
-
You can find all of this information using `pack` via its `inspect-image` command.
12
+
You can find some of this information using `pack` via its `inspect-image` command. The bill-of-materials information will be available using `pack sbom download`.
13
13
14
14
<!-- test:exec -->
15
15
```bash
@@ -34,18 +34,77 @@ Processes:
34
34
35
35
Apart from the above standard metadata, buildpacks can also populate information about the dependencies they have provided in form of a `Bill-of-Materials`. Let's see how we can use this to populate information about the version of `ruby` that was installed in the output app image.
36
36
37
-
To add the `ruby` version to the output of `pack inspect-image`, we will have to provide a `Bill-of-Materials` (`BOM`) containing this information. You'll need to update the `launch.toml` created at the end of your `build` script:
37
+
To add the `ruby` version to the output of `pack download sbom`, we will have to provide a `Bill-of-Materials` (`BOM`) containing this information. There are three "standard" ways to report SBOM data. You'll need to choose to use on of CycloneDX, SPDX or Syft update the `ruby.sbom.<ext>` (where `<ext>` is the extension appropriate for your BOM standard, one of `cdx.json`, `spdx.json` or `syft.json`) at the end of your `build` script. Discussion of which BOM format to choose is outside the scope of this tutorial, but we will note that the SBOM format you choose to use is likely to be the output format of any BOM scanner (eg: [`syft cli`](https://github.com/anchore/syft)) you might choose to use. In this example we will use the CycloneDX json format.
38
+
39
+
First, annotate the `buildpack.toml` to specify that it emits CycloneDX:
Then, in our buildpack implemetnation we will generate the necessary BOM metadata:
38
58
39
59
```bash
40
60
# ...
41
61
42
62
# Append a Bill-of-Materials containing metadata about the provided ruby version
43
-
cat >>"$layersdir/launch.toml"<<EOL
44
-
[[bom]]
45
-
name = "ruby"
46
-
[bom.metadata]
47
-
version = "$ruby_version"
63
+
cat >>"$layersdir/ruby.sbom.cdx.json"<<EOL
64
+
{
65
+
"bomFormat": "CycloneDX",
66
+
"specVersion": "1.3",
67
+
"version": 1,
68
+
"components": [
69
+
{
70
+
"type": "library",
71
+
"name": "ruby",
72
+
"version": "$ruby_version"
73
+
}
74
+
]
75
+
}
76
+
EOL
77
+
```
78
+
79
+
We can also add an BOM entry for each dependency listed in `Gemfile.lock`. Here we use `jq` to add a new record to the `components` array in `bundler.sbom.cdx.json`:
80
+
81
+
```bash
82
+
crubybom="${layersdir}/ruby.sbom.cdx.json"
83
+
cat >>${rubybom}<<EOL
84
+
{
85
+
"bomFormat": "CycloneDX",
86
+
"specVersion": "1.3",
87
+
"version": 1,
88
+
"components": [
89
+
{
90
+
"type": "library",
91
+
"name": "ruby",
92
+
"version": "$ruby_version"
93
+
}
94
+
]
95
+
}
48
96
EOL
97
+
if [[ -f Gemfile.lock ]] ;then
98
+
forgemin$(gem dep -q | grep ^Gem | sed 's/^Gem //')
99
+
do
100
+
version=${gem##*-}
101
+
name=${gem%-${version}}
102
+
DEP=$(jq --arg name "${name}" --arg version "${version}" \
You should then be able to inspect your Ruby app for its Bill-of-Materials via:
222
+
Viewing your bill-of-materials requires first pushing the built image to a container registry and then querying the bill-of-materials. If you are a `docker` user, we can experiment with an OCI container registry by running an instance of Docker's `registry:2` (as an aside, the standard Docker daemon is a container registry, but is not fully [OCI compliant](https://opencontainers.org/)).
145
223
146
224
<!-- test:exec -->
147
225
```bash
148
-
pack inspect-image test-ruby-app --bom
226
+
docker run -d -p 5000:5000 registry:2
227
+
docker image tag test-ruby-app localhost:5000/test-ruby-app
228
+
docker push localhost:5000/test-ruby-app
229
+
pack sbom download localhost:5000/test-ruby-app
149
230
```{{execute}}
150
231
232
+
The SBOM information is now downloaded to the local file system:
You should find that the included `ruby` version is `2.5.0` as expected.
152
240
153
-
<!-- test:assert=contains -->
241
+
<!-- test:assert=contains;ignore-lines=... -->
154
242
```text
243
+
{
244
+
"bomFormat": "CycloneDX",
245
+
"specVersion": "1.3",
246
+
"version": 1,
247
+
"components": [
155
248
{
249
+
"type": "library",
156
250
"name": "ruby",
157
-
"metadata": {
158
-
"version": "2.5.0"
159
-
},
160
-
"buildpacks": {
161
-
"id": "examples/ruby",
162
-
"version": "0.0.1"
163
-
}
164
-
}
251
+
"version": "2.5.0"
252
+
},
253
+
...
254
+
]
255
+
}
165
256
```
166
257
167
258
Congratulations! You’ve created your first configurable Cloud Native Buildpack that uses detection, image layers, and caching to create an introspectable and runnable OCI image.
0 commit comments