diff --git a/backend/app/dto/app.go b/backend/app/dto/app.go index b03425feedd2..395060ffafd0 100644 --- a/backend/app/dto/app.go +++ b/backend/app/dto/app.go @@ -15,6 +15,10 @@ type AuthParam struct { RootPassword string `json:"PANEL_DB_ROOT_PASSWORD"` } +type RedisAuthParam struct { + RootPassword string `json:"PANEL_REDIS_ROOT_PASSWORD"` +} + type ContainerExec struct { ContainerName string `json:"containerName"` DbParam AppDatabase `json:"dbParam"` diff --git a/backend/app/service/app_utils.go b/backend/app/service/app_utils.go index 664180f2e84b..46c569d52bad 100644 --- a/backend/app/service/app_utils.go +++ b/backend/app/service/app_utils.go @@ -83,20 +83,33 @@ func checkPort(key string, params map[string]interface{}) (int, error) { func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall, params map[string]interface{}) error { var dbConfig dto.AppDatabase if app.Type == "runtime" { - var authParam dto.AuthParam - paramByte, err := json.Marshal(params) - if err != nil { - return err - } - if err := json.Unmarshal(paramByte, &authParam); err != nil { - return err - } - if authParam.RootPassword != "" { - authByte, err := json.Marshal(authParam) - if err != nil { - return err + switch app.Key { + case "mysql", "mariadb", "postgresql": + if password, ok := params["PANEL_DB_ROOT_PASSWORD"]; ok { + if password != "" { + authParam := dto.AuthParam{ + RootPassword: password.(string), + } + authByte, err := json.Marshal(authParam) + if err != nil { + return err + } + appInstall.Param = string(authByte) + } + } + case "redis": + if password, ok := params["PANEL_REDIS_ROOT_PASSWORD"]; ok { + if password != "" { + authParam := dto.RedisAuthParam{ + RootPassword: password.(string), + } + authByte, err := json.Marshal(authParam) + if err != nil { + return err + } + appInstall.Param = string(authByte) + } } - appInstall.Param = string(authByte) } } if app.Type == "website" || app.Type == "tool" { @@ -104,7 +117,7 @@ func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall if err != nil { return err } - if err := json.Unmarshal(paramByte, &dbConfig); err != nil { + if err = json.Unmarshal(paramByte, &dbConfig); err != nil { return err } } diff --git a/backend/init/migration/migrate.go b/backend/init/migration/migrate.go index 06d97d1e58ff..be5636ef7998 100644 --- a/backend/init/migration/migrate.go +++ b/backend/init/migration/migrate.go @@ -36,6 +36,7 @@ func Init() { migrations.UpdateAppDetail, migrations.EncryptHostPassword, migrations.AddRemoteDB, + migrations.UpdateRedisParam, }) if err := m.Migrate(); err != nil { global.LOG.Error(err) diff --git a/backend/init/migration/migrations/init.go b/backend/init/migration/migrations/init.go index 08bcad21a133..34d8b4f54af1 100644 --- a/backend/init/migration/migrations/init.go +++ b/backend/init/migration/migrations/init.go @@ -523,3 +523,27 @@ var AddRemoteDB = &gormigrate.Migration{ return nil }, } + +var UpdateRedisParam = &gormigrate.Migration{ + ID: "20230804-update-redis-param", + Migrate: func(tx *gorm.DB) error { + var ( + app model.App + appInstall model.AppInstall + ) + if err := global.DB.Where("key = ?", "redis").First(&app).Error; err != nil { + return nil + } + if err := global.DB.Where("app_id = ?", app.ID).First(&appInstall).Error; err != nil { + return nil + } + appInstall.Param = strings.ReplaceAll(appInstall.Param, "PANEL_DB_ROOT_PASSWORD", "PANEL_REDIS_ROOT_PASSWORD") + appInstall.DockerCompose = strings.ReplaceAll(appInstall.DockerCompose, "PANEL_DB_ROOT_PASSWORD", "PANEL_REDIS_ROOT_PASSWORD") + appInstall.Env = strings.ReplaceAll(appInstall.Env, "PANEL_DB_ROOT_PASSWORD", "PANEL_REDIS_ROOT_PASSWORD") + if err := tx.Model(&model.AppInstall{}).Where("id = ?", appInstall.ID).Updates(appInstall).Error; err != nil { + return err + } + return nil + + }, +}