manifest: add resolved commit specs to Serialize()

Same as with package specs and container specs, the commit specs are
added to the manifest serialization after being resolved.
This commit is contained in:
Achilleas Koutsou 2023-05-31 16:55:21 +02:00 committed by Ondřej Budai
parent e05d4b4a03
commit 89a398371d
21 changed files with 101 additions and 39 deletions

View file

@ -181,7 +181,9 @@ func makeManifestJob(name string, imgType distro.ImageType, cr composeRequest, d
return fmt.Errorf("[%s] container resolution failed: %s", filename, err.Error())
}
mf, err := manifest.Serialize(packageSpecs, containerSpecs)
commitSpecs := resolvePipelineCommits(manifest.Content.OSTreeCommits)
mf, err := manifest.Serialize(packageSpecs, containerSpecs, commitSpecs)
if err != nil {
return fmt.Errorf("[%s] manifest serialization failed: %s", filename, err.Error())
}
@ -279,6 +281,23 @@ func resolvePipelineContainers(containerSources map[string][]container.SourceSpe
return containerSpecs, nil
}
func resolvePipelineCommits(commitSources map[string][]ostree.SourceSpec) map[string][]ostree.CommitSpec {
// "resolve" ostree commits by copying the source specs into commit specs
commits := make(map[string][]ostree.CommitSpec, len(commitSources))
for name, commitSources := range commitSources {
commitSpecs := make([]ostree.CommitSpec, len(commitSources))
for idx, commitSource := range commitSources {
commitSpecs[idx] = ostree.CommitSpec{
Ref: commitSource.Ref,
URL: commitSource.URL,
Checksum: commitSource.Parent,
}
}
commits[name] = commitSpecs
}
return commits
}
func depsolve(cacheDir string, packageSets map[string][]rpmmd.PackageSet, d distro.Distro, arch string) (map[string][]rpmmd.PackageSpec, error) {
solver := dnfjson.NewSolver(d.ModulePlatformID(), d.Releasever(), arch, d.Name(), cacheDir)
solver.SetDNFJSONPath("./dnf-json")

View file

@ -223,6 +223,20 @@ func main() {
containers[name] = containerSpecs
}
// "resolve" ostree commits by copying the source specs into commit specs
commits := make(map[string][]ostree.CommitSpec, len(manifest.Content.OSTreeCommits))
for name, commitSources := range manifest.Content.OSTreeCommits {
commitSpecs := make([]ostree.CommitSpec, len(commitSources))
for idx, commitSource := range commitSources {
commitSpecs[idx] = ostree.CommitSpec{
Ref: commitSource.Ref,
URL: commitSource.URL,
Checksum: commitSource.Parent,
}
}
commits[name] = commitSpecs
}
var bytes []byte
if rpmmdArg {
bytes, err = json.Marshal(depsolvedSets)
@ -230,12 +244,7 @@ func main() {
panic(err)
}
} else {
if composeRequest.OSTree.Ref == "" {
// use default OSTreeRef for image type
composeRequest.OSTree.Ref = imageType.OSTreeRef()
}
ms, err := manifest.Serialize(depsolvedSets, containers)
ms, err := manifest.Serialize(depsolvedSets, containers, commits)
if err != nil {
panic(err.Error())
}

View file

@ -48,7 +48,7 @@ func RunPlayground(img image.ImageKind, d distro.Distro, arch distro.Arch, repos
fmt.Fprintf(os.Stderr, "could not clean dnf cache: %s", err.Error())
}
bytes, err := manifest.Serialize(packageSpecs, nil)
bytes, err := manifest.Serialize(packageSpecs, nil, nil)
if err != nil {
panic("failed to serialize manifest: " + err.Error())
}

View file

@ -36,7 +36,7 @@ func getManifest(bp blueprint.Blueprint, t distro.ImageType, a distro.Arch, d di
pkgSpecSets[name] = res
}
mf, err := manifest.Serialize(pkgSpecSets, nil)
mf, err := manifest.Serialize(pkgSpecSets, nil, nil)
if err != nil {
panic(err)
}