mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-02-08 01:20:07 +08:00
fix: 解决网站一键部署的BUG
This commit is contained in:
parent
8ddaef68cf
commit
e33bf51941
@ -1,7 +1,6 @@
|
|||||||
package v1
|
package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
||||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||||
@ -64,10 +63,13 @@ func (b *BaseApi) InstallApp(c *gin.Context) {
|
|||||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
install, err := appService.Install(context.Background(), req)
|
tx, ctx := helper.GetTxAndContext()
|
||||||
|
install, err := appService.Install(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
tx.Commit()
|
||||||
helper.SuccessWithData(c, install)
|
helper.SuccessWithData(c, install)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package helper
|
package helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/global"
|
||||||
|
"gorm.io/gorm"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@ -103,3 +106,9 @@ func GetIntParamByKey(c *gin.Context, key string) (uint, error) {
|
|||||||
intNum, _ := strconv.Atoi(idParam)
|
intNum, _ := strconv.Atoi(idParam)
|
||||||
return uint(intNum), nil
|
return uint(intNum), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetTxAndContext() (tx *gorm.DB, ctx context.Context) {
|
||||||
|
tx = global.DB.Begin()
|
||||||
|
ctx = context.WithValue(context.Background(), constant.DB, tx)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -215,16 +215,12 @@ func (a AppService) Install(ctx context.Context, req request.AppInstallCreate) (
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, ctx := getTxByContext(ctx)
|
|
||||||
if err := appInstallRepo.Create(ctx, &appInstall); err != nil {
|
if err := appInstallRepo.Create(ctx, &appInstall); err != nil {
|
||||||
tx.Rollback()
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := createLink(ctx, app, &appInstall, req.Params); err != nil {
|
if err := createLink(ctx, app, &appInstall, req.Params); err != nil {
|
||||||
tx.Rollback()
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
tx.Commit()
|
|
||||||
go upApp(appInstall.GetComposePath(), appInstall)
|
go upApp(appInstall.GetComposePath(), appInstall)
|
||||||
go updateToolApp(appInstall)
|
go updateToolApp(appInstall)
|
||||||
return &appInstall, nil
|
return &appInstall, nil
|
||||||
|
@ -93,7 +93,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tx, ctx := getTxAndContext()
|
tx, ctx := getTxAndContext()
|
||||||
|
var appInstall *model.AppInstall
|
||||||
switch create.Type {
|
switch create.Type {
|
||||||
case constant.Deployment:
|
case constant.Deployment:
|
||||||
if create.AppType == constant.NewApp {
|
if create.AppType == constant.NewApp {
|
||||||
@ -101,11 +101,12 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) error {
|
|||||||
req.Name = create.AppInstall.Name
|
req.Name = create.AppInstall.Name
|
||||||
req.AppDetailId = create.AppInstall.AppDetailId
|
req.AppDetailId = create.AppInstall.AppDetailId
|
||||||
req.Params = create.AppInstall.Params
|
req.Params = create.AppInstall.Params
|
||||||
install, err := ServiceGroupApp.Install(ctx, req)
|
var installErr error
|
||||||
if err != nil {
|
appInstall, installErr = ServiceGroupApp.Install(ctx, req)
|
||||||
return err
|
if installErr != nil {
|
||||||
|
return installErr
|
||||||
}
|
}
|
||||||
website.AppInstallID = install.ID
|
website.AppInstallID = appInstall.ID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +138,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := configDefaultNginx(website, domains); err != nil {
|
if err := configDefaultNginx(website, domains, appInstall); err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ func createWebsiteFolder(nginxInstall model.AppInstall, website *model.Website)
|
|||||||
return fileOp.CopyDir(path.Join(nginxFolder, "www", "common", "waf", "rules"), path.Join(siteFolder, "waf"))
|
return fileOp.CopyDir(path.Join(nginxFolder, "www", "common", "waf", "rules"), path.Join(siteFolder, "waf"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain) error {
|
func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain, appInstall *model.AppInstall) error {
|
||||||
nginxInstall, err := getAppInstallByKey(constant.AppNginx)
|
nginxInstall, err := getAppInstallByKey(constant.AppNginx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -136,10 +136,6 @@ func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain) e
|
|||||||
|
|
||||||
switch website.Type {
|
switch website.Type {
|
||||||
case constant.Deployment:
|
case constant.Deployment:
|
||||||
appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
proxy := fmt.Sprintf("http://127.0.0.1:%d", appInstall.HttpPort)
|
proxy := fmt.Sprintf("http://127.0.0.1:%d", appInstall.HttpPort)
|
||||||
server.UpdateRootProxy([]string{proxy})
|
server.UpdateRootProxy([]string{proxy})
|
||||||
case constant.Static:
|
case constant.Static:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user