Compute the source fingerprint with mesh-sdk's one function (issue 1214)
This commit is contained in:
+21
-27
@@ -10,6 +10,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/delivery"
|
||||
"github.com/novox/mesh-controller/internal/catalogue"
|
||||
)
|
||||
|
||||
@@ -36,7 +37,7 @@ import (
|
||||
// (novox/hq ADR 0097 refuses the unpinned bases; what a RUN step downloads is not seen here).
|
||||
|
||||
// sourcePrefix names the fingerprint's form, so a later form is never compared equal to this one.
|
||||
const sourcePrefix = "src1:"
|
||||
const sourcePrefix = delivery.SourcePrefix
|
||||
|
||||
// sourceInputs collects what one build was made from.
|
||||
type sourceInputs struct {
|
||||
@@ -262,40 +263,33 @@ func (s *sourceInputs) notPinned(why string) {
|
||||
}
|
||||
}
|
||||
|
||||
// sourceFingerprint is the one function the controller's builder and the indexer both call (novox/hq ADR 0437 §5);
|
||||
// a variable only so a test can see it called.
|
||||
var sourceFingerprint = delivery.SourceFingerprint
|
||||
|
||||
// inputs are what the build's fingerprint is of, as the SDK names them.
|
||||
func (s *sourceInputs) inputs() delivery.SourceInputs {
|
||||
if s == nil {
|
||||
return delivery.SourceInputs{}
|
||||
}
|
||||
return delivery.SourceInputs{
|
||||
Module: s.module, Tree: s.tree, Bases: s.bases,
|
||||
Contexts: s.contexts, Toolchains: s.toolchains, Unpinned: s.unpinned,
|
||||
}
|
||||
}
|
||||
|
||||
// fingerprint is the build's source fingerprint, or empty when the source does not pin the build.
|
||||
func (s *sourceInputs) fingerprint() string {
|
||||
if s == nil || s.unpinned != "" || s.tree == "" {
|
||||
if s == nil {
|
||||
return ""
|
||||
}
|
||||
var lines []string
|
||||
lines = append(lines, "module "+s.module, "tree "+s.tree)
|
||||
bases := map[string]bool{}
|
||||
for _, b := range s.bases {
|
||||
bases[referenceDigest(b)] = true
|
||||
}
|
||||
for b := range bases {
|
||||
lines = append(lines, "base "+b)
|
||||
}
|
||||
for a, t := range s.contexts {
|
||||
lines = append(lines, "context "+a+" "+t)
|
||||
}
|
||||
for a, t := range s.toolchains {
|
||||
lines = append(lines, "toolchain "+a+" "+t)
|
||||
}
|
||||
// The module and its tree first, the rest in a fixed order.
|
||||
sort.Strings(lines[2:])
|
||||
sum := sha256.Sum256([]byte(strings.Join(lines, "\n")))
|
||||
return sourcePrefix + hex.EncodeToString(sum[:])
|
||||
fp, _ := sourceFingerprint(s.inputs())
|
||||
return fp
|
||||
}
|
||||
|
||||
// referenceDigest is a reference's digest — `sha256:…` — so the registry address it was copied into does not
|
||||
// enter the fingerprint; the reference itself when it carries none.
|
||||
func referenceDigest(reference string) string {
|
||||
if _, digest, pinned := strings.Cut(reference, "@"); pinned && digest != "" {
|
||||
return digest
|
||||
}
|
||||
return reference
|
||||
}
|
||||
func referenceDigest(reference string) string { return delivery.ReferenceDigest(reference) }
|
||||
|
||||
// gitTree is the git tree of a directory of a clone at its checked-out commit: the whole tree for an
|
||||
// empty path.
|
||||
|
||||
Reference in New Issue
Block a user