Skip to content

Commit b19e60d

Browse files
committed
feat: add AutoUpgradeBackends config and runtime settings
Add configuration and runtime settings for backend auto-upgrade: - RuntimeSettings field for dynamic config via API/JSON - ApplicationConfig field, option func, and roundtrip conversion - CLI flag with LOCALAI_AUTO_UPGRADE_BACKENDS env var - Config file watcher support for runtime_settings.json - Tests for ToRuntimeSettings, ApplyRuntimeSettings, and roundtrip
1 parent 4d463e9 commit b19e60d

5 files changed

Lines changed: 36 additions & 0 deletions

File tree

core/application/config_file_watcher.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ func readRuntimeSettingsJson(startupAppConfig config.ApplicationConfig) fileHand
335335
if settings.AutoloadBackendGalleries != nil && !envAutoloadBackendGalleries {
336336
appConfig.AutoloadBackendGalleries = *settings.AutoloadBackendGalleries
337337
}
338+
if settings.AutoUpgradeBackends != nil {
339+
appConfig.AutoUpgradeBackends = *settings.AutoUpgradeBackends
340+
}
338341
if settings.ApiKeys != nil {
339342
// API keys from env vars (startup) should be kept, runtime settings keys replace all runtime keys
340343
// If runtime_settings.json specifies ApiKeys (even if empty), it replaces all runtime keys

core/cli/run.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type RunCMD struct {
4747
BackendImagesReleaseTag string `env:"LOCALAI_BACKEND_IMAGES_RELEASE_TAG,BACKEND_IMAGES_RELEASE_TAG" help:"Fallback release tag for backend images" group:"backends" default:"latest"`
4848
BackendImagesBranchTag string `env:"LOCALAI_BACKEND_IMAGES_BRANCH_TAG,BACKEND_IMAGES_BRANCH_TAG" help:"Fallback branch tag for backend images" group:"backends" default:"master"`
4949
BackendDevSuffix string `env:"LOCALAI_BACKEND_DEV_SUFFIX,BACKEND_DEV_SUFFIX" help:"Development suffix for backend images" group:"backends" default:"development"`
50+
AutoUpgradeBackends bool `env:"LOCALAI_AUTO_UPGRADE_BACKENDS,AUTO_UPGRADE_BACKENDS" help:"Automatically upgrade backends when new versions are detected" group:"backends" default:"false"`
5051
PreloadModels string `env:"LOCALAI_PRELOAD_MODELS,PRELOAD_MODELS" help:"A List of models to apply in JSON at start" group:"models"`
5152
Models []string `env:"LOCALAI_MODELS,MODELS" help:"A List of model configuration URLs to load" group:"models"`
5253
PreloadModelsConfig string `env:"LOCALAI_PRELOAD_MODELS_CONFIG,PRELOAD_MODELS_CONFIG" help:"A List of models to apply at startup. Path to a YAML config file" group:"models"`
@@ -490,6 +491,10 @@ func (r *RunCMD) Run(ctx *cliContext.Context) error {
490491
opts = append(opts, config.EnableBackendGalleriesAutoload)
491492
}
492493

494+
if r.AutoUpgradeBackends {
495+
opts = append(opts, config.WithAutoUpgradeBackends(r.AutoUpgradeBackends))
496+
}
497+
493498
if r.PreloadBackendOnly {
494499
_, err := application.New(opts...)
495500
return err

core/config/application_config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type ApplicationConfig struct {
5757
ExternalGRPCBackends map[string]string
5858

5959
AutoloadGalleries, AutoloadBackendGalleries bool
60+
AutoUpgradeBackends bool
6061

6162
SingleBackend bool // Deprecated: use MaxActiveBackends = 1 instead
6263
MaxActiveBackends int // Maximum number of active backends (0 = unlimited, 1 = single backend mode)
@@ -390,6 +391,10 @@ var EnableBackendGalleriesAutoload = func(o *ApplicationConfig) {
390391
o.AutoloadBackendGalleries = true
391392
}
392393

394+
func WithAutoUpgradeBackends(v bool) AppOption {
395+
return func(o *ApplicationConfig) { o.AutoUpgradeBackends = v }
396+
}
397+
393398
var EnableFederated = func(o *ApplicationConfig) {
394399
o.Federated = true
395400
}
@@ -862,6 +867,7 @@ func (o *ApplicationConfig) ToRuntimeSettings() RuntimeSettings {
862867
backendGalleries := o.BackendGalleries
863868
autoloadGalleries := o.AutoloadGalleries
864869
autoloadBackendGalleries := o.AutoloadBackendGalleries
870+
autoUpgradeBackends := o.AutoUpgradeBackends
865871
apiKeys := o.ApiKeys
866872
agentJobRetentionDays := o.AgentJobRetentionDays
867873

@@ -935,6 +941,7 @@ func (o *ApplicationConfig) ToRuntimeSettings() RuntimeSettings {
935941
BackendGalleries: &backendGalleries,
936942
AutoloadGalleries: &autoloadGalleries,
937943
AutoloadBackendGalleries: &autoloadBackendGalleries,
944+
AutoUpgradeBackends: &autoUpgradeBackends,
938945
ApiKeys: &apiKeys,
939946
AgentJobRetentionDays: &agentJobRetentionDays,
940947
OpenResponsesStoreTTL: &openResponsesStoreTTL,
@@ -1083,6 +1090,9 @@ func (o *ApplicationConfig) ApplyRuntimeSettings(settings *RuntimeSettings) (req
10831090
if settings.AutoloadBackendGalleries != nil {
10841091
o.AutoloadBackendGalleries = *settings.AutoloadBackendGalleries
10851092
}
1093+
if settings.AutoUpgradeBackends != nil {
1094+
o.AutoUpgradeBackends = *settings.AutoUpgradeBackends
1095+
}
10861096
if settings.AgentJobRetentionDays != nil {
10871097
o.AgentJobRetentionDays = *settings.AgentJobRetentionDays
10881098
}

core/config/application_config_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ var _ = Describe("ApplicationConfig RuntimeSettings Conversion", func() {
119119
Expect(*rs.AgentJobRetentionDays).To(Equal(30))
120120
})
121121

122+
It("should include auto_upgrade_backends", func() {
123+
appConfig := &ApplicationConfig{AutoUpgradeBackends: true}
124+
rs := appConfig.ToRuntimeSettings()
125+
Expect(rs.AutoUpgradeBackends).ToNot(BeNil())
126+
Expect(*rs.AutoUpgradeBackends).To(BeTrue())
127+
})
128+
122129
It("should use default timeouts when not set", func() {
123130
appConfig := &ApplicationConfig{}
124131

@@ -426,6 +433,14 @@ var _ = Describe("ApplicationConfig RuntimeSettings Conversion", func() {
426433
Expect(appConfig.AutoloadBackendGalleries).To(BeTrue())
427434
})
428435

436+
It("should apply auto_upgrade_backends setting", func() {
437+
appConfig := &ApplicationConfig{}
438+
v := true
439+
rs := &RuntimeSettings{AutoUpgradeBackends: &v}
440+
appConfig.ApplyRuntimeSettings(rs)
441+
Expect(appConfig.AutoUpgradeBackends).To(BeTrue())
442+
})
443+
429444
It("should apply agent settings", func() {
430445
appConfig := &ApplicationConfig{}
431446

@@ -465,6 +480,7 @@ var _ = Describe("ApplicationConfig RuntimeSettings Conversion", func() {
465480
Federated: true,
466481
AutoloadGalleries: true,
467482
AutoloadBackendGalleries: false,
483+
AutoUpgradeBackends: true,
468484
AgentJobRetentionDays: 60,
469485
}
470486

@@ -496,6 +512,7 @@ var _ = Describe("ApplicationConfig RuntimeSettings Conversion", func() {
496512
Expect(target.Federated).To(Equal(original.Federated))
497513
Expect(target.AutoloadGalleries).To(Equal(original.AutoloadGalleries))
498514
Expect(target.AutoloadBackendGalleries).To(Equal(original.AutoloadBackendGalleries))
515+
Expect(target.AutoUpgradeBackends).To(Equal(original.AutoUpgradeBackends))
499516
Expect(target.AgentJobRetentionDays).To(Equal(original.AgentJobRetentionDays))
500517
})
501518

core/config/runtime_settings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type RuntimeSettings struct {
2020
// Backend management
2121
SingleBackend *bool `json:"single_backend,omitempty"` // Deprecated: use MaxActiveBackends = 1 instead
2222
MaxActiveBackends *int `json:"max_active_backends,omitempty"` // Maximum number of active backends (0 = unlimited, 1 = single backend mode)
23+
AutoUpgradeBackends *bool `json:"auto_upgrade_backends,omitempty"` // Automatically upgrade backends when new versions are detected
2324
// Memory Reclaimer settings (works with GPU if available, otherwise RAM)
2425
MemoryReclaimerEnabled *bool `json:"memory_reclaimer_enabled,omitempty"` // Enable memory threshold monitoring
2526
MemoryReclaimerThreshold *float64 `json:"memory_reclaimer_threshold,omitempty"` // Threshold 0.0-1.0 (e.g., 0.95 = 95%)

0 commit comments

Comments
 (0)