BLD11: the three build modules take the version from the ask as MESH_VERSION; version.numbered is no longer heard
The Go compile, the Node tsc/esbuild/npm and the image's buildah bud get the build argument MESH_VERSION from the version the build ask carries. The late publish on version.numbered goes (code, tests, the consumes of the Go and image manifests). The image's label and tag and a program's stamp are open (question to the lead): the design names no key or symbol. Builds: design 47 G §349, §370, §413 Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
This commit is contained in:
@@ -1,91 +0,0 @@
|
||||
package buildstep
|
||||
|
||||
// **The late publish** (novox/hq ADR 0617 §1, design 51 *The versions*, *Publishing*; CAT-BG2, CAT-BI1): a trunk build
|
||||
// whose number the builder did not know yet publishes its digest unnumbered; the builder says version.numbered once it
|
||||
// numbers that fingerprint, and the build module publishes the held digest again under that version. Nothing travels:
|
||||
// the publish names the one part by its digest, which the holder holds, so it answers held and tags the version (the
|
||||
// holder asks builder_versions first, ADR 0605 §4). The bytes never stayed on the node, so a holder that no longer holds
|
||||
// the digest is said and the event offered again. Every instance may hear the same event; the publish is the same call
|
||||
// under the same transfer name, so a second one is answered held. One place for every build module: mesh-build-go's
|
||||
// bundles and archives on oci-artifact-registry, mesh-build-image's images on container-image-registry.
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
reg "git.novox.be/novox/mesh-delivery/contracts/go/seats/containerimageregistry"
|
||||
builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"git.novox.be/novox/mesh-delivery/sdk/parts"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
)
|
||||
|
||||
// NumberedPattern is the event type a build module consumes for the late publish, as its manifest's `consumes` names it.
|
||||
const NumberedPattern = builds.BuilderModule + "." + builds.VersionNumberedEvent
|
||||
|
||||
// errNotHere is a held part's Open: its bytes did not stay on the node.
|
||||
var errNotHere = errors.New("the built bytes did not stay on the node; the holder must hold the digest")
|
||||
|
||||
// LatePublish publishes a numbered build's held digest under its version on seat, from the builder's version.numbered
|
||||
// body, when its kind is one of kinds. It answers false, nil for an event that is not the module's to publish: another
|
||||
// kind, another seat (an event naming none is the artifact seat's, as the builder wrote it before images), or a version
|
||||
// numbered with no digest.
|
||||
func LatePublish(ctx context.Context, call SeatCall, body []byte, seat string, kinds ...string) (bool, error) {
|
||||
n, err := builds.DecodeVersionNumbered(body)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
on := n.Seat
|
||||
if on == "" {
|
||||
on = ArtifactSeat
|
||||
}
|
||||
if n.Digest == "" || on != seat || !slices.Contains(kinds, n.Kind) {
|
||||
return false, nil
|
||||
}
|
||||
in := reg.PublishInput{Name: n.Name, Kind: n.Kind, Version: n.Version, Tag: n.Tag, Digest: n.Digest,
|
||||
Fingerprint: n.Fingerprint, Commit: n.Commit, Transfer: TransferName(n.Name, "v"+n.Version, n.Digest)}
|
||||
sent, err := OnSeat(ctx, seat, "late publish of "+n.Name+" "+n.Version+" at "+n.Digest, func() (parts.Sent, error) {
|
||||
return PublishParts(ctx, call, seat, in, []parts.Part{{Digest: n.Digest,
|
||||
Open: func() (io.ReadCloser, error) { return nil, errNotHere }}})
|
||||
}, nil)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("the late publish of %s@%s (%s): %w", n.Name, n.Version, n.Digest, err)
|
||||
}
|
||||
if len(sent.Parts) > 0 {
|
||||
return false, fmt.Errorf("the late publish of %s@%s sent parts it should not have", n.Name, n.Version)
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// HearNumbered subscribes late to the builder's version.numbered, asking again until the runtime takes it, and says
|
||||
// each publish and each failure; an error is the event's, which is offered again.
|
||||
func HearNumbered(ctx context.Context, late func(ctx context.Context, body []byte) (bool, error)) {
|
||||
handle := func(e stdio.Envelope) error {
|
||||
did, err := late(ctx, e.Body)
|
||||
if err != nil {
|
||||
log.Printf("%v", err)
|
||||
return err
|
||||
}
|
||||
if did {
|
||||
log.Printf("published a numbered build's held digest under its version (%s)", e.Headers["x-event-id"])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
for wait := 2 * time.Second; ; wait = min(wait*2, time.Minute) {
|
||||
err := stdio.Subscribe(NumberedPattern, handle)
|
||||
if err == nil {
|
||||
log.Printf("listening for the builder's %s", NumberedPattern)
|
||||
return
|
||||
}
|
||||
log.Printf("not hearing the builder's %s yet (%v); asking again in %s", NumberedPattern, err, wait)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-time.After(wait):
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ func (m *Module) buildTool() StepTool {
|
||||
"workspace": map[string]any{"type": "string", "description": "the workspace id build_go_fetch answered"},
|
||||
"module": map[string]any{"type": "string", "description": "the module's directory in the workspace, . for the repository's root"},
|
||||
"artifact": map[string]any{"type": "string", "description": "the artifact's name in the module's manifest"},
|
||||
"version": map[string]any{"type": "string", "description": "the version the builder gave a package at the trunk's claim; absent for a candidate, whose package is not published"},
|
||||
"version": map[string]any{"type": "string", "description": "the version the build ask carries for the artifact: a Go package's tag, and the build argument MESH_VERSION of every artifact; absent for a candidate, whose package is not published"},
|
||||
"seat": map[string]any{"type": "string", "description": "the registry seat the artifact is published through, as the build ask names it"},
|
||||
"publish": map[string]any{"type": "boolean", "description": "true for a merged trunk commit alone: the build writes the shared Go caches; without it (a candidate) they are read beneath a throwaway layer"},
|
||||
},
|
||||
@@ -114,8 +114,9 @@ func (m *Module) build(ctx context.Context, args map[string]any) (any, error) {
|
||||
if art == nil {
|
||||
return nil, fmt.Errorf("the module %s has no artifact %q (it has %s)", manifest.Module, name, strings.Join(names, ", "))
|
||||
}
|
||||
// The version the build ask carries is the build's argument MESH_VERSION for every artifact (design 47 G §370).
|
||||
version, _ := args["version"].(string)
|
||||
if art.Kind == catalogue.ArtifactPackage && art.Language == "go" {
|
||||
version, _ := args["version"].(string)
|
||||
seat, _ := args["seat"].(string)
|
||||
return m.buildGoPackage(ctx, workspace, dir, *art, version, seat)
|
||||
}
|
||||
@@ -153,7 +154,11 @@ func (m *Module) build(ctx context.Context, args map[string]any) (any, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r := run(ctx, m.buildEnv(dir), "go", cmd...); r.Status != 0 || r.Err != "" {
|
||||
env := m.buildEnv(dir)
|
||||
if version != "" {
|
||||
env = append(env, "MESH_VERSION="+version)
|
||||
}
|
||||
if r := run(ctx, env, "go", cmd...); r.Status != 0 || r.Err != "" {
|
||||
return nil, fmt.Errorf("go build of %s: %s", art.Name, causeLine(r.Err+"\n"+r.Stderr+"\n"+r.Stdout))
|
||||
}
|
||||
if err := m.insideModule(workspace, dir, out); err != nil {
|
||||
|
||||
@@ -255,3 +255,34 @@ func TestAManifestFallingBackToAPredefinedKeyBuilds(t *testing.T) {
|
||||
t.Errorf("result = %+v", res)
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 G §370 (BLD11): a build ask carrying a version gives the compile the build argument MESH_VERSION, and one
|
||||
// without gives none.
|
||||
func TestTheBuildGetsTheVersionTheAskCarriesAsMeshVersion(t *testing.T) {
|
||||
for _, version := range []string{"1.4.3", ""} {
|
||||
m, states, calls := buildModule(t, manifestWith(goBundle), "binary")
|
||||
for _, tool := range m.Tools(m.StepTools()) {
|
||||
if tool.Name == "build_go_build" {
|
||||
if _, err := tool.Run(map[string]any{"workspace": "ws1", "module": "modules/demo", "artifact": "tools", "version": version}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if st := states.waitEnd(t); st.State != sdkstep.StepPassed {
|
||||
t.Fatalf("the step ended %s: %s", st.State, st.Reason)
|
||||
}
|
||||
got := ""
|
||||
for _, r := range *calls {
|
||||
if strings.HasPrefix(r.line, "go ") {
|
||||
for _, e := range r.env {
|
||||
if strings.HasPrefix(e, "MESH_VERSION=") {
|
||||
got = strings.TrimPrefix(e, "MESH_VERSION=")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if got != version {
|
||||
t.Errorf("ask version %q: the compile's MESH_VERSION = %q", version, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package main
|
||||
|
||||
// The late publish (CAT-BG2): a numbered bundle or archive's held digest published under its version, by the build
|
||||
// modules' one late publish (buildstep/latepublish.go).
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.novox.be/novox/mesh-catalog/modules/mesh-build-go/buildstep"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
)
|
||||
|
||||
// NumberedPattern is the event type this module consumes for the late publish, as its manifest's `consumes` names it.
|
||||
const NumberedPattern = buildstep.NumberedPattern
|
||||
|
||||
// LatePublish publishes a numbered bundle or archive's held digest under its version on the artifact seat; a Go package
|
||||
// publishes at its build, an image is mesh-build-image's.
|
||||
func (m *Module) LatePublish(ctx context.Context, body []byte) (bool, error) {
|
||||
call := m.Call
|
||||
if call == nil {
|
||||
call = stdio.Ask
|
||||
}
|
||||
return buildstep.LatePublish(ctx, call, body, ArtifactSeat, "bundle", "archive")
|
||||
}
|
||||
|
||||
// hearNumbered hears the builder's version.numbered for the late publish.
|
||||
func (m *Module) hearNumbered(ctx context.Context) { buildstep.HearNumbered(ctx, m.LatePublish) }
|
||||
@@ -88,8 +88,6 @@ func main() {
|
||||
if m.Node != "" {
|
||||
// The seat's asks, pulled once Serve has the runtime's channel; a pull before it is said and tried again.
|
||||
go func() { _ = puller.Pull(ctx) }()
|
||||
// The builder's version.numbered, for the late publish of a held digest (latepublish.go).
|
||||
go m.hearNumbered(ctx)
|
||||
}
|
||||
if err := stdio.Serve("", append(m.Tools(steps), m.SeatTools(puller)...)); err != nil {
|
||||
logf("%v", err)
|
||||
|
||||
@@ -186,9 +186,9 @@ func TestTheModuleInvokesTheArtifactSeatsVerbsAndWritesNoStore(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// The late publish hears the builder's version.numbered (latepublish.go).
|
||||
if !slices.Contains(m.Consumes, NumberedPattern) {
|
||||
t.Errorf("consumes %v lack %s", m.Consumes, NumberedPattern)
|
||||
// The version comes in the ask: no consume of version.numbered (design 47 G §349, §413).
|
||||
if slices.Contains(m.Consumes, "mesh-delivery-builder.version.numbered") {
|
||||
t.Errorf("consumes %v still hear version.numbered", m.Consumes)
|
||||
}
|
||||
for _, r := range m.Resources {
|
||||
if r["id"] == "registry" {
|
||||
|
||||
@@ -313,57 +313,3 @@ func TestEachGoPackageOfAModuleInAFolderIsPublishedUnderItsOwnModulePath(t *test
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CAT-BG2 (design 51 *The versions*): the builder's version.numbered for a bundle or an archive publishes the held
|
||||
// digest under its version, sending nothing; a digest the holder no longer holds fails the event (offered again),
|
||||
// and what is not this module's to publish is let pass.
|
||||
func TestTheNumberedEventPublishesAHeldDigestUnderItsVersion(t *testing.T) {
|
||||
digest := "sha256:" + strings.Repeat("ab", 32)
|
||||
other := "sha256:" + strings.Repeat("cd", 32)
|
||||
numbered := func(kind, seat, digest string) []byte {
|
||||
raw, err := builds.EncodeVersionNumbered(builds.VersionNumbered{Name: "mod/tools", Kind: kind, Version: "0.1.4",
|
||||
Module: "mod", Fingerprint: "fp", Commit: "c0", Digest: digest, Seat: seat})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return raw
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
body []byte
|
||||
did, fail bool
|
||||
}{
|
||||
{"a held bundle is tagged", numbered("bundle", ArtifactSeat, digest), true, false},
|
||||
{"an archive with no seat named goes to the artifact seat", numbered("archive", "", digest), true, false},
|
||||
{"a digest the holder lacks fails, sending nothing", numbered("bundle", ArtifactSeat, other), false, true},
|
||||
{"a Go package is not published late", numbered("package", GoPackageSeat, digest), false, false},
|
||||
{"an image is mesh-build-image's", numbered("image", "container-image-registry", digest), false, false},
|
||||
{"no digest, nothing to publish", numbered("bundle", ArtifactSeat, ""), false, false},
|
||||
{"an unreadable body fails", []byte(`{"name":"mod/tools"}`), false, true},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
m := &Module{}
|
||||
s := withStore(t, m)
|
||||
s.blobs["mod/tools@"+digest] = []byte("held")
|
||||
did, err := m.LatePublish(t.Context(), c.body)
|
||||
if did != c.did || (err != nil) != c.fail {
|
||||
t.Fatalf("did %v, err %v; want did %v, fail %v", did, err, c.did, c.fail)
|
||||
}
|
||||
for _, k := range s.asked {
|
||||
if strings.HasSuffix(k, ".publish-part") {
|
||||
t.Errorf("a late publish sent a part: %v", s.asked)
|
||||
}
|
||||
}
|
||||
if !c.did {
|
||||
return
|
||||
}
|
||||
if len(s.published) != 1 {
|
||||
t.Fatalf("published %v", s.published)
|
||||
}
|
||||
p := s.published[0]
|
||||
if p.Name != "mod/tools" || p.Version != "0.1.4" || p.Digest != digest || p.Fingerprint != "fp" || p.Commit != "c0" {
|
||||
t.Errorf("published %+v", p)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
"serves": ["current", "drop", "pause", "resume", "steps"]
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"mesh-delivery-builder.version.numbered"
|
||||
],
|
||||
"reads": [
|
||||
"mesh-delivery-checker.kept"
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user