mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-14 01:34:47 +08:00
feat: 应用商店,安装 Mysql 和 Redis 时同步更新 phpMyAdmin和Redis-Commander信息
This commit is contained in:
parent
ee7f486d2a
commit
e68a21c2fc
@ -93,7 +93,7 @@
|
|||||||
"author": "phpmyadmin",
|
"author": "phpmyadmin",
|
||||||
"type": "tool",
|
"type": "tool",
|
||||||
"required": ["mysql"],
|
"required": ["mysql"],
|
||||||
"limit": 0,
|
"limit": 1,
|
||||||
"crossVersionUpdate": true,
|
"crossVersionUpdate": true,
|
||||||
"source": "https://www.phpmyadmin.net/"
|
"source": "https://www.phpmyadmin.net/"
|
||||||
},
|
},
|
||||||
@ -106,7 +106,7 @@
|
|||||||
"author": "redis-commander",
|
"author": "redis-commander",
|
||||||
"type": "tool",
|
"type": "tool",
|
||||||
"required": ["redis"],
|
"required": ["redis"],
|
||||||
"limit": 0,
|
"limit": 1,
|
||||||
"crossVersionUpdate": true,
|
"crossVersionUpdate": true,
|
||||||
"source": "https://github.com/joeferner/redis-commander"
|
"source": "https://github.com/joeferner/redis-commander"
|
||||||
}
|
}
|
||||||
|
@ -183,3 +183,8 @@ type AppResource struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var AppToolMap = map[string]string{
|
||||||
|
"mysql": "phpmyadmin",
|
||||||
|
"redis": "redis-commander",
|
||||||
|
}
|
||||||
|
@ -3,7 +3,6 @@ package repo
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/model"
|
"github.com/1Panel-dev/1Panel/backend/app/model"
|
||||||
"github.com/1Panel-dev/1Panel/backend/global"
|
"github.com/1Panel-dev/1Panel/backend/global"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@ -132,10 +131,7 @@ func (a *AppInstallRepo) LoadBaseInfoByKey(key string) (*RootInfo, error) {
|
|||||||
if ok {
|
if ok {
|
||||||
info.Password = password
|
info.Password = password
|
||||||
}
|
}
|
||||||
port, ok := envMap["PANEL_APP_PORT_HTTP"].(float64)
|
info.Port = int64(appInstall.HttpPort)
|
||||||
if ok {
|
|
||||||
info.Port = int64(port)
|
|
||||||
}
|
|
||||||
info.ID = appInstall.ID
|
info.ID = appInstall.ID
|
||||||
info.ContainerName = appInstall.ContainerName
|
info.ContainerName = appInstall.ContainerName
|
||||||
info.Name = appInstall.Name
|
info.Name = appInstall.Name
|
||||||
|
@ -226,6 +226,7 @@ func (a AppService) Install(name string, appDetailId uint, params map[string]int
|
|||||||
}
|
}
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
go upApp(appInstall.GetComposePath(), appInstall)
|
go upApp(appInstall.GetComposePath(), appInstall)
|
||||||
|
go updateToolApp(appInstall)
|
||||||
return &appInstall, nil
|
return &appInstall, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,3 +634,53 @@ func getAppInstallByKey(key string) (model.AppInstall, error) {
|
|||||||
}
|
}
|
||||||
return appInstall, nil
|
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
|
#website
|
||||||
ErrDomainIsExist: "域名已存在"
|
ErrDomainIsExist: "域名已存在"
|
||||||
ErrAliasIsExist: "代号已存在"
|
ErrAliasIsExist: "代号已存在"
|
||||||
|
ErrAppDelete: ''
|
||||||
|
|
||||||
#ssl
|
#ssl
|
||||||
ErrSSLCannotDelete: "证书正在被网站使用,无法删除"
|
ErrSSLCannotDelete: "证书正在被网站使用,无法删除"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user