mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-28 01:36:56 +08:00
feat: Application installation supports using existing remote databases (#9598)
This commit is contained in:
parent
aeaca0c5cd
commit
3f90333090
3 changed files with 9 additions and 7 deletions
|
|
@ -7,10 +7,11 @@ import (
|
|||
)
|
||||
|
||||
type AppDatabase struct {
|
||||
ServiceName string `json:"PANEL_DB_HOST"`
|
||||
DbName string `json:"PANEL_DB_NAME"`
|
||||
DbUser string `json:"PANEL_DB_USER"`
|
||||
Password string `json:"PANEL_DB_USER_PASSWORD"`
|
||||
ServiceName string `json:"PANEL_DB_HOST"`
|
||||
DbName string `json:"PANEL_DB_NAME"`
|
||||
DbUser string `json:"PANEL_DB_USER"`
|
||||
Password string `json:"PANEL_DB_USER_PASSWORD"`
|
||||
DatabaseName string `json:"DATABASE_NAME"`
|
||||
}
|
||||
|
||||
type AuthParam struct {
|
||||
|
|
|
|||
|
|
@ -483,6 +483,7 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App
|
|||
req.Params["PANEL_DB_HOST"] = database.Address
|
||||
req.Params["PANEL_DB_PORT"] = database.Port
|
||||
req.Params["PANEL_DB_HOST_NAME"] = hostName
|
||||
req.Params["DATABASE_NAME"] = database.Name
|
||||
}
|
||||
}
|
||||
paramByte, err = json.Marshal(req.Params)
|
||||
|
|
|
|||
|
|
@ -141,7 +141,6 @@ func createLink(ctx context.Context, installTask *task.Task, app model.App, appI
|
|||
}
|
||||
_ = deleteLink(del)
|
||||
}
|
||||
var dbConfig dto.AppDatabase
|
||||
if DatabaseKeys[app.Key] > 0 {
|
||||
handleDataBaseApp := func(task *task.Task) error {
|
||||
database := &model.Database{
|
||||
|
|
@ -232,6 +231,7 @@ func createLink(ctx context.Context, installTask *task.Task, app model.App, appI
|
|||
}
|
||||
}
|
||||
|
||||
var dbConfig dto.AppDatabase
|
||||
if app.Type == "website" || app.Type == "tool" {
|
||||
paramByte, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
|
|
@ -258,7 +258,7 @@ func createLink(ctx context.Context, installTask *task.Task, app model.App, appI
|
|||
case constant.AppPostgresql, constant.AppPostgres, constant.AppPostgresqlCluster:
|
||||
oldPostgresqlDb, _ := postgresqlRepo.Get(repo.WithByName(dbConfig.DbName), repo.WithByFrom(constant.ResourceLocal))
|
||||
if oldPostgresqlDb.ID == 0 {
|
||||
oldPostgresqlDb, _ = postgresqlRepo.Get(repo.WithByName(dbConfig.DbName), repo.WithByFrom(constant.AppResourceRemote))
|
||||
oldPostgresqlDb, _ = postgresqlRepo.Get(repo.WithByName(dbConfig.DbName), postgresqlRepo.WithByPostgresqlName(dbConfig.DatabaseName), repo.WithByFrom(constant.AppResourceRemote))
|
||||
}
|
||||
resourceId = oldPostgresqlDb.ID
|
||||
if oldPostgresqlDb.ID > 0 {
|
||||
|
|
@ -283,7 +283,7 @@ func createLink(ctx context.Context, installTask *task.Task, app model.App, appI
|
|||
case constant.AppMysql, constant.AppMariaDB, constant.AppMysqlCluster:
|
||||
oldMysqlDb, _ := mysqlRepo.Get(repo.WithByName(dbConfig.DbName), repo.WithByFrom(constant.ResourceLocal))
|
||||
if oldMysqlDb.ID == 0 {
|
||||
oldMysqlDb, _ = mysqlRepo.Get(repo.WithByName(dbConfig.DbName), repo.WithByFrom(constant.AppResourceRemote))
|
||||
oldMysqlDb, _ = mysqlRepo.Get(repo.WithByName(dbConfig.DbName), mysqlRepo.WithByMysqlName(dbConfig.DatabaseName), repo.WithByFrom(constant.AppResourceRemote))
|
||||
}
|
||||
resourceId = oldMysqlDb.ID
|
||||
if oldMysqlDb.ID > 0 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue