osbuild/skopeo: helper function for files input

Add a helper function that collects all the manifest list digests from a
list of container specs and returns a FilesInput to be used with the
stage.

Use the function in the OS pipeline when adding containers.  The
manifests input to the stage constructor will be empty if there are no
manifest lists in the container specs.
This commit is contained in:
Achilleas Koutsou 2023-03-17 16:07:40 +01:00
parent 753bcaed78
commit d41a74475e
4 changed files with 24 additions and 3 deletions

View file

@ -352,7 +352,8 @@ func (p *OS) serialize() osbuild.Pipeline {
pipeline.AddStage(osbuild.NewContainersStorageConfStage(containerStoreOpts))
}
skopeo := osbuild.NewSkopeoStage(storagePath, images, nil)
manifests := osbuild.NewFilesInputForManifestLists(p.Containers)
skopeo := osbuild.NewSkopeoStage(storagePath, images, manifests)
pipeline.AddStage(skopeo)
}

View file

@ -3,6 +3,8 @@ package osbuild
import (
"encoding/json"
"fmt"
"github.com/osbuild/osbuild-composer/internal/container"
)
// SPECIFIC INPUT STRUCTURE
@ -276,3 +278,19 @@ func NewFilesInputSourceObjectRef(entries map[string]FilesInputRefMetadata) File
}
return &refs
}
// NewFilesInputForManifestLists creates a FilesInput for container manifest
// lists. If there are no list digests in the container specs, it returns nil.
func NewFilesInputForManifestLists(containers []container.Spec) *FilesInput {
refs := make([]string, 0, len(containers))
for _, c := range containers {
if c.ListDigest != "" {
refs = append(refs, c.ListDigest)
}
}
if len(refs) == 0 {
return nil
}
filesRef := FilesInputSourcePlainRef(refs)
return NewFilesInput(&filesRef)
}

View file

@ -11327,7 +11327,8 @@
"Digest": "sha256:4d76a7480ce1861c95975945633dc9d03807ffb45c64b664ef22e673798d414b",
"TLSVerify": null,
"ImageID": "sha256:d4ee87dab8193afad523b1042b9d3f5ec887555a704e5aaec2876798ebb585a6",
"LocalName": "registry.gitlab.com/redhat/services/products/image-builder/ci/osbuild-composer/fedora-minimal"
"LocalName": "registry.gitlab.com/redhat/services/products/image-builder/ci/osbuild-composer/fedora-minimal",
"ListDigest": ""
}
],
"no-image-info": true

View file

@ -11827,7 +11827,8 @@
"Digest": "sha256:4d76a7480ce1861c95975945633dc9d03807ffb45c64b664ef22e673798d414b",
"TLSVerify": null,
"ImageID": "sha256:d4ee87dab8193afad523b1042b9d3f5ec887555a704e5aaec2876798ebb585a6",
"LocalName": "registry.gitlab.com/redhat/services/products/image-builder/ci/osbuild-composer/fedora-minimal"
"LocalName": "registry.gitlab.com/redhat/services/products/image-builder/ci/osbuild-composer/fedora-minimal",
"ListDigest": ""
}
],
"no-image-info": true