From 9c91854d3bf148af512b65970e9f257669731ffb Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 02:06:39 +0100 Subject: [PATCH] The node-engine keeps an image's pinned reference; the blobs form is for files and bundles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The composer wrote every placed artifact as artifact-store://…/blobs/, 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 --- internal/nodegrant/testdata/node.json | 1 + internal/selfcompose/entries.go | 14 ++-- internal/selfcompose/references.go | 114 ++++++++++++++++++++++++++ internal/selfcompose/selfcompose.go | 8 +- internal/selfcompose/versions.go | 13 +-- internal/selfcompose/versions_test.go | 79 ++++++++++++++++-- module.json | 1 + 7 files changed, 202 insertions(+), 28 deletions(-) create mode 100644 internal/selfcompose/references.go diff --git a/internal/nodegrant/testdata/node.json b/internal/nodegrant/testdata/node.json index e31dcc1c..1bf87c3c 100644 --- a/internal/nodegrant/testdata/node.json +++ b/internal/nodegrant/testdata/node.json @@ -117,6 +117,7 @@ "mesh.control.NODE.>", "mesh.seat.mesh-catalog.call.entry.node~NODE", "mesh.seat.mesh-catalog.call.module.node~NODE", + "mesh.seat.container-image-registry.call.name-of.node~NODE", "mesh.seat.container-image-registry.call.versions.node~NODE", "mesh.seat.mesh-catalog.call.revision.node~NODE", "mesh.seat.mesh-grants.call.withheld.node~NODE", diff --git a/internal/selfcompose/entries.go b/internal/selfcompose/entries.go index 2be77ef8..0f964b9f 100644 --- a/internal/selfcompose/entries.go +++ b/internal/selfcompose/entries.go @@ -33,7 +33,7 @@ import ( // state `composed-` beside the compositions (`entry.`, the entry as `entry` answers it), with each want it // composes from (`want.`), written whole before the composition that uses them and read at its start before it asks // anything. A module's manifest is the entry's, and each artifact's reference is made from the digest its want's parts name -// (referenceOf), so it reads neither the indexer's states nor the builder's. +// (referenceOf; an upstream copy's named by the image seat's verb name-of), so it reads neither the indexer's states nor the builder's. // The keys of the kept entries and wants in the composition state. const ( @@ -773,12 +773,6 @@ func (c *Composer) entryHolds() map[string]string { return out } -// referenceOf is an artifact's reference made from the digest its want's part names, or its version resolves (A-430a), in the form the artifact store is -// addressed by (the lead's answer A-50): artifact-store:////blobs/. -func referenceOf(module, artifact, digest string) string { - return "artifact-store://" + module + "/" + artifact + "/blobs/" + digest -} - // buildOf is the build a want names, made from the entry the composer holds and the parts of the want (the builder's done key is // not read, §421, §628): done, with each placed artifact of the entry (no package, H-A-466) at the digest its part names and the reference made from it. Nil // where the entry is not held, the want names another fingerprint, or a part is missing. The shadow's wants for the modules a @@ -803,6 +797,10 @@ func (c *Composer) buildOf(module, fp string) *builds.BuilderBuild { c.manifests[digest] = raw c.mu.Unlock() b := builds.BuilderBuild{State: builds.BuildDone, Manifest: digest} + var manifest *catalogue.Manifest + if m, err := catalogue.Decode(raw); err == nil { + manifest = &m + } for _, a := range k.entry.Artifacts { if !placed(a.Kind) { continue // a package is no part of what the node composes (H-A-466) @@ -810,7 +808,7 @@ func (c *Composer) buildOf(module, fp string) *builds.BuilderBuild { _, name, _ := strings.Cut(a.Ref, ":") digest := parts[a.Ref] b.Artifacts = append(b.Artifacts, builds.BuiltArtifact{Name: name, Kind: a.Kind, Digest: digest, - Reference: referenceOf(module, name, digest)}) + Reference: c.referenceOf(module, manifest, a.Kind, name, digest)}) } return &b } diff --git a/internal/selfcompose/references.go b/internal/selfcompose/references.go new file mode 100644 index 00000000..f93f0a96 --- /dev/null +++ b/internal/selfcompose/references.go @@ -0,0 +1,114 @@ +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//@ (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//@): 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:////blobs/. +// 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:////blobs/ (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) + } +} diff --git a/internal/selfcompose/selfcompose.go b/internal/selfcompose/selfcompose.go index 4c7d33ba..e0e7f896 100644 --- a/internal/selfcompose/selfcompose.go +++ b/internal/selfcompose/selfcompose.go @@ -158,7 +158,8 @@ type Env struct { // the compose call's own (H-A-458 (3)). Taken func(ctx context.Context, seat, ask string, bound time.Duration) (bool, error) // Registry asks the registry seats' verb versions (oci-artifact-registry, container-image-registry) in the engine's own - // name: a want naming its version is resolved to its artifacts' digests through it (design 47 G A-430a). + // name: a want naming its version is resolved to its artifacts' digests through it (design 47 G A-430a); and the image + // seat's verb name-of, which names an upstream copy (design 47 H2 H-A-513 second addendum). Registry meshcatalogclient.Call } @@ -234,7 +235,10 @@ type Composer struct { // unanswered is each fingerprint whose entry-unanswered the composer told, so it is told once and cleared once. unanswered map[string]bool // resolved is each wanted build's digests as its version resolved them through the registry seats (versions.go, A-430a). - resolved map[resolvedKey]versionParts + resolved map[resolvedKey]versionParts + // namedFrom is each upstream copy's reference the image seat's verb name-of answered, by the from a manifest pins it by, kept + // for the process's life: a cache of what the seat answers (design 47 H2 H-A-513 second addendum, references.go). + namedFrom map[string]string keptWantVal map[string]keptWant keptWants map[string]bool keptWrite sync.Mutex diff --git a/internal/selfcompose/versions.go b/internal/selfcompose/versions.go index 402d17f6..460ec40b 100644 --- a/internal/selfcompose/versions.go +++ b/internal/selfcompose/versions.go @@ -268,15 +268,6 @@ func (c *Composer) versionDigest(seat, name string, w meshwants.WantsByWantNodeM // pinnedDigest is the digest the manifest's upstream artifact pins in its from (`@sha256:`); "" when none. func pinnedDigest(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 d - } - } - } - return "" + _, d, _ := strings.Cut(pinnedFrom(m, artifact), "@") + return d } diff --git a/internal/selfcompose/versions_test.go b/internal/selfcompose/versions_test.go index 68084554..e6741b33 100644 --- a/internal/selfcompose/versions_test.go +++ b/internal/selfcompose/versions_test.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "encoding/json" "errors" + "reflect" "runtime" "strings" "sync" @@ -13,15 +14,18 @@ import ( "time" "github.com/novox/mesh-host/internal/agent" + "github.com/novox/mesh-host/internal/compose/resolution" "github.com/novox/mesh-host/internal/nodegrant" "github.com/novox/mesh-host/internal/takein" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds" "git.novox.be/novox/mesh-sdk/go/catalogue" + "git.novox.be/novox/mesh-sdk/go/declaration" "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/containerimageregistry" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" "git.novox.be/novox/mesh-networking/modules/mesh-connectivity-contracts/go/seats/nodepacketfilter" @@ -34,7 +38,10 @@ import ( func aWantNamingItsVersionIsResolvedThroughTheRegistrySeats(t *testing.T) { fp := meshcatalogclient.SourcePrefix2 + strings.Repeat("a", 64) d := func(c string) string { return "sha256:" + strings.Repeat(c, 64) } - manifest := map[string]any{"module": "mail", "version": "1", "build": map[string]any{"artifacts": []any{ + manifest := map[string]any{"module": "mail", "version": "1", "resources": []any{ + map[string]any{"id": "server", "type": "container", "name": "mesh-mail", "artifact": "server"}, + map[string]any{"id": "web", "type": "container", "name": "mesh-mail-web", "artifact": "web"}, + }, "build": map[string]any{"artifacts": []any{ map[string]any{"name": "server", "kind": "upstream", "from": "alpine@" + d("9")}, map[string]any{"name": "files", "kind": "archive", "from": "files"}, map[string]any{"name": "web", "kind": "image", "from": "Dockerfile"}, @@ -67,21 +74,42 @@ func aWantNamingItsVersionIsResolvedThroughTheRegistrySeats(t *testing.T) { // pkg names a package artifact the builder's done key carries with no reference beside what the build made: the key // frombus hands takein.Manifest (H-A-466). pkg string + // refs is each artifact's reference the build names, by artifact reference (design 47 H2 H-A-513 second addendum). + refs map[string]string + // nameOfDown makes the image seat's verb name-of fail: the upstream copy keeps the blobs form, said once. + nameOfDown bool }{ "resolved": {want: meshwants.WantsByWantNodeModuleValue{Fp: fp, Version: "1.2.3", Self: true}, - parts: map[string]string{"mail:server": d("9"), "mail:files": d("1"), "mail:web": d("3")}}, + parts: map[string]string{"mail:server": d("9"), "mail:files": d("1"), "mail:web": d("3")}, + refs: map[string]string{"mail:server": "container-image-registry/upstream/docker.io/library/alpine@" + d("9"), + "mail:files": "artifact-store://mail/files/blobs/" + d("1"), "mail:web": "container-image-registry/mail/web@" + d("3")}}, + "name-of unanswered": {want: meshwants.WantsByWantNodeModuleValue{Fp: fp, Version: "1.2.3", Self: true}, nameOfDown: true, + parts: map[string]string{"mail:server": d("9"), "mail:files": d("1"), "mail:web": d("3")}, + refs: map[string]string{"mail:server": "artifact-store://mail/server/blobs/" + d("9"), + "mail:files": "artifact-store://mail/files/blobs/" + d("1"), "mail:web": "container-image-registry/mail/web@" + d("3")}}, "a version a seat does not hold": {want: meshwants.WantsByWantNodeModuleValue{Fp: fp, Version: "2.0.0", Self: true}, missing: "2.0.0", said: []string{"mail at version 2.0.0", "oci-artifact-registry", "container-image-registry"}}, "a seat that does not answer": {want: meshwants.WantsByWantNodeModuleValue{Fp: fp, Version: "1.2.3", Self: true}, down: "container-image-registry", missing: "mail:web", said: []string{"mail at version 1.2.3: the seat container-image-registry"}}, "a package artifact": {want: meshwants.WantsByWantNodeModuleValue{Fp: fpPkg, Version: "1.2.3", Self: true}, entry: &withPackage, - parts: map[string]string{"mail:tools": d("4")}, pkg: "mailapi"}, + parts: map[string]string{"mail:tools": d("4")}, pkg: "mailapi", + refs: map[string]string{"mail:tools": "artifact-store://mail/tools/blobs/" + d("4")}}, } { var mu sync.Mutex var said []string env := Env{Say: func(line string) { mu.Lock(); said = append(said, line); mu.Unlock() }} - calls := 0 + calls, named := 0, 0 env.Registry = EntryCall(func(_ context.Context, seat, verb string, args any) (json.RawMessage, error) { + if seat == "container-image-registry" && verb == "name-of" { + // The holder's own naming of an upstream copy (distribution's ParseSource), as the seat answers it. + named++ + from := args.(containerimageregistry.NameOfInput).From + name, digest, _ := strings.Cut(from, "@") + if row.nameOfDown || !strings.HasPrefix(digest, "sha256:") { + return nil, errors.New("no responders") + } + return json.RawMessage(`{"reference":"container-image-registry/upstream/docker.io/library/` + name + `@` + digest + `"}`), nil + } calls++ if verb != "versions" { t.Errorf("%s: asked %s.%s", name, seat, verb) @@ -164,8 +192,45 @@ func aWantNamingItsVersionIsResolvedThroughTheRegistrySeats(t *testing.T) { } } for _, a := range b.Artifacts { - if a.Digest != row.parts["mail:"+a.Name] || a.Reference != referenceOf("mail", a.Name, a.Digest) { - t.Errorf("%s: artifact %+v", name, a) + if a.Digest != row.parts["mail:"+a.Name] || a.Reference != row.refs["mail:"+a.Name] { + t.Errorf("%s: artifact %+v, want the reference %s", name, a, row.refs["mail:"+a.Name]) + } + } + // The upstream copy's name is asked once and kept (by its from); an unanswered ask is said once and asked again. + again := c.buildOf("mail", entry.Fp) + if again == nil || !reflect.DeepEqual(again.Artifacts, b.Artifacts) { + t.Errorf("%s: the build made again is %+v, want %+v", name, again, b.Artifacts) + } + if upstream := row.refs["mail:server"] != ""; upstream && !row.nameOfDown && named != 1 || upstream && row.nameOfDown && named != 2 { + t.Errorf("%s: name-of asked %d times", name, named) + } + if n := strings.Count(strings.Join(said, "\n"), `mail:server: the seat container-image-registry's verb name-of names no copy of "alpine@`); row.nameOfDown && n != 1 { + t.Errorf("%s: the unanswered name-of is said %d times, want once: %q", name, n, said) + } + // What the node composes from the build passes the declaration's own check: each container's image is pinned, + // name@digest through the registry's host (H-A-513); the blobs form is a file's, never an image's. + if row.refs["mail:server"] != "" && !row.nameOfDown { + taken, err := takein.Manifest(context.Background(), m, *b, nil) + if err != nil { + t.Fatalf("%s: %v", name, err) + } + out, err := resolution.Declaration(catalogue.Resolution{Node: "anchor", Modules: []catalogue.Manifest{taken}}, + catalogue.Rendering{ArtifactStore: "anchor.internal:5100"}) + if err != nil { + t.Fatalf("%s: %v", name, err) + } + images := map[string]any{} + for _, r := range out { + if r["type"] == "container" { + images[r["id"].(string)] = r["image"] + } + } + if images["mail.server"] != "anchor.internal:5100/upstream/docker.io/library/alpine@"+d("9") || images["mail.web"] != "anchor.internal:5100/mail/web@"+d("3") { + t.Errorf("%s: the containers' images are %v", name, images) + } + raw, _ := json.Marshal(map[string]any{"declaration": 1, "resources": out}) + if _, err := declaration.Parse(raw); err != nil { + t.Errorf("%s: the declaration's check refuses what the node composes: %v", name, err) } } // A resolution is asked once, and it names the node keeping the build its digests are of. @@ -377,7 +442,7 @@ func aResolutionWhoseFetchFailedIsForgotten(t *testing.T) { c.wants["mail"] = want c.keptEnt[fp] = keptEntry{entry: entry} parts, _ := c.partsOf("mail", entry, want) - _, err := reader{c: c}.Archive(context.Background(), referenceOf("mail", "files", parts["mail:files"]), parts["mail:files"]) + _, err := reader{c: c}.Archive(context.Background(), blobsReference("mail", "files", parts["mail:files"]), parts["mail:files"]) if (err != nil) != (row.forgets || row.failed) { t.Errorf("%s: the fetch: %v", name, err) } diff --git a/module.json b/module.json index 4db1dbac..93a791f3 100644 --- a/module.json +++ b/module.json @@ -46,6 +46,7 @@ } ], "invokes": [ + "seat:container-image-registry.name-of", "seat:container-image-registry.versions", "seat:mesh-catalog.entry", "seat:mesh-catalog.module",