Skip to content

Commit ff5baa0

Browse files
committed
solver: merge local and remote images into single list
This also allows us to specify that local images should be generated with exactly the same specification as remote images, but with the pkg:oci scheme instead of pkg:docker. Signed-off-by: Justin Chadwell <[email protected]>
1 parent 80ea813 commit ff5baa0

File tree

2 files changed

+14
-50
lines changed

2 files changed

+14
-50
lines changed

solver/llbsolver/provenance/capture.go

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type ImageSource struct {
1616
Ref string
1717
Platform *ocispecs.Platform
1818
Digest digest.Digest
19+
Local bool
1920
}
2021

2122
type GitSource struct {
@@ -43,11 +44,10 @@ type SSH struct {
4344
}
4445

4546
type Sources struct {
46-
Images []ImageSource
47-
LocalImages []ImageSource
48-
Git []GitSource
49-
HTTP []HTTPSource
50-
Local []LocalSource
47+
Images []ImageSource
48+
Git []GitSource
49+
HTTP []HTTPSource
50+
Local []LocalSource
5151
}
5252

5353
type Capture struct {
@@ -67,9 +67,6 @@ func (c *Capture) Merge(c2 *Capture) error {
6767
for _, i := range c2.Sources.Images {
6868
c.AddImage(i)
6969
}
70-
for _, i := range c2.Sources.LocalImages {
71-
c.AddLocalImage(i)
72-
}
7370
for _, l := range c2.Sources.Local {
7471
c.AddLocal(l)
7572
}
@@ -98,9 +95,6 @@ func (c *Capture) Sort() {
9895
sort.Slice(c.Sources.Images, func(i, j int) bool {
9996
return c.Sources.Images[i].Ref < c.Sources.Images[j].Ref
10097
})
101-
sort.Slice(c.Sources.LocalImages, func(i, j int) bool {
102-
return c.Sources.LocalImages[i].Ref < c.Sources.LocalImages[j].Ref
103-
})
10498
sort.Slice(c.Sources.Local, func(i, j int) bool {
10599
return c.Sources.Local[i].Name < c.Sources.Local[j].Name
106100
})
@@ -151,7 +145,7 @@ func (c *Capture) OptimizeImageSources() error {
151145

152146
func (c *Capture) AddImage(i ImageSource) {
153147
for _, v := range c.Sources.Images {
154-
if v.Ref == i.Ref {
148+
if v.Ref == i.Ref && v.Local == i.Local {
155149
if v.Platform == i.Platform {
156150
return
157151
}
@@ -165,22 +159,6 @@ func (c *Capture) AddImage(i ImageSource) {
165159
c.Sources.Images = append(c.Sources.Images, i)
166160
}
167161

168-
func (c *Capture) AddLocalImage(i ImageSource) {
169-
for _, v := range c.Sources.LocalImages {
170-
if v.Ref == i.Ref {
171-
if v.Platform == i.Platform {
172-
return
173-
}
174-
if v.Platform != nil && i.Platform != nil {
175-
if v.Platform.Architecture == i.Platform.Architecture && v.Platform.OS == i.Platform.OS && v.Platform.Variant == i.Platform.Variant {
176-
return
177-
}
178-
}
179-
}
180-
}
181-
c.Sources.LocalImages = append(c.Sources.LocalImages, i)
182-
}
183-
184162
func (c *Capture) AddLocal(l LocalSource) {
185163
for _, v := range c.Sources.Local {
186164
if v.Name == l.Name {

solver/llbsolver/provenance/predicate.go

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,17 @@ type BuildKitMetadata struct {
5656
}
5757

5858
func slsaMaterials(srcs Sources) ([]slsa.ProvenanceMaterial, error) {
59-
count := len(srcs.Images) + len(srcs.Git) + len(srcs.HTTP) + len(srcs.LocalImages)
59+
count := len(srcs.Images) + len(srcs.Git) + len(srcs.HTTP)
6060
out := make([]slsa.ProvenanceMaterial, 0, count)
6161

6262
for _, s := range srcs.Images {
63-
uri, err := purl.RefToPURL(packageurl.TypeDocker, s.Ref, s.Platform)
63+
var uri string
64+
var err error
65+
if s.Local {
66+
uri, err = purl.RefToPURL(packageurl.TypeOCI, s.Ref, s.Platform)
67+
} else {
68+
uri, err = purl.RefToPURL(packageurl.TypeDocker, s.Ref, s.Platform)
69+
}
6470
if err != nil {
6571
return nil, err
6672
}
@@ -93,26 +99,6 @@ func slsaMaterials(srcs Sources) ([]slsa.ProvenanceMaterial, error) {
9399
})
94100
}
95101

96-
for _, s := range srcs.LocalImages {
97-
q := []packageurl.Qualifier{}
98-
if s.Platform != nil {
99-
q = append(q, packageurl.Qualifier{
100-
Key: "platform",
101-
Value: platforms.Format(*s.Platform),
102-
})
103-
}
104-
packageurl.NewPackageURL(packageurl.TypeOCI, "", s.Ref, "", q, "")
105-
106-
material := slsa.ProvenanceMaterial{
107-
URI: s.Ref,
108-
}
109-
if s.Digest != "" {
110-
material.Digest = slsa.DigestSet{
111-
s.Digest.Algorithm().String(): s.Digest.Hex(),
112-
}
113-
}
114-
out = append(out, material)
115-
}
116102
return out, nil
117103
}
118104

0 commit comments

Comments
 (0)