package main import ( "os" "path/filepath" "strings" "testing" "git.novox.be/novox/mesh-sdk/go/catalogue" ) // Issue 1703 (the live failure of the first assignment): the module is moved, so the provisioner's client on the node // fills its templates, and it fills only config, secrets, collections, placement and what a moved provider told it. // The registry's address therefore cannot be a ${bound:artifact-store:...} (the artifact store has not moved): it is the // placement ${seat:mesh-artifact-store:reach}, the form the container runtime's daemon.json uses. This composes the // module on a machine with buildah and the artifact store reachable, handing its files to the client as a node does. func TestTheModuleComposesWhereItsFilesAreHandedToTheProvisionersClient(t *testing.T) { built := func(m catalogue.Manifest) []catalogue.Built { texts := map[string]string{} entries, err := os.ReadDir(filepath.Join(moduleDir, "files")) if err != nil { t.Fatal(err) } for _, e := range entries { raw, err := os.ReadFile(filepath.Join(moduleDir, "files", e.Name())) if err != nil { t.Fatal(err) } texts[e.Name()] = string(raw) } return []catalogue.Built{ {Name: "tools", Kind: "bundle", Reference: catalogue.ArtifactStoreScheme + "mesh-build-image/tools/blobs/sha256:" + strings.Repeat("a", 64), Digest: "sha256:" + strings.Repeat("a", 64)}, {Name: "files", Kind: "archive", Reference: catalogue.ArtifactStoreScheme + "mesh-build-image/files/blobs/sha256:" + strings.Repeat("b", 64), Digest: "sha256:" + strings.Repeat("b", 64), Texts: texts}, } } read := func(name string) catalogue.Manifest { return decodeTree(t, filepath.Join(catalogueRoot, "modules", name)) } image := read("mesh-build-image") resolved, err := image.Resolve(built(image)) if err != nil { t.Fatal(err) } shelf := map[string]catalogue.Manifest{ "mesh-build-image": resolved, "buildah": read("buildah"), "forge": {Module: "forge", Version: "1", Provides: []catalogue.Offer{{Name: "forge-account"}}}, "store": {Module: "store", Version: "1", Provides: []catalogue.Offer{{Name: "artifact-store"}}}, "runner": {Module: "runner", Version: "1", Provides: []catalogue.Offer{{Name: "node-tools"}}}, // node-tools, which the module pulls its asks through (1911) } node := catalogue.Node{Name: "builder", Site: "house", Capabilities: map[string]bool{"package-manager": true, "user-namespaces": true}} r, err := catalogue.Resolve(shelf, []string{"forge", "store", "runner", "buildah", "mesh-build-image"}, node, catalogue.World{}) if err != nil { t.Fatal(err) } r.Account = "op" // What the resolution states for the node: the forge's provider has moved, the artifact store's has not. r.Needs = []catalogue.Needed{ {Name: "forge-account", For: "mesh-build-image", Module: "forge", From: "novox", At: "10.7.0.1", ProviderMoved: true, Serves: map[string]any{"known_host": "[novox.internal]:222 ssh-ed25519 AAAA", "host_key": "ssh-ed25519 AAAA", "ssh_host": "novox.internal", "ssh_alias": "mesh-forge", "ssh_port": "222", "ssh_base": "ssh://git@novox.internal:222/", "https_base": "https://git.novox.be/"}}, {Name: "artifact-store", For: "mesh-build-image", Module: "store", From: "novox", At: "10.7.0.1", Serves: map[string]any{"port": "5000"}}, } with := catalogue.Rendering{Hands: true, Provisioner: "mesh-provisioner-client", ArtifactStore: "store:5000", Needed: map[string]map[string]string{"mesh-build-image": {"broker": "sealed-to-the-node"}}} c, err := r.Compose(with) if err != nil { t.Fatalf("the module does not compose on a machine with buildah and the artifact store: %v", err) } if _, asked := c.Plans["mesh-build-image"].Placement["seat:mesh-artifact-store:reach"]; !asked { t.Errorf("the plan's placement %v does not ask where the registry is reached", c.Plans["mesh-build-image"].Placement) } }