Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit f0e2deb

Browse files
committed
Update packages and hide generic packages that are already covered
1 parent 6e87f80 commit f0e2deb

File tree

7 files changed

+515
-18
lines changed

7 files changed

+515
-18
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# build stage
2-
FROM golang:1.19-alpine3.16@sha256:0eb08c89ab1b0c638a9fe2780f7ae3ab18f6ecda2c76b908e09eb8073912045d as build
2+
FROM golang:1.20-alpine3.17 as build
33

44
RUN apk add --no-cache git build-base ca-certificates
55

go.mod

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
module github.com/docker/index-cli-plugin
22

3-
go 1.19
3+
go 1.20
44

55
require (
66
github.com/Microsoft/go-winio v0.6.0
77
github.com/anchore/packageurl-go v0.1.1-0.20230104203445-02e0a6721501
8-
github.com/anchore/stereoscope v0.0.0-20230222185948-fab1c9638abc
9-
github.com/anchore/syft v0.73.0
8+
github.com/anchore/stereoscope v0.0.0-20230301191755-abfb374a1122
9+
github.com/anchore/syft v0.74.1
1010
github.com/aquasecurity/trivy v0.30.4
1111
github.com/atomist-skills/go-skill v0.0.6-0.20221221214636-a7de163fd901
1212
github.com/briandowns/spinner v1.12.0
@@ -161,11 +161,11 @@ require (
161161
github.com/shogo82148/go-shuffle v0.0.0-20170808115208-59829097ff3b // indirect
162162
github.com/shopspring/decimal v1.2.0 // indirect
163163
github.com/spdx/tools-golang v0.5.0-rc1 // indirect
164-
github.com/spf13/afero v1.9.3 // indirect
164+
github.com/spf13/afero v1.9.5 // indirect
165165
github.com/spf13/cast v1.5.0 // indirect
166166
github.com/spf13/pflag v1.0.5 // indirect
167167
github.com/stretchr/objx v0.5.0 // indirect
168-
github.com/stretchr/testify v1.8.1 // indirect
168+
github.com/stretchr/testify v1.8.2 // indirect
169169
github.com/sylabs/sif/v2 v2.8.1 // indirect
170170
github.com/sylabs/squashfs v0.6.1 // indirect
171171
github.com/therootcompany/xz v1.0.1 // indirect
@@ -175,7 +175,7 @@ require (
175175
github.com/vbatts/tar-split v0.11.2 // indirect
176176
github.com/vifraa/gopom v0.2.1 // indirect
177177
github.com/wagoodman/go-partybus v0.0.0-20210627031916-db1f5573bbc5 // indirect
178-
github.com/wagoodman/go-progress v0.0.0-20200731105512-1020f39e6240 // indirect
178+
github.com/wagoodman/go-progress v0.0.0-20230301185719-21920a456ad5 // indirect
179179
github.com/xanzy/ssh-agent v0.3.0 // indirect
180180
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
181181
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
@@ -186,14 +186,14 @@ require (
186186
go.uber.org/zap v1.23.0 // indirect
187187
golang.org/x/crypto v0.3.0 // indirect
188188
golang.org/x/exp v0.0.0-20230202163644-54bba9f4231b // indirect
189-
golang.org/x/mod v0.8.0 // indirect
190-
golang.org/x/net v0.7.0 // indirect
189+
golang.org/x/mod v0.9.0 // indirect
190+
golang.org/x/net v0.8.0 // indirect
191191
golang.org/x/oauth2 v0.1.0 // indirect
192192
golang.org/x/sync v0.1.0 // indirect
193-
golang.org/x/sys v0.5.0 // indirect
194-
golang.org/x/term v0.5.0 // indirect
195-
golang.org/x/text v0.7.0 // indirect
196-
golang.org/x/tools v0.2.0 // indirect
193+
golang.org/x/sys v0.6.0 // indirect
194+
golang.org/x/term v0.6.0 // indirect
195+
golang.org/x/text v0.8.0 // indirect
196+
golang.org/x/tools v0.6.0 // indirect
197197
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
198198
gonum.org/v1/gonum v0.7.0 // indirect
199199
google.golang.org/appengine v1.6.7 // indirect

go.sum

Lines changed: 424 additions & 0 deletions
Large diffs are not rendered by default.

sbom/detect/detect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type PackageDetector = func(packages []types.Package, image *source.Source, lm *
3434
var detectors []PackageDetector
3535

3636
func init() {
37-
detectors = []PackageDetector{nodePackageDetector()}
37+
detectors = []PackageDetector{}
3838
}
3939

4040
func AdditionalPackages(packages []types.Package, image *source.Source, lm *types.LayerMapping) []types.Package {

sbom/detect/python.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright © 2022 Docker, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package detect
18+
19+
import (
20+
"regexp"
21+
22+
"github.com/docker/index-cli-plugin/types"
23+
)
24+
25+
func pythonPackageDetector() PackageDetector {
26+
expr := regexp.MustCompile("libpython(.*)\\.so\\.")
27+
pkg := types.Package{
28+
Type: "github",
29+
Namespace: "python",
30+
Name: "python",
31+
Author: "Python Project",
32+
Description: "Python runtime",
33+
Licenses: []string{"PSF"},
34+
Url: "https://python.org",
35+
}
36+
filter := func(purl string) bool {
37+
pkg, _ := types.ToPackageUrl(purl)
38+
return pkg.Name == "python"
39+
}
40+
return stringsNodeDetector("python", "PYTHON_VERSION", expr, pkg, filter)
41+
}

sbom/index.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func IndexPath(path string, name string, cli command.Cli) (*types.Sbom, error) {
8181
func IndexImage(image string, options IndexOptions) (*types.Sbom, error) {
8282
if strings.HasPrefix(image, "sha256:") {
8383
configFilePath := options.Cli.ConfigFile().Filename
84-
sbomFilePath := filepath.Join(filepath.Dir(configFilePath), "sbom", "sha256", image[7:], "sbom.json")
84+
sbomFilePath := filepath.Join(filepath.Dir(configFilePath), "scout", "sbom", "sha256", image[7:], "sbom.json")
8585
if sbom := cachedSbom(sbomFilePath); sbom != nil {
8686
return sbom, nil
8787
}
@@ -95,7 +95,7 @@ func IndexImage(image string, options IndexOptions) (*types.Sbom, error) {
9595

9696
func indexImage(cache *registry.ImageCache, cli command.Cli) (*types.Sbom, error) {
9797
configFilePath := cli.ConfigFile().Filename
98-
sbomFilePath := filepath.Join(filepath.Dir(configFilePath), "sbom", "sha256", cache.Id[7:], "sbom.json")
98+
sbomFilePath := filepath.Join(filepath.Dir(configFilePath), "scout", "sbom", "sha256", cache.Id[7:], "sbom.json")
9999
if sbom := cachedSbom(sbomFilePath); sbom != nil {
100100
return sbom, nil
101101
}
@@ -136,7 +136,7 @@ func indexImage(cache *registry.ImageCache, cli command.Cli) (*types.Sbom, error
136136
return nil, errors.Wrapf(err, "failed to normalize packages: %s", cache.Name)
137137
}
138138

139-
packages := types.MergePackages(syftResult, trivyResult)
139+
packages := types.FilterGenericPackages(types.MergePackages(syftResult, trivyResult))
140140

141141
s.Stop()
142142
skill.Log.Infof(`Indexed %d packages`, len(packages))

types/purl.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"strings"
2323

2424
"github.com/anchore/packageurl-go"
25-
2625
"github.com/atomist-skills/go-skill"
2726
)
2827

@@ -203,6 +202,39 @@ func MergePackages(results ...IndexResult) []Package {
203202
return packages
204203
}
205204

205+
func FilterGenericPackages(packages []Package) []Package {
206+
pkgs := make([]Package, 0)
207+
genericPkgs := make([]Package, 0)
208+
for _, pkg := range packages {
209+
if pkg.Type != "generic" {
210+
pkgs = append(pkgs, pkg)
211+
} else {
212+
genericPkgs = append(genericPkgs, pkg)
213+
}
214+
}
215+
for _, pkg := range genericPkgs {
216+
found := false
217+
for _, loc := range pkg.Locations {
218+
for _, p := range pkgs {
219+
if containsLocation(p.Locations, loc.Path) || containsLocation(p.Files, loc.Path) {
220+
found = true
221+
}
222+
}
223+
}
224+
for _, loc := range pkg.Files {
225+
for _, p := range pkgs {
226+
if containsLocation(p.Locations, loc.Path) || containsLocation(p.Files, loc.Path) {
227+
found = true
228+
}
229+
}
230+
}
231+
if !found {
232+
pkgs = append(pkgs, pkg)
233+
}
234+
}
235+
return pkgs
236+
}
237+
206238
func containsPackage(packages *[]Package, pkg Package) (int, bool) {
207239
for i, p := range *packages {
208240
if p.Purl == pkg.Purl {

0 commit comments

Comments
 (0)