@@ -25,6 +25,39 @@ const (
2525 runFile = "run.sh"
2626)
2727
28+ // Environment variables for configurable fallback URI patterns
29+ const (
30+ // Default fallback tag values
31+ defaultLatestTag = "latest"
32+ defaultMasterTag = "master"
33+ defaultDevSuffix = "development"
34+
35+ // Environment variable names
36+ envLatestTag = "LOCALAI_BACKEND_IMAGES_RELEASE_TAG"
37+ envMasterTag = "LOCALAI_BACKEND_IMAGES_BRANCH_TAG"
38+ envDevSuffix = "LOCALAI_BACKEND_DEV_SUFFIX"
39+ )
40+
41+ // getFallbackTagValues returns the configurable fallback tag values from environment variables
42+ func getFallbackTagValues () (latestTag , masterTag , devSuffix string ) {
43+ latestTag = os .Getenv (envLatestTag )
44+ masterTag = os .Getenv (envMasterTag )
45+ devSuffix = os .Getenv (envDevSuffix )
46+
47+ // Use defaults if environment variables are not set
48+ if latestTag == "" {
49+ latestTag = defaultLatestTag
50+ }
51+ if masterTag == "" {
52+ masterTag = defaultMasterTag
53+ }
54+ if devSuffix == "" {
55+ devSuffix = defaultDevSuffix
56+ }
57+
58+ return latestTag , masterTag , devSuffix
59+ }
60+
2861// backendCandidate represents an installed concrete backend option for a given alias
2962type backendCandidate struct {
3063 name string
@@ -139,6 +172,9 @@ func InstallBackendFromGallery(ctx context.Context, galleries []config.Gallery,
139172}
140173
141174func InstallBackend (ctx context.Context , systemState * system.SystemState , modelLoader * model.ModelLoader , config * GalleryBackend , downloadStatus func (string , string , string , float64 )) error {
175+ // Get configurable fallback tag values from environment variables
176+ latestTag , masterTag , devSuffix := getFallbackTagValues ()
177+
142178 // Create base path if it doesn't exist
143179 err := os .MkdirAll (systemState .Backend .BackendsPath , 0750 )
144180 if err != nil {
@@ -182,25 +218,25 @@ func InstallBackend(ctx context.Context, systemState *system.SystemState, modelL
182218 }
183219 }
184220
185- // Try fallback: replace "latest -" with "master -" in the URI
186- fallbackURI := strings .Replace (string (config .URI ), "latest -" , "master -" , 1 )
221+ // Try fallback: replace latestTag + " -" with masterTag + " -" in the URI
222+ fallbackURI := strings .Replace (string (config .URI ), latestTag + " -" , masterTag + " -" , 1 )
187223 if fallbackURI != string (config .URI ) {
188224 xlog .Debug ("Trying fallback URI" , "original" , config .URI , "fallback" , fallbackURI )
189225 if err := downloader .URI (fallbackURI ).DownloadFileWithContext (ctx , backendPath , "" , 1 , 1 , downloadStatus ); err == nil {
190226 xlog .Debug ("Downloaded backend using fallback URI" , "uri" , fallbackURI , "backendPath" , backendPath )
191227 success = true
192228 } else {
193- // Try another fallback: add "-development" suffix to the backend name
229+ // Try another fallback: add "-" + devSuffix suffix to the backend name
194230 // For example: master-gpu-nvidia-cuda-13-ace-step -> master-gpu-nvidia-cuda-13-ace-step-development
195- if ! strings .Contains (fallbackURI , "-development" ) {
231+ if ! strings .Contains (fallbackURI , "-" + devSuffix ) {
196232 // Extract backend name from URI and add -development
197233 parts := strings .Split (fallbackURI , "-" )
198234 if len (parts ) >= 2 {
199235 // Find where the backend name ends (usually the last part before the tag)
200236 // Pattern: quay.io/go-skynet/local-ai-backends:master-gpu-nvidia-cuda-13-ace-step
201237 lastDash := strings .LastIndex (fallbackURI , "-" )
202238 if lastDash > 0 {
203- devFallbackURI := fallbackURI [:lastDash ] + "-development"
239+ devFallbackURI := fallbackURI [:lastDash ] + "-" + devSuffix
204240 xlog .Debug ("Trying development fallback URI" , "fallback" , devFallbackURI )
205241 if err := downloader .URI (devFallbackURI ).DownloadFileWithContext (ctx , backendPath , "" , 1 , 1 , downloadStatus ); err == nil {
206242 xlog .Debug ("Downloaded backend using development fallback URI" , "uri" , devFallbackURI , "backendPath" , backendPath )
0 commit comments