feat: support explicit source bundles through the common installer

This commit is contained in:
Codex
2026-10-06 18:31:23 +02:00
parent 785d96ea50
commit 5c05778614
11 changed files with 353 additions and 5 deletions
+35 -1
View File
@@ -19,6 +19,7 @@ import (
// Manifest is the publication/consumer contract. Each platform maps to a single-image digest,
// not a mutable tag or multi-platform index. Maintenance roles use Images["core"].
type Manifest struct {
Distribution string `json:"distribution,omitempty"`
SchemaVersion int `json:"schema_version"`
Version string `json:"version"`
Revision string `json:"revision"`
@@ -30,6 +31,13 @@ type Manifest struct {
Compose []string `json:"compose"`
}
func (m Manifest) Mode() string {
if m.Distribution == "source" {
return "source"
}
return "prebuilt"
}
var hex256 = regexp.MustCompile(`^[a-f0-9]{64}$`)
var imageReference = regexp.MustCompile(`^docker\.io/[a-z0-9][a-z0-9._/-]*@sha256:[a-f0-9]{64}$`)
@@ -37,6 +45,9 @@ func invalidRelease() error {
return errors.New("release manifest or packaged files are incomplete, incompatible or invalid")
}
func (m Manifest) Validate() error {
if m.Distribution != "" && m.Distribution != "prebuilt" && m.Distribution != "source" {
return invalidRelease()
}
if m.SchemaVersion != 1 || m.ValidatorProtocol != Protocol || !regexp.MustCompile(`^[0-9]+\.[0-9]+\.[0-9]+(?:-[A-Za-z0-9.-]+)?$`).MatchString(m.Version) || !regexp.MustCompile(`^[a-f0-9]{40}$`).MatchString(m.Revision) {
return invalidRelease()
}
@@ -56,7 +67,11 @@ func (m Manifest) Validate() error {
return invalidRelease()
}
for platform, ref := range m.Images[service] {
if (platform != "linux/amd64" && platform != "linux/arm64") || !imageReference.MatchString(ref) {
valid := imageReference.MatchString(ref)
if m.Mode() == "source" && (service == "core" || service == "frontend") {
valid = strings.HasPrefix(ref, "sha256:") && hex256.MatchString(strings.TrimPrefix(ref, "sha256:"))
}
if (platform != "linux/amd64" && platform != "linux/arm64") || !valid {
return invalidRelease()
}
}
@@ -110,6 +125,25 @@ func CheckImages(ctx context.Context, runner Runner, m Manifest, platform string
r.Add("image-"+service, "error", "release.images."+service, "Publish the selected Linux architecture before producing an executable plan.")
continue
}
if m.Mode() == "source" && (service == "core" || service == "frontend") {
result, err := docker(ctx, runner, "image", "inspect", "--format", "{{json .}}", ref)
var image struct {
ID string `json:"Id"`
OS string `json:"Os"`
Architecture string `json:"Architecture"`
Config struct {
Labels map[string]string `json:"Labels"`
} `json:"Config"`
}
good := err == nil && result.ExitCode == 0 && json.Unmarshal([]byte(result.Stdout), &image) == nil && image.ID == ref &&
image.OS+"/"+image.Architecture == platform && image.Config.Labels["org.opencontainers.image.revision"] == m.Revision && image.Config.Labels["org.opencontainers.image.version"] == m.Version
outcome := "passed"
if !good {
outcome = "error"
}
r.Add("image-"+service, outcome, "release.images."+service, "Require the explicitly built local image, matching source revision, version and architecture; rebuild the selected source bundle if it is missing.")
continue
}
result, err := docker(ctx, runner, "manifest", "inspect", "--verbose", ref)
var manifest struct {
Descriptor struct {
@@ -0,0 +1,47 @@
package preflight
import (
"context"
"encoding/json"
"github.com/aritmolab/thothii/tools/tht/internal/compose"
"io"
"strings"
"testing"
)
type localDocker struct {
fakeDocker
wrong bool
}
func (d *localDocker) Run(ctx context.Context, args []string, input io.Reader) (compose.Result, error) {
if args[0] != "image" {
return d.fakeDocker.Run(ctx, args, input)
}
revision := strings.Repeat("b", 40)
if d.wrong {
revision = strings.Repeat("c", 40)
}
value, _ := json.Marshal(map[string]any{"Id": args[len(args)-1], "Os": "linux", "Architecture": "amd64", "Config": map[string]any{"Labels": map[string]string{"org.opencontainers.image.revision": revision, "org.opencontainers.image.version": "1.0.0"}}})
return compose.Result{Stdout: string(value)}, nil
}
func TestSourceImagesNeedExplicitDistributionAndMatchingLocalIdentity(t *testing.T) {
m := Manifest{Distribution: "source", Revision: strings.Repeat("b", 40), Version: "1.0.0", Images: map[string]map[string]string{}}
for _, role := range []string{"core", "frontend", "catalog", "qdrant", "embedding"} {
ref := "docker.io/example/" + role + "@sha256:" + strings.Repeat("a", 64)
if role == "core" || role == "frontend" {
ref = "sha256:" + strings.Repeat("a", 64)
}
m.Images[role] = map[string]string{"linux/amd64": ref}
}
if !CheckImages(context.Background(), &localDocker{}, m, "linux/amd64").OK {
t.Fatal("explicit local images rejected")
}
if CheckImages(context.Background(), &localDocker{wrong: true}, m, "linux/amd64").OK {
t.Fatal("different source accepted")
}
m.Distribution = ""
if CheckImages(context.Background(), &localDocker{}, m, "linux/amd64").OK {
t.Fatal("implicit source fallback accepted")
}
}