gen-manifests: use sha256 to fake ostree ref resolution
When a test manifest requires a commit to be resolved for content, fake the commit ID resolution deterministically by hashing the URL + ref. Store the resolved commit spec with the manifest metadata alongside the other content (packages and containers). Also add the secrets field if RHSM is true, which is now supposed to be done by the resolver.
This commit is contained in:
parent
7d1ee88700
commit
a9350d1098
1 changed files with 21 additions and 9 deletions
|
|
@ -8,6 +8,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
|
@ -192,7 +193,7 @@ func makeManifestJob(name string, imgType distro.ImageType, cr composeRequest, d
|
|||
Blueprint: cr.Blueprint,
|
||||
OSTree: cr.OSTree,
|
||||
}
|
||||
err = save(mf, packageSpecs, containerSpecs, request, path, filename)
|
||||
err = save(mf, packageSpecs, containerSpecs, commitSpecs, request, path, filename)
|
||||
return
|
||||
}
|
||||
return job
|
||||
|
|
@ -276,17 +277,27 @@ func resolvePipelineContainers(containerSources map[string][]container.SourceSpe
|
|||
return containerSpecs, nil
|
||||
}
|
||||
|
||||
func resolveCommit(commitSource ostree.SourceSpec) ostree.CommitSpec {
|
||||
// "resolve" ostree commits by hashing the URL + ref to create a
|
||||
// realistic-looking commit ID in a deterministic way
|
||||
checksum := fmt.Sprintf("%x", sha256.Sum256([]byte(commitSource.URL+commitSource.Ref)))
|
||||
spec := ostree.CommitSpec{
|
||||
Ref: commitSource.Ref,
|
||||
URL: commitSource.URL,
|
||||
Checksum: checksum,
|
||||
}
|
||||
if commitSource.RHSM {
|
||||
spec.Secrets = "org.osbuild.rhsm.consumer"
|
||||
}
|
||||
return spec
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
commitSpecs[idx] = resolveCommit(commitSource)
|
||||
}
|
||||
commits[name] = commitSpecs
|
||||
}
|
||||
|
|
@ -307,15 +318,16 @@ func depsolve(cacheDir string, packageSets map[string][]rpmmd.PackageSet, d dist
|
|||
return depsolvedSets, nil
|
||||
}
|
||||
|
||||
func save(ms manifest.OSBuildManifest, pkgs map[string][]rpmmd.PackageSpec, containers map[string][]container.Spec, cr composeRequest, path, filename string) error {
|
||||
func save(ms manifest.OSBuildManifest, pkgs map[string][]rpmmd.PackageSpec, containers map[string][]container.Spec, commits map[string][]ostree.CommitSpec, cr composeRequest, path, filename string) error {
|
||||
data := struct {
|
||||
ComposeRequest composeRequest `json:"compose-request"`
|
||||
Manifest manifest.OSBuildManifest `json:"manifest"`
|
||||
RPMMD map[string][]rpmmd.PackageSpec `json:"rpmmd"`
|
||||
Containers map[string][]container.Spec `json:"containers,omitempty"`
|
||||
OSTreeCommits map[string][]ostree.CommitSpec `json:"ostree-commits,omitempty"`
|
||||
NoImageInfo bool `json:"no-image-info"`
|
||||
}{
|
||||
cr, ms, pkgs, containers, true,
|
||||
cr, ms, pkgs, containers, commits, true,
|
||||
}
|
||||
b, err := json.MarshalIndent(data, "", " ")
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue