The composer wrote every placed artifact as artifact-store://…/blobs/<digest>,
which the routing turns into a blob URL the declaration's own check refuses
("image … is not pinned"), so nats's composition was refused on the node. An
image now keeps the image seat's form, an upstream copy the reference the seat's
holder answers by name-of (kept by from; unanswered leaves the old form, said
once), and only bundles and archives take the blobs form.
Builds: design 47 H2 H-A-513, H-A-513 second addendum
115 lines
4.4 KiB
Go
115 lines
4.4 KiB
Go
package selfcompose
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/containerimageregistryclient/reference"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/containerimageregistry"
|
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
|
|
"github.com/novox/mesh-host/internal/registryforms"
|
|
)
|
|
|
|
// **An image keeps its pinned reference; only files and bundles take the blobs form** (design 47 H2 H-A-513 and its second
|
|
// addendum). A container's image must be name@digest for the declaration's own check to pass, so an artifact's reference is
|
|
// made by its kind:
|
|
// - an image's in the image seat's form, container-image-registry/<module>/<artifact>@<digest> (reference.SeatReference);
|
|
// - an upstream copy's as the image seat's holder keeps it, which the seat's verb name-of answers for the from its manifest
|
|
// pins (container-image-registry/upstream/<host>/<path>@<digest>): the holder owns that naming, so the node-engine asks it
|
|
// and repeats no rule of its own. Answers are kept by from for the process's life; an unanswered ask leaves the artifact in
|
|
// the blobs form, said once per artifact, and is asked again at the next compose;
|
|
// - a bundle's or an archive's in the form the artifact store is addressed by (the lead's answer A-50),
|
|
// artifact-store://<module>/<artifact>/blobs/<digest>.
|
|
// The resolution routes each through the registry's host as this network reaches it (resolution.artifactsInto).
|
|
|
|
// blobsReference is the artifact store's form of an artifact: artifact-store://<module>/<artifact>/blobs/<digest> (A-50).
|
|
func blobsReference(module, artifact, digest string) string {
|
|
return reference.ArtifactStoreScheme + module + "/" + artifact + "/blobs/" + digest
|
|
}
|
|
|
|
// referenceOf is the reference of module's artifact of kind at digest, m its build's manifest (nil when it cannot be read).
|
|
func (c *Composer) referenceOf(module string, m *catalogue.Manifest, kind, artifact, digest string) string {
|
|
switch kind {
|
|
case catalogue.ArtifactImage:
|
|
return reference.SeatReference(registryforms.Forms.Image, module, artifact, digest)
|
|
case catalogue.ArtifactUpstream:
|
|
from := ""
|
|
if m != nil {
|
|
from = pinnedFrom(*m, artifact)
|
|
}
|
|
named, why := c.nameOf(from)
|
|
if why == "" {
|
|
return named
|
|
}
|
|
c.sayOnceKey("name-of "+module+":"+artifact, fmt.Sprintf("%s:%s: the seat %s's verb %s names no copy of %q (%s), so its image is composed in the blobs form until it answers",
|
|
module, artifact, registryforms.Forms.Image, containerimageregistry.VerbNameOf, from, why))
|
|
}
|
|
return blobsReference(module, artifact, digest)
|
|
}
|
|
|
|
// nameOf is the reference the image seat's verb name-of answers for from, kept once answered; why says what failed.
|
|
func (c *Composer) nameOf(from string) (string, string) {
|
|
if from == "" {
|
|
return "", "the manifest pins no from for it"
|
|
}
|
|
c.mu.Lock()
|
|
named, ok := c.namedFrom[from]
|
|
c.mu.Unlock()
|
|
if ok {
|
|
return named, ""
|
|
}
|
|
if c.env.Registry == nil {
|
|
return "", "this node-engine reads no registry seat"
|
|
}
|
|
raw, err := c.env.Registry("seat:"+registryforms.Forms.Image+"."+containerimageregistry.VerbNameOf, containerimageregistry.NameOfInput{From: from})
|
|
if err != nil {
|
|
return "", fmt.Sprintf("the call failed: %v", err)
|
|
}
|
|
answer, said, ok := buscalls.Unwrap(raw)
|
|
if !ok {
|
|
return "", "the seat refused it: " + said
|
|
}
|
|
a, _, err := containerimageregistry.DecodeNameOfAnswer(answer)
|
|
if err != nil || a.Reference == "" {
|
|
return "", fmt.Sprintf("its answer names no reference: %s", strings.TrimSpace(string(answer)))
|
|
}
|
|
c.mu.Lock()
|
|
if c.namedFrom == nil {
|
|
c.namedFrom = map[string]string{}
|
|
}
|
|
c.namedFrom[from] = a.Reference
|
|
c.mu.Unlock()
|
|
return a.Reference, ""
|
|
}
|
|
|
|
// pinnedFrom is the from the manifest names artifact by, when it pins a digest; "" otherwise.
|
|
func pinnedFrom(m catalogue.Manifest, artifact string) string {
|
|
if m.Build == nil {
|
|
return ""
|
|
}
|
|
for _, a := range m.Build.Artifacts {
|
|
if a.Name == artifact {
|
|
if _, d, ok := strings.Cut(a.From, "@"); ok && strings.HasPrefix(d, "sha256:") {
|
|
return a.From
|
|
}
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// sayOnceKey says line once for key, whatever line holds each time (a reason may differ between asks).
|
|
func (c *Composer) sayOnceKey(key, line string) {
|
|
c.mu.Lock()
|
|
if c.told == nil {
|
|
c.told = map[string]bool{}
|
|
}
|
|
again := c.told[key]
|
|
c.told[key] = true
|
|
c.mu.Unlock()
|
|
if !again {
|
|
c.env.Say(line)
|
|
}
|
|
}
|