feat(infra): auto-install and start shared database/auth at boot when missing
ensureInfraRunning now resolves the missing infra service from the registry (via the new lib/registry package, extracted from the GetRegistry handler so the UI and the bootstrap share one source of truth) and installs it before starting it. A fresh host boots with its database and auth service without manual UI steps; failures stay non-fatal warnings like before.
This commit is contained in:
+21
-10
@@ -21,6 +21,7 @@ import (
|
||||
|
||||
"git.dcntrlized.org/Dcntrlized/Maestro/lib/docker"
|
||||
"git.dcntrlized.org/Dcntrlized/Maestro/lib/logger"
|
||||
libregistry "git.dcntrlized.org/Dcntrlized/Maestro/lib/registry"
|
||||
"git.dcntrlized.org/Dcntrlized/Maestro/lib/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
@@ -50,10 +51,11 @@ func EnsureDCNTRLIZEDNetwork(ctx context.Context, dc *docker.DockerClient) error
|
||||
return nil
|
||||
}
|
||||
|
||||
// EnsureDatabaseRunning ensures the shared database container is running. It
|
||||
// starts the database only when it is already installed; otherwise it logs and
|
||||
// leaves installation to the UI. The database is infrastructure, so this must
|
||||
// never be invoked for the database service itself (StartContainer guards that).
|
||||
// EnsureDatabaseRunning ensures the shared database container is running. On a
|
||||
// fresh host — when the database is not installed yet — it resolves the
|
||||
// database from the registry and installs it automatically before starting it.
|
||||
// The database is infrastructure, so this must never be invoked for the
|
||||
// database service itself (StartContainer guards that).
|
||||
func EnsureDatabaseRunning(ctx context.Context) error {
|
||||
return ensureInfraRunning(ctx, DatabaseServiceName, "shared database")
|
||||
}
|
||||
@@ -61,14 +63,17 @@ func EnsureDatabaseRunning(ctx context.Context) error {
|
||||
// EnsureAuthRunning ensures the shared auth service container is running. The
|
||||
// auth service is hidden infrastructure: every consumer proxies /auth/* to it
|
||||
// and validates action tokens with its key, so it must be up before services
|
||||
// that depend on it start. Only starts when already installed.
|
||||
// that depend on it start. Like the database, it is installed automatically
|
||||
// from the registry when it is missing.
|
||||
func EnsureAuthRunning(ctx context.Context) error {
|
||||
return ensureInfraRunning(ctx, AuthServiceName, "shared auth service")
|
||||
}
|
||||
|
||||
// ensureInfraRunning starts a hidden infrastructure container (shared database,
|
||||
// shared auth service) when it is installed but not running. It never installs
|
||||
// infrastructure itself — the UI does that from the registry.
|
||||
// ensureInfraRunning makes sure a hidden infrastructure container (shared
|
||||
// database, shared auth service) is running. When the service is not installed
|
||||
// yet it resolves the registry item and installs it first, so a fresh host
|
||||
// boots with its infrastructure without manual UI steps. Failures are returned
|
||||
// to the caller, which treats them as non-fatal warnings.
|
||||
func ensureInfraRunning(ctx context.Context, serviceName, label string) error {
|
||||
dc, err := docker.NewDockerClient()
|
||||
if err != nil {
|
||||
@@ -84,8 +89,14 @@ func ensureInfraRunning(ctx context.Context, serviceName, label string) error {
|
||||
return nil
|
||||
}
|
||||
if !IsInstalled(serviceName) {
|
||||
logger.Info("%s not installed; install %s from the registry to enable services that need it", label, serviceName)
|
||||
return nil
|
||||
logger.Info("%s %s not installed; installing from the registry...", label, serviceName)
|
||||
item, err := libregistry.ItemByName(ctx, serviceName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve %s %s from the registry: %w", label, serviceName, err)
|
||||
}
|
||||
if err := InstallContainer(ctx, *item); err != nil {
|
||||
return fmt.Errorf("failed to install %s %s: %w", label, serviceName, err)
|
||||
}
|
||||
}
|
||||
|
||||
logger.Info("Starting %s %s...", label, serviceName)
|
||||
|
||||
Reference in New Issue
Block a user