feat: support explicit source bundles through the common installer
This commit is contained in:
@@ -29,6 +29,7 @@ type RuntimeCheck struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
type Result struct {
|
||||
Distribution string `json:"distribution"`
|
||||
SchemaVersion int `json:"schema_version"`
|
||||
PlatformReady bool `json:"platform_ready"`
|
||||
WorkspaceReady bool `json:"workspace_ready"`
|
||||
@@ -42,6 +43,7 @@ type Result struct {
|
||||
Journal string `json:"journal,omitempty"`
|
||||
}
|
||||
type journal struct {
|
||||
Distribution string `json:"distribution,omitempty"`
|
||||
SchemaVersion int `json:"schema_version"`
|
||||
Installation string `json:"installation"`
|
||||
ReleaseRevision string `json:"release_revision"`
|
||||
@@ -76,6 +78,7 @@ func Run(ctx context.Context, request Request, runner compose.Runner, check Chec
|
||||
if err != nil || !reflect.DeepEqual(manifest, plan.Release) {
|
||||
return fail("release", "Restore the exact verified release bundle and generate a new plan if its identity changed.")
|
||||
}
|
||||
result.Distribution = manifest.Mode()
|
||||
if err := safeio.EnsurePrivateDirectory(filepath.Join(installation.ProjectDirectory, ".tht")); err != nil {
|
||||
return fail("lock", "The installation control directory must be private and canonical.")
|
||||
}
|
||||
@@ -106,13 +109,20 @@ func Run(ctx context.Context, request Request, runner compose.Runner, check Chec
|
||||
}
|
||||
defer clear(payload)
|
||||
result.Journal = filepath.Join(installation.ControlDirectory(), "installation-apply.json")
|
||||
state := journal{SchemaVersion: 1, Installation: installation.Path, ReleaseRevision: plan.Release.Revision, PlanSeal: plan.InputSeal}
|
||||
state := journal{SchemaVersion: 1, Installation: installation.Path, ReleaseRevision: plan.Release.Revision, PlanSeal: plan.InputSeal, Distribution: manifest.Mode()}
|
||||
if _, err := os.Lstat(result.Journal); err == nil {
|
||||
data, readErr := safeio.ReadCanonicalPrivateRegular(result.Journal, 16<<10)
|
||||
var previous journal
|
||||
if readErr != nil || json.Unmarshal(data, &previous) != nil || previous.SchemaVersion != 1 || previous.Installation != installation.Path || previous.ReleaseRevision != plan.Release.Revision {
|
||||
return fail("journal", "The existing installation journal is invalid or belongs to another release; this command is not a product upgrade.")
|
||||
}
|
||||
previousMode := previous.Distribution
|
||||
if previousMode == "" {
|
||||
previousMode = "prebuilt"
|
||||
}
|
||||
if previousMode != manifest.Mode() {
|
||||
return fail("journal", "Changing between source and prebuilt requires an explicit upgrade or a separate installation.")
|
||||
}
|
||||
} else if !os.IsNotExist(err) {
|
||||
return fail("journal", "Cannot safely read the installation journal.")
|
||||
}
|
||||
@@ -181,6 +191,9 @@ func Run(ctx context.Context, request Request, runner compose.Runner, check Chec
|
||||
return nil
|
||||
}},
|
||||
{"pull", func() error {
|
||||
if manifest.Mode() == "source" {
|
||||
return docker(30*time.Minute, "pull", "--policy", "always", "catalog-db", "qdrant", "embedding", "embedding-model-init")
|
||||
}
|
||||
return docker(30*time.Minute, "--profile", "catalog-maintenance", "--profile", "workspace-maintenance", "pull", "--policy", "always")
|
||||
}},
|
||||
{"runtime-identity", func() error {
|
||||
|
||||
@@ -82,6 +82,7 @@ type dockerFixture struct {
|
||||
calls [][]string
|
||||
fail string
|
||||
wrongImage bool
|
||||
source bool
|
||||
}
|
||||
|
||||
func (r *dockerFixture) Run(_ context.Context, args []string, input io.Reader) (compose.Result, error) {
|
||||
@@ -133,6 +134,9 @@ func (r *dockerFixture) Run(_ context.Context, args []string, input io.Reader) (
|
||||
continue
|
||||
}
|
||||
services[service] = map[string]string{"image": "docker.io/example/" + role + "@sha256:" + strings.Repeat("a", 64)}
|
||||
if r.source && (role == "core" || role == "frontend") {
|
||||
services[service] = map[string]string{"image": "sha256:" + strings.Repeat("a", 64)}
|
||||
}
|
||||
}
|
||||
if r.wrongImage {
|
||||
services["core"] = map[string]string{"image": "unverified:latest"}
|
||||
@@ -149,6 +153,36 @@ func (r *dockerFixture) Run(_ context.Context, args []string, input io.Reader) (
|
||||
return compose.Result{Stdout: `{"ok":true}`}, nil
|
||||
}
|
||||
|
||||
func TestExplicitSourceApplySharesReadinessAndPullsOnlyUpstream(t *testing.T) {
|
||||
path, p := fixture(t)
|
||||
p.Release.Distribution = "source"
|
||||
for _, role := range []string{"core", "frontend"} {
|
||||
p.Release.Images[role][p.Platform] = "sha256:" + strings.Repeat("a", 64)
|
||||
}
|
||||
data, _ := json.Marshal(p.Release)
|
||||
if err := os.WriteFile(p.ManifestPath, data, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = os.Remove(path)
|
||||
_ = os.Remove(path + ".key")
|
||||
if err := preflight.WritePlan(path, &p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := &dockerFixture{source: true}
|
||||
result, err := Run(context.Background(), Request{PlanPath: path, InstallationPath: p.Installation.Path}, r, func(context.Context, preflight.Plan) error { return nil })
|
||||
if err != nil || !result.WorkspaceReady || result.Distribution != "source" {
|
||||
t.Fatalf("source apply: %+v %v", result, err)
|
||||
}
|
||||
for _, call := range flatten(r.calls) {
|
||||
if strings.Contains(call, " pull ") && !strings.Contains(call, "pull --policy always catalog-db qdrant embedding embedding-model-init") {
|
||||
t.Fatal("source application images pulled")
|
||||
}
|
||||
if strings.Contains(call, " build ") {
|
||||
t.Fatal("apply implicitly built source")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyRefusesUnreleasedEffectiveImageBeforePull(t *testing.T) {
|
||||
path, p := fixture(t)
|
||||
r := &dockerFixture{wrongImage: true}
|
||||
|
||||
Reference in New Issue
Block a user