mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-18 22:22:59 +08:00
feat: 应用商店,安装 Mysql 和 Redis 时同步更新 phpMyAdmin和Redis-Commander信息
This commit is contained in:
parent
ee7f486d2a
commit
e68a21c2fc
@ -93,7 +93,7 @@
|
||||
"author": "phpmyadmin",
|
||||
"type": "tool",
|
||||
"required": ["mysql"],
|
||||
"limit": 0,
|
||||
"limit": 1,
|
||||
"crossVersionUpdate": true,
|
||||
"source": "https://www.phpmyadmin.net/"
|
||||
},
|
||||
@ -106,7 +106,7 @@
|
||||
"author": "redis-commander",
|
||||
"type": "tool",
|
||||
"required": ["redis"],
|
||||
"limit": 0,
|
||||
"limit": 1,
|
||||
"crossVersionUpdate": true,
|
||||
"source": "https://github.com/joeferner/redis-commander"
|
||||
}
|
||||
|
@ -183,3 +183,8 @@ type AppResource struct {
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
var AppToolMap = map[string]string{
|
||||
"mysql": "phpmyadmin",
|
||||
"redis": "redis-commander",
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package repo
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/backend/app/model"
|
||||
"github.com/1Panel-dev/1Panel/backend/global"
|
||||
"gorm.io/gorm"
|
||||
@ -132,10 +131,7 @@ func (a *AppInstallRepo) LoadBaseInfoByKey(key string) (*RootInfo, error) {
|
||||
if ok {
|
||||
info.Password = password
|
||||
}
|
||||
port, ok := envMap["PANEL_APP_PORT_HTTP"].(float64)
|
||||
if ok {
|
||||
info.Port = int64(port)
|
||||
}
|
||||
info.Port = int64(appInstall.HttpPort)
|
||||
info.ID = appInstall.ID
|
||||
info.ContainerName = appInstall.ContainerName
|
||||
info.Name = appInstall.Name
|
||||
|
@ -226,6 +226,7 @@ func (a AppService) Install(name string, appDetailId uint, params map[string]int
|
||||
}
|
||||
tx.Commit()
|
||||
go upApp(appInstall.GetComposePath(), appInstall)
|
||||
go updateToolApp(appInstall)
|
||||
return &appInstall, nil
|
||||
}
|
||||
|
||||
|
@ -634,3 +634,53 @@ func getAppInstallByKey(key string) (model.AppInstall, error) {
|
||||
}
|
||||
return appInstall, nil
|
||||
}
|
||||
|
||||
func updateToolApp(installed model.AppInstall) {
|
||||
tooKey, ok := dto.AppToolMap[installed.App.Key]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
toolInstall, _ := getAppInstallByKey(tooKey)
|
||||
if reflect.DeepEqual(toolInstall, model.AppInstall{}) {
|
||||
return
|
||||
}
|
||||
paramMap := make(map[string]string)
|
||||
_ = json.Unmarshal([]byte(installed.Param), ¶mMap)
|
||||
envMap := make(map[string]interface{})
|
||||
_ = json.Unmarshal([]byte(toolInstall.Env), &envMap)
|
||||
if password, ok := paramMap["PANEL_DB_ROOT_PASSWORD"]; ok {
|
||||
envMap["PANEL_DB_ROOT_PASSWORD"] = password
|
||||
}
|
||||
if _, ok := envMap["PANEL_REDIS_HOST"]; ok {
|
||||
envMap["PANEL_REDIS_HOST"] = installed.ServiceName
|
||||
}
|
||||
if _, ok := envMap["PANEL_DB_HOST"]; ok {
|
||||
envMap["PANEL_DB_HOST"] = installed.ServiceName
|
||||
}
|
||||
|
||||
envPath := path.Join(toolInstall.GetPath(), ".env")
|
||||
contentByte, err := json.Marshal(envMap)
|
||||
if err != nil {
|
||||
global.LOG.Errorf("update tool app [%s] error : %s", toolInstall.Name, err.Error())
|
||||
return
|
||||
}
|
||||
envFileMap := make(map[string]string)
|
||||
handleMap(envMap, envFileMap)
|
||||
if err = godotenv.Write(envFileMap, envPath); err != nil {
|
||||
global.LOG.Errorf("update tool app [%s] error : %s", toolInstall.Name, err.Error())
|
||||
return
|
||||
}
|
||||
toolInstall.Env = string(contentByte)
|
||||
if err := appInstallRepo.Save(&toolInstall); err != nil {
|
||||
global.LOG.Errorf("update tool app [%s] error : %s", toolInstall.Name, err.Error())
|
||||
return
|
||||
}
|
||||
if out, err := compose.Down(toolInstall.GetComposePath()); err != nil {
|
||||
global.LOG.Errorf("update tool app [%s] error : %s", toolInstall.Name, out)
|
||||
return
|
||||
}
|
||||
if out, err := compose.Up(toolInstall.GetComposePath()); err != nil {
|
||||
global.LOG.Errorf("update tool app [%s] error : %s", toolInstall.Name, out)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ ErrFileToLarge: "文件超过10M,无法打开"
|
||||
#website
|
||||
ErrDomainIsExist: "域名已存在"
|
||||
ErrAliasIsExist: "代号已存在"
|
||||
ErrAppDelete: ''
|
||||
|
||||
#ssl
|
||||
ErrSSLCannotDelete: "证书正在被网站使用,无法删除"
|
||||
|
Loading…
Reference in New Issue
Block a user