From 03fac3ec06e04bd307cc40bdb2e3138c009fbc48 Mon Sep 17 00:00:00 2001 From: CityFun <31820853+zhengkunwang223@users.noreply.github.com> Date: Tue, 1 Jul 2025 15:47:33 +0800 Subject: [PATCH] fix: Resolve the issue of lost GPU configuration after upgrade ollama (#9362) --- backend/app/service/app_utils.go | 37 +++++++++++++++++---- backend/init/migration/migrate.go | 1 + backend/init/migration/migrations/v_1_10.go | 7 ++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/backend/app/service/app_utils.go b/backend/app/service/app_utils.go index 1036afab0..cdafaf15b 100644 --- a/backend/app/service/app_utils.go +++ b/backend/app/service/app_utils.go @@ -442,17 +442,14 @@ func deleteLink(ctx context.Context, install *model.AppInstall, deleteDB bool, f return appInstallResourceRepo.DeleteBy(ctx, appInstallResourceRepo.WithAppInstallId(install.ID)) } -func getUpgradeCompose(install model.AppInstall, detail model.AppDetail) (string, error) { - if detail.DockerCompose == "" { - return "", nil - } +func handleUpgradeCompose(install model.AppInstall, detail model.AppDetail) (map[string]interface{}, error) { composeMap := make(map[string]interface{}) if err := yaml.Unmarshal([]byte(detail.DockerCompose), &composeMap); err != nil { - return "", err + return nil, err } value, ok := composeMap["services"] if !ok || value == nil { - return "", buserr.New(constant.ErrFileParse) + return nil, buserr.New("ErrFileParse") } servicesMap := value.(map[string]interface{}) if len(servicesMap) == 1 { @@ -470,6 +467,34 @@ func getUpgradeCompose(install model.AppInstall, detail model.AppDetail) (string delete(servicesMap, oldServiceName) } } + serviceValue := servicesMap[install.ServiceName].(map[string]interface{}) + + oldComposeMap := make(map[string]interface{}) + if err := yaml.Unmarshal([]byte(install.DockerCompose), &oldComposeMap); err != nil { + return nil, err + } + oldValue, ok := oldComposeMap["services"] + if !ok || oldValue == nil { + return nil, buserr.New("ErrFileParse") + } + oldValueMap := oldValue.(map[string]interface{}) + oldServiceValue := oldValueMap[install.ServiceName].(map[string]interface{}) + if oldServiceValue["deploy"] != nil { + serviceValue["deploy"] = oldServiceValue["deploy"] + } + servicesMap[install.ServiceName] = serviceValue + composeMap["services"] = servicesMap + return composeMap, nil +} + +func getUpgradeCompose(install model.AppInstall, detail model.AppDetail) (string, error) { + if detail.DockerCompose == "" { + return "", nil + } + composeMap, err := handleUpgradeCompose(install, detail) + if err != nil { + return "", err + } envs := make(map[string]interface{}) if err := json.Unmarshal([]byte(install.Env), &envs); err != nil { return "", err diff --git a/backend/init/migration/migrate.go b/backend/init/migration/migrate.go index 7e7aeede0..0ef409656 100644 --- a/backend/init/migration/migrate.go +++ b/backend/init/migration/migrate.go @@ -109,6 +109,7 @@ func Init() { migrations.AddMcpServer, migrations.AddPbootCMSPHPExtensions, + migrations.DeleteV2Openresty, }) if err := m.Migrate(); err != nil { global.LOG.Error(err) diff --git a/backend/init/migration/migrations/v_1_10.go b/backend/init/migration/migrations/v_1_10.go index 4f2ddcae1..7b4d5f002 100644 --- a/backend/init/migration/migrations/v_1_10.go +++ b/backend/init/migration/migrations/v_1_10.go @@ -485,3 +485,10 @@ var AddPbootCMSPHPExtensions = &gormigrate.Migration{ return nil }, } + +var DeleteV2Openresty = &gormigrate.Migration{ + ID: "20250701-delete-v2-openresty", + Migrate: func(tx *gorm.DB) error { + return tx.Delete(&model.AppDetail{}).Where("version = '1.27.1.2-0-1-focal'").Error + }, +}