osbuild: add skopeo-index source
New osbuild source that can download a manifest-list from a container registry, using the `--multi-arch=index-only` option of skopeo copy.
This commit is contained in:
parent
ad2a5bff7c
commit
069021093c
1 changed files with 57 additions and 0 deletions
57
internal/osbuild/skopeo_index_source.go
Normal file
57
internal/osbuild/skopeo_index_source.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package osbuild
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SkopeoIndexSource struct {
|
||||
Items map[string]SkopeoIndexSourceItem `json:"items"`
|
||||
}
|
||||
|
||||
func (SkopeoIndexSource) isSource() {}
|
||||
|
||||
type SkopeoIndexSourceImage struct {
|
||||
Name string `json:"name"`
|
||||
TLSVerify *bool `json:"tls-verify,omitempty"`
|
||||
}
|
||||
|
||||
type SkopeoIndexSourceItem struct {
|
||||
Image SkopeoIndexSourceImage `json:"image"`
|
||||
}
|
||||
|
||||
func (item SkopeoIndexSourceItem) validate() error {
|
||||
|
||||
if item.Image.Name == "" {
|
||||
return fmt.Errorf("source item has empty name")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewSkopeoIndexSource creates a new and empty SkopeoIndexSource
|
||||
func NewSkopeoIndexSource() *SkopeoIndexSource {
|
||||
return &SkopeoIndexSource{
|
||||
Items: make(map[string]SkopeoIndexSourceItem),
|
||||
}
|
||||
}
|
||||
|
||||
// AddItem adds a source item to the source; will panic
|
||||
// if any of the supplied options are invalid or missing
|
||||
func (source *SkopeoIndexSource) AddItem(name, image string, tlsVerify *bool) {
|
||||
item := SkopeoIndexSourceItem{
|
||||
Image: SkopeoIndexSourceImage{
|
||||
Name: name,
|
||||
TLSVerify: tlsVerify,
|
||||
},
|
||||
}
|
||||
|
||||
if err := item.validate(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !skopeoDigestPattern.MatchString(image) {
|
||||
panic("item has invalid image id")
|
||||
}
|
||||
|
||||
source.Items[image] = item
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue