diff --git a/agent/app/repo/app_install.go b/agent/app/repo/app_install.go
index 60b977d81..49be4d148 100644
--- a/agent/app/repo/app_install.go
+++ b/agent/app/repo/app_install.go
@@ -27,7 +27,7 @@ type IAppInstallRepo interface {
WithPort(port int) DBOption
WithIdNotInWebsite() DBOption
WithIDNotIs(id uint) DBOption
- ListBy(opts ...DBOption) ([]model.AppInstall, error)
+ ListBy(ctx context.Context, opts ...DBOption) ([]model.AppInstall, error)
GetFirst(opts ...DBOption) (model.AppInstall, error)
Create(ctx context.Context, install *model.AppInstall) error
Save(ctx context.Context, install *model.AppInstall) error
@@ -109,9 +109,9 @@ func (a *AppInstallRepo) WithIdNotInWebsite() DBOption {
}
}
-func (a *AppInstallRepo) ListBy(opts ...DBOption) ([]model.AppInstall, error) {
+func (a *AppInstallRepo) ListBy(ctx context.Context, opts ...DBOption) ([]model.AppInstall, error) {
var install []model.AppInstall
- db := getDb(opts...).Model(&model.AppInstall{})
+ db := getTx(ctx, opts...).Model(&model.AppInstall{})
err := db.Preload("App").Find(&install).Error
return install, err
}
diff --git a/agent/app/repo/runtime.go b/agent/app/repo/runtime.go
index 0cfe48cae..234568ae5 100644
--- a/agent/app/repo/runtime.go
+++ b/agent/app/repo/runtime.go
@@ -22,7 +22,7 @@ type IRuntimeRepo interface {
Create(ctx context.Context, runtime *model.Runtime) error
Save(runtime *model.Runtime) error
DeleteBy(opts ...DBOption) error
- GetFirst(opts ...DBOption) (*model.Runtime, error)
+ GetFirst(ctx context.Context, opts ...DBOption) (*model.Runtime, error)
List(opts ...DBOption) ([]model.Runtime, error)
}
@@ -94,9 +94,9 @@ func (r *RuntimeRepo) DeleteBy(opts ...DBOption) error {
return getDb(opts...).Delete(&model.Runtime{}).Error
}
-func (r *RuntimeRepo) GetFirst(opts ...DBOption) (*model.Runtime, error) {
+func (r *RuntimeRepo) GetFirst(ctx context.Context, opts ...DBOption) (*model.Runtime, error) {
var runtime model.Runtime
- if err := getDb(opts...).First(&runtime).Error; err != nil {
+ if err := getTx(ctx, opts...).First(&runtime).Error; err != nil {
return nil, err
}
return &runtime, nil
diff --git a/agent/app/service/app.go b/agent/app/service/app.go
index e66441ad7..a781ab4d6 100644
--- a/agent/app/service/app.go
+++ b/agent/app/service/app.go
@@ -143,7 +143,7 @@ func (a AppService) PageApp(ctx *gin.Context, req request.AppSearch) (interface{
continue
}
appDTO.Tags = tags
- installs, _ := appInstallRepo.ListBy(appInstallRepo.WithAppId(ap.ID))
+ installs, _ := appInstallRepo.ListBy(context.Background(), appInstallRepo.WithAppId(ap.ID))
appDTO.Installed = len(installs) > 0
}
res.Items = appDTOs
@@ -349,7 +349,7 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App
err = buserr.WithDetail("Err1PanelNetworkFailed", err.Error(), nil)
return
}
- if list, _ := appInstallRepo.ListBy(repo.WithByLowerName(req.Name)); len(list) > 0 {
+ if list, _ := appInstallRepo.ListBy(context.Background(), repo.WithByLowerName(req.Name)); len(list) > 0 {
err = buserr.New("ErrAppNameExist")
return
}
@@ -455,7 +455,7 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App
containerName := constant.ContainerPrefix + app.Key + "-" + common.RandStr(4)
if req.Advanced && req.ContainerName != "" {
containerName = req.ContainerName
- appInstalls, _ := appInstallRepo.ListBy(appInstallRepo.WithContainerName(containerName))
+ appInstalls, _ := appInstallRepo.ListBy(context.Background(), appInstallRepo.WithContainerName(containerName))
if len(appInstalls) > 0 {
err = buserr.New("ErrContainerName")
return
@@ -684,7 +684,7 @@ func (a AppService) SyncAppListFromLocal(TaskID string) {
} else {
oldAppIds = append(oldAppIds, app.ID)
if app.Status == constant.AppTakeDown {
- installs, _ := appInstallRepo.ListBy(appInstallRepo.WithAppId(app.ID))
+ installs, _ := appInstallRepo.ListBy(context.Background(), appInstallRepo.WithAppId(app.ID))
if len(installs) > 0 {
updateApps = append(updateApps, app)
continue
@@ -894,7 +894,7 @@ var InitTypes = map[string]struct{}{
func deleteCustomApp() {
var appIDS []uint
- installs, _ := appInstallRepo.ListBy()
+ installs, _ := appInstallRepo.ListBy(context.Background())
for _, install := range installs {
appIDS = append(appIDS, install.AppId)
}
@@ -1015,10 +1015,9 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
if _, ok := InitTypes[app.Type]; ok {
dockerComposeUrl := fmt.Sprintf("%s/%s", versionUrl, "docker-compose.yml")
_, composeRes, err := req_helper.HandleRequest(dockerComposeUrl, http.MethodGet, constant.TimeOut20s)
- if err != nil {
- return err
+ if err == nil {
+ detail.DockerCompose = string(composeRes)
}
- detail.DockerCompose = string(composeRes)
} else {
detail.DockerCompose = ""
}
@@ -1052,7 +1051,7 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
addAppArray = append(addAppArray, v)
} else {
if v.Status == constant.AppTakeDown {
- installs, _ := appInstallRepo.ListBy(appInstallRepo.WithAppId(v.ID))
+ installs, _ := appInstallRepo.ListBy(context.Background(), appInstallRepo.WithAppId(v.ID))
if len(installs) > 0 {
updateAppArray = append(updateAppArray, v)
continue
@@ -1124,12 +1123,12 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
addDetails = append(addDetails, d)
} else {
if d.Status == constant.AppTakeDown {
- runtime, _ := runtimeRepo.GetFirst(runtimeRepo.WithDetailId(d.ID))
+ runtime, _ := runtimeRepo.GetFirst(ctx, runtimeRepo.WithDetailId(d.ID))
if runtime != nil {
updateDetails = append(updateDetails, d)
continue
}
- installs, _ := appInstallRepo.ListBy(appInstallRepo.WithDetailIdsIn([]uint{d.ID}))
+ installs, _ := appInstallRepo.ListBy(ctx, appInstallRepo.WithDetailIdsIn([]uint{d.ID}))
if len(installs) > 0 {
updateDetails = append(updateDetails, d)
continue
diff --git a/agent/app/service/app_install.go b/agent/app/service/app_install.go
index a2814b591..99a8e34d8 100644
--- a/agent/app/service/app_install.go
+++ b/agent/app/service/app_install.go
@@ -69,7 +69,7 @@ func NewIAppInstalledService() IAppInstallService {
func (a *AppInstallService) GetInstallList() ([]dto.AppInstallInfo, error) {
var datas []dto.AppInstallInfo
- appInstalls, err := appInstallRepo.ListBy()
+ appInstalls, err := appInstallRepo.ListBy(context.Background())
if err != nil {
return nil, err
}
@@ -113,7 +113,7 @@ func (a *AppInstallService) Page(req request.AppInstalledSearch) (int64, []respo
}
if req.Update {
- installs, err = appInstallRepo.ListBy(opts...)
+ installs, err = appInstallRepo.ListBy(context.Background(), opts...)
if err != nil {
return 0, nil, err
}
@@ -225,12 +225,12 @@ func (a *AppInstallService) SearchForWebsite(req request.AppInstalledSearch) ([]
}
opts = append(opts, appInstallRepo.WithAppIdsIn(ids))
}
- installs, err = appInstallRepo.ListBy(opts...)
+ installs, err = appInstallRepo.ListBy(context.Background(), opts...)
if err != nil {
return nil, err
}
} else {
- installs, err = appInstallRepo.ListBy()
+ installs, err = appInstallRepo.ListBy(context.Background())
if err != nil {
return nil, err
}
@@ -450,7 +450,7 @@ func (a *AppInstallService) IgnoreUpgrade(req request.AppInstalledIgnoreUpgrade)
}
func (a *AppInstallService) SyncAll(systemInit bool) error {
- allList, err := appInstallRepo.ListBy()
+ allList, err := appInstallRepo.ListBy(context.Background())
if err != nil {
return err
}
@@ -510,7 +510,7 @@ func (a *AppInstallService) GetServices(key string) ([]response.AppService, erro
if err != nil {
return nil, err
}
- installs, err := appInstallRepo.ListBy(appInstallRepo.WithAppId(app.ID), appInstallRepo.WithStatus(constant.StatusRunning))
+ installs, err := appInstallRepo.ListBy(context.Background(), appInstallRepo.WithAppId(app.ID), appInstallRepo.WithStatus(constant.StatusRunning))
if err != nil {
return nil, err
}
diff --git a/agent/app/service/app_utils.go b/agent/app/service/app_utils.go
index 30c898128..50fcb5594 100644
--- a/agent/app/service/app_utils.go
+++ b/agent/app/service/app_utils.go
@@ -78,7 +78,7 @@ func checkPort(key string, params map[string]interface{}) (int, error) {
portN = p
}
- oldInstalled, _ := appInstallRepo.ListBy(appInstallRepo.WithPort(portN))
+ oldInstalled, _ := appInstallRepo.ListBy(context.Background(), appInstallRepo.WithPort(portN))
if len(oldInstalled) > 0 {
var apps []string
for _, install := range oldInstalled {
@@ -104,7 +104,7 @@ func checkPortExist(port int) error {
errMap["name"] = appInstall.Name
return buserr.WithMap("ErrPortExist", errMap, nil)
}
- runtime, _ := runtimeRepo.GetFirst(runtimeRepo.WithPort(port))
+ runtime, _ := runtimeRepo.GetFirst(context.Background(), runtimeRepo.WithPort(port))
if runtime != nil {
errMap["type"] = i18n.GetMsgByKey("TYPE_RUNTIME")
errMap["name"] = runtime.Name
@@ -715,7 +715,7 @@ func upgradeInstall(req request.AppInstallUpgrade) error {
_ = fileOp.DeleteDir(path.Join(global.Dir.RuntimeDir, "php"))
websites, _ := websiteRepo.List(repo.WithByType("runtime"))
for _, website := range websites {
- runtime, _ := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID))
+ runtime, _ := runtimeRepo.GetFirst(context.Background(), repo.WithByID(website.RuntimeID))
if runtime != nil && runtime.Type == "php" {
website.Type = constant.Static
website.RuntimeID = 0
@@ -820,7 +820,7 @@ func coverEnvJsonToStr(envJson string) (string, error) {
func checkLimit(app model.App) error {
if app.Limit > 0 {
- installs, err := appInstallRepo.ListBy(appInstallRepo.WithAppId(app.ID))
+ installs, err := appInstallRepo.ListBy(context.Background(), appInstallRepo.WithAppId(app.ID))
if err != nil {
return err
}
diff --git a/agent/app/service/backup_website.go b/agent/app/service/backup_website.go
index da38de27b..ec24dca06 100644
--- a/agent/app/service/backup_website.go
+++ b/agent/app/service/backup_website.go
@@ -1,6 +1,7 @@
package service
import (
+ "context"
"encoding/json"
"fmt"
"io/fs"
@@ -158,7 +159,7 @@ func handleWebsiteRecover(website *model.Website, recoverFile string, isRollback
return err
}
case constant.Runtime:
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(website.RuntimeID))
if err != nil {
return err
}
@@ -240,7 +241,7 @@ func handleWebsiteBackup(website *model.Website, backupDir, fileName, excludes,
}
t.LogSuccess(task.GetTaskName(app.Name, task.TaskBackup, task.TaskScopeApp))
case constant.Runtime:
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(website.RuntimeID))
if err != nil {
return err
}
@@ -287,7 +288,7 @@ func checkValidOfWebsite(oldWebsite, website *model.Website) error {
}
}
if oldWebsite.RuntimeID != 0 {
- if _, err := runtimeRepo.GetFirst(repo.WithByID(oldWebsite.RuntimeID)); err != nil {
+ if _, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(oldWebsite.RuntimeID)); err != nil {
return buserr.WithDetail("ErrBackupMatch", "runtime", nil)
}
}
diff --git a/agent/app/service/cronjob_backup.go b/agent/app/service/cronjob_backup.go
index 619eb4768..8ccf4093e 100644
--- a/agent/app/service/cronjob_backup.go
+++ b/agent/app/service/cronjob_backup.go
@@ -1,6 +1,7 @@
package service
import (
+ "context"
"fmt"
"os"
"path"
@@ -22,7 +23,7 @@ import (
func (u *CronjobService) handleApp(cronjob model.Cronjob, startTime time.Time, taskID string) error {
var apps []model.AppInstall
if cronjob.AppID == "all" {
- apps, _ = appInstallRepo.ListBy()
+ apps, _ = appInstallRepo.ListBy(context.Background())
} else {
itemID, _ := strconv.Atoi(cronjob.AppID)
app, err := appInstallRepo.GetFirst(repo.WithByID(uint(itemID)))
diff --git a/agent/app/service/dashboard.go b/agent/app/service/dashboard.go
index 744ae7cec..caa9da636 100644
--- a/agent/app/service/dashboard.go
+++ b/agent/app/service/dashboard.go
@@ -1,6 +1,7 @@
package service
import (
+ "context"
"encoding/json"
"fmt"
network "net"
@@ -156,7 +157,7 @@ func (u *DashboardService) LoadBaseInfo(ioOption string, netOption string) (*dto
}
baseInfo.SystemProxy = "noProxy"
- appInstall, err := appInstallRepo.ListBy()
+ appInstall, err := appInstallRepo.ListBy(context.Background())
if err != nil {
return nil, err
}
@@ -275,7 +276,7 @@ func (u *DashboardService) LoadAppLauncher() ([]dto.AppLauncher, error) {
data []dto.AppLauncher
recommendList []dto.AppLauncher
)
- appInstalls, err := appInstallRepo.ListBy()
+ appInstalls, err := appInstallRepo.ListBy(context.Background())
if err != nil {
return data, err
}
@@ -346,7 +347,7 @@ func (u *DashboardService) ListLauncherOption(filter string) ([]dto.LauncherOpti
showList := loadShowList()
var data []dto.LauncherOption
optionMap := make(map[string]bool)
- appInstalls, err := appInstallRepo.ListBy()
+ appInstalls, err := appInstallRepo.ListBy(context.Background())
if err != nil {
return data, err
}
diff --git a/agent/app/service/file.go b/agent/app/service/file.go
index 7bb69a8d2..e4de757c1 100644
--- a/agent/app/service/file.go
+++ b/agent/app/service/file.go
@@ -1,6 +1,7 @@
package service
import (
+ "context"
"fmt"
"io"
"io/fs"
@@ -433,7 +434,7 @@ func (f *FileService) ReadLogByLine(req request.FileReadByLineReq) (*response.Fi
}
logFilePath = GetSitePath(website, req.Name)
case constant.TypePhp:
- php, err := runtimeRepo.GetFirst(repo.WithByID(req.ID))
+ php, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(req.ID))
if err != nil {
return nil, err
}
diff --git a/agent/app/service/firewall.go b/agent/app/service/firewall.go
index 2e0108aa5..c0cb9ff39 100644
--- a/agent/app/service/firewall.go
+++ b/agent/app/service/firewall.go
@@ -1,6 +1,7 @@
package service
import (
+ "context"
"fmt"
"os"
"sort"
@@ -514,7 +515,7 @@ type portOfApp struct {
func (u *FirewallService) loadPortByApp() []portOfApp {
var datas []portOfApp
- apps, err := appInstallRepo.ListBy()
+ apps, err := appInstallRepo.ListBy(context.Background())
if err != nil {
return datas
}
diff --git a/agent/app/service/runtime.go b/agent/app/service/runtime.go
index c252c8613..f095697e5 100644
--- a/agent/app/service/runtime.go
+++ b/agent/app/service/runtime.go
@@ -81,7 +81,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
if create.Type != "" {
opts = append(opts, repo.WithByType(create.Type))
}
- exist, _ := runtimeRepo.GetFirst(opts...)
+ exist, _ := runtimeRepo.GetFirst(context.Background(), opts...)
if exist != nil {
return nil, buserr.New("ErrNameIsExist")
}
@@ -106,7 +106,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
}
return nil, runtimeRepo.Create(context.Background(), runtime)
}
- exist, _ = runtimeRepo.GetFirst(runtimeRepo.WithImage(create.Image))
+ exist, _ = runtimeRepo.GetFirst(context.Background(), runtimeRepo.WithImage(create.Image))
if exist != nil {
return nil, buserr.New("ErrImageExist")
}
@@ -227,7 +227,7 @@ func (r *RuntimeService) DeleteCheck(runTimeId uint) ([]dto.AppResource, error)
}
func (r *RuntimeService) Delete(runtimeDelete request.RuntimeDelete) error {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(runtimeDelete.ID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(runtimeDelete.ID))
if err != nil {
return err
}
@@ -268,7 +268,7 @@ func (r *RuntimeService) Delete(runtimeDelete request.RuntimeDelete) error {
}
func (r *RuntimeService) Get(id uint) (*response.RuntimeDTO, error) {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(id))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(id))
if err != nil {
return nil, err
}
@@ -426,7 +426,7 @@ func (r *RuntimeService) Get(id uint) (*response.RuntimeDTO, error) {
}
func (r *RuntimeService) Update(req request.RuntimeUpdate) error {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(req.ID))
if err != nil {
return err
}
@@ -439,7 +439,7 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error {
var hostPorts []string
switch runtime.Type {
case constant.RuntimePHP:
- exist, _ := runtimeRepo.GetFirst(runtimeRepo.WithImage(req.Name), runtimeRepo.WithNotId(req.ID))
+ exist, _ := runtimeRepo.GetFirst(context.Background(), runtimeRepo.WithImage(req.Name), runtimeRepo.WithNotId(req.ID))
if exist != nil {
return buserr.New("ErrImageExist")
}
@@ -557,7 +557,7 @@ func (r *RuntimeService) GetNodePackageRunScript(req request.NodePackageReq) ([]
}
func (r *RuntimeService) OperateRuntime(req request.RuntimeOperate) error {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(req.ID))
if err != nil {
return err
}
@@ -593,7 +593,7 @@ func (r *RuntimeService) OperateRuntime(req request.RuntimeOperate) error {
}
func (r *RuntimeService) GetNodeModules(req request.NodeModuleReq) ([]response.NodeModule, error) {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(req.ID))
if err != nil {
return nil, err
}
@@ -626,7 +626,7 @@ func (r *RuntimeService) GetNodeModules(req request.NodeModuleReq) ([]response.N
}
func (r *RuntimeService) OperateNodeModules(req request.NodeModuleOperateReq) error {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(req.ID))
if err != nil {
return err
}
@@ -689,7 +689,7 @@ func (r *RuntimeService) SyncRuntimeStatus() error {
func (r *RuntimeService) GetPHPExtensions(runtimeID uint) (response.PHPExtensionRes, error) {
var res response.PHPExtensionRes
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(runtimeID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(runtimeID))
if err != nil {
return res, err
}
@@ -729,7 +729,7 @@ func (r *RuntimeService) GetPHPExtensions(runtimeID uint) (response.PHPExtension
}
func (r *RuntimeService) InstallPHPExtension(req request.PHPExtensionInstallReq) error {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(req.ID))
if err != nil {
return err
}
@@ -810,7 +810,7 @@ func (r *RuntimeService) InstallPHPExtension(req request.PHPExtensionInstallReq)
}
func (r *RuntimeService) UnInstallPHPExtension(req request.PHPExtensionInstallReq) error {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(req.ID))
if err != nil {
return err
}
@@ -824,7 +824,7 @@ func (r *RuntimeService) UnInstallPHPExtension(req request.PHPExtensionInstallRe
}
func (r *RuntimeService) GetPHPConfig(id uint) (*response.PHPConfig, error) {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(id))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(id))
if err != nil {
return nil, err
}
@@ -874,7 +874,7 @@ func (r *RuntimeService) GetPHPConfig(id uint) (*response.PHPConfig, error) {
}
func (r *RuntimeService) UpdatePHPConfig(req request.PHPConfigUpdate) (err error) {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(req.ID))
if err != nil {
return err
}
@@ -939,7 +939,7 @@ func (r *RuntimeService) UpdatePHPConfig(req request.PHPConfigUpdate) (err error
}
func (r *RuntimeService) GetPHPConfigFile(req request.PHPFileReq) (*response.FileInfo, error) {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(req.ID))
if err != nil {
return nil, err
}
@@ -961,7 +961,7 @@ func (r *RuntimeService) GetPHPConfigFile(req request.PHPFileReq) (*response.Fil
}
func (r *RuntimeService) UpdatePHPConfigFile(req request.PHPFileUpdate) error {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(req.ID))
if err != nil {
return err
}
@@ -981,7 +981,7 @@ func (r *RuntimeService) UpdatePHPConfigFile(req request.PHPFileUpdate) error {
}
func (r *RuntimeService) UpdateFPMConfig(req request.FPMConfig) error {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(req.ID))
if err != nil {
return err
}
@@ -1019,7 +1019,7 @@ var PmKeys = map[string]struct {
}
func (r *RuntimeService) GetFPMConfig(id uint) (*request.FPMConfig, error) {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(id))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(id))
if err != nil {
return nil, err
}
@@ -1042,7 +1042,7 @@ func (r *RuntimeService) GetFPMConfig(id uint) (*request.FPMConfig, error) {
}
func (r *RuntimeService) GetSupervisorProcess(id uint) ([]response.SupervisorProcessConfig, error) {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(id))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(id))
if err != nil {
return nil, err
}
@@ -1051,7 +1051,7 @@ func (r *RuntimeService) GetSupervisorProcess(id uint) ([]response.SupervisorPro
}
func (r *RuntimeService) OperateSupervisorProcess(req request.PHPSupervisorProcessConfig) error {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(req.ID))
if err != nil {
return err
}
@@ -1060,7 +1060,7 @@ func (r *RuntimeService) OperateSupervisorProcess(req request.PHPSupervisorProce
}
func (r *RuntimeService) OperateSupervisorProcessFile(req request.PHPSupervisorProcessFileReq) (string, error) {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(req.ID))
if err != nil {
return "", err
}
diff --git a/agent/app/service/runtime_utils.go b/agent/app/service/runtime_utils.go
index 9d876b08e..14511df79 100644
--- a/agent/app/service/runtime_utils.go
+++ b/agent/app/service/runtime_utils.go
@@ -727,7 +727,7 @@ func checkRuntimePortExist(port int, scanPort bool, runtimeID uint) error {
if runtimeID > 0 {
opts = append(opts, repo.WithByNOTID(runtimeID))
}
- runtime, _ := runtimeRepo.GetFirst(opts...)
+ runtime, _ := runtimeRepo.GetFirst(context.Background(), opts...)
if runtime != nil {
errMap["type"] = i18n.GetMsgByKey("TYPE_RUNTIME")
errMap["name"] = runtime.Name
diff --git a/agent/app/service/snapshot.go b/agent/app/service/snapshot.go
index 745b744ae..fd5dda1f5 100644
--- a/agent/app/service/snapshot.go
+++ b/agent/app/service/snapshot.go
@@ -181,7 +181,7 @@ func loadOs() string {
func loadApps(fileOp fileUtils.FileOp) ([]dto.DataTree, error) {
var data []dto.DataTree
- apps, err := appInstallRepo.ListBy()
+ apps, err := appInstallRepo.ListBy(context.Background())
if err != nil {
return data, err
}
diff --git a/agent/app/service/snapshot_recover.go b/agent/app/service/snapshot_recover.go
index 6ba546852..398caac0b 100644
--- a/agent/app/service/snapshot_recover.go
+++ b/agent/app/service/snapshot_recover.go
@@ -295,7 +295,7 @@ func recoverAppData(src string, itemHelper *snapRecoverHelper) error {
itemHelper.Task.LogSuccess(i18n.GetMsgByKey("RecoverAppImage"))
}
- appInstalls, err := appInstallRepo.ListBy()
+ appInstalls, err := appInstallRepo.ListBy(context.Background())
itemHelper.Task.LogWithStatus(i18n.GetMsgByKey("RecoverAppList"), err)
if err != nil {
return err
diff --git a/agent/app/service/website.go b/agent/app/service/website.go
index 49d8f7447..b68a68e66 100644
--- a/agent/app/service/website.go
+++ b/agent/app/service/website.go
@@ -170,7 +170,7 @@ func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []respons
appName = appInstall.Name
appInstallID = appInstall.ID
case constant.Runtime:
- runtime, _ := runtimeRepo.GetFirst(repo.WithByID(web.RuntimeID))
+ runtime, _ := runtimeRepo.GetFirst(context.Background(), repo.WithByID(web.RuntimeID))
if runtime != nil {
runtimeName = runtime.Name
runtimeType = runtime.Type
@@ -372,7 +372,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
createTask.AddSubTask(i18n.GetMsgByKey("ConfigApp"), configApp, nil)
}
case constant.Runtime:
- runtime, err = runtimeRepo.GetFirst(repo.WithByID(create.RuntimeID))
+ runtime, err = runtimeRepo.GetFirst(context.Background(), repo.WithByID(create.RuntimeID))
if err != nil {
return err
}
@@ -557,7 +557,7 @@ func (w WebsiteService) GetWebsite(id uint) (response.WebsiteDTO, error) {
res.SitePath = GetSitePath(website, SiteDir)
res.SiteDir = website.SiteDir
if website.Type == constant.Runtime {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(website.RuntimeID))
if err != nil {
return res, err
}
@@ -1146,7 +1146,7 @@ func (w WebsiteService) PreInstallCheck(req request.WebsiteInstallCheckReq) ([]r
checkIds = append(req.InstallIds, appInstall.ID)
}
if len(checkIds) > 0 {
- installList, _ := appInstallRepo.ListBy(repo.WithByIDs(checkIds))
+ installList, _ := appInstallRepo.ListBy(context.Background(), repo.WithByIDs(checkIds))
for _, install := range installList {
if err = syncAppInstallStatus(&install, false); err != nil {
return nil, err
@@ -1338,7 +1338,7 @@ func (w WebsiteService) ChangePHPVersion(req request.WebsitePHPVersionReq) error
return err
}
if website.Type == constant.Runtime {
- oldRuntime, err := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID))
+ oldRuntime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(website.RuntimeID))
if err != nil {
return err
}
@@ -1374,7 +1374,7 @@ func (w WebsiteService) ChangePHPVersion(req request.WebsitePHPVersionReq) error
if req.RuntimeID > 0 {
server.UpdateDirective("index", []string{"index.php index.html index.htm default.php default.htm default.html"})
server.RemoveDirective("location", []string{"~", "[^/]\\.php(/|$)"})
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.RuntimeID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(req.RuntimeID))
if err != nil {
return err
}
@@ -3152,7 +3152,7 @@ func (w WebsiteService) GetWebsiteResource(websiteID uint) ([]response.Resource,
databaseType string
)
if website.Type == constant.Runtime {
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(website.RuntimeID))
if err != nil {
return nil, err
}
diff --git a/agent/app/service/website_utils.go b/agent/app/service/website_utils.go
index 51832ad00..3ef611f20 100644
--- a/agent/app/service/website_utils.go
+++ b/agent/app/service/website_utils.go
@@ -1,6 +1,7 @@
package service
import (
+ "context"
"encoding/json"
"fmt"
"log"
@@ -237,7 +238,7 @@ func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain, a
rootIndex = path.Join("/www/sites", parentWebsite.Alias, "index", website.SiteDir)
server.UpdateDirective("error_page", []string{"404", "/404.html"})
if parentWebsite.Type == constant.Runtime {
- parentRuntime, err := runtimeRepo.GetFirst(repo.WithByID(parentWebsite.RuntimeID))
+ parentRuntime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(parentWebsite.RuntimeID))
if err != nil {
return err
}
@@ -799,7 +800,7 @@ func opWebsite(website *model.Website, operate string) error {
case constant.Deployment:
server.RemoveDirective("location", []string{"/"})
case constant.Runtime:
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(website.RuntimeID))
if err != nil {
return err
}
@@ -845,7 +846,7 @@ func opWebsite(website *model.Website, operate string) error {
case constant.Runtime:
server.UpdateRoot(rootIndex)
localPath := ""
- runtime, err := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID))
+ runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(website.RuntimeID))
if err != nil {
return err
}
@@ -916,7 +917,7 @@ func checkIsLinkApp(website model.Website) bool {
return true
}
if website.Type == constant.Runtime {
- runtime, _ := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID))
+ runtime, _ := runtimeRepo.GetFirst(context.Background(), repo.WithByID(website.RuntimeID))
return runtime.Resource == constant.ResourceAppstore
}
return false
@@ -990,7 +991,7 @@ func getWebsiteDomains(domains []request.WebsiteDomain, defaultPort int, website
err = buserr.WithMap("ErrPortExist", errMap, nil)
return
}
- runtime, _ := runtimeRepo.GetFirst(runtimeRepo.WithPort(port))
+ runtime, _ := runtimeRepo.GetFirst(context.Background(), runtimeRepo.WithPort(port))
if runtime != nil {
errMap["type"] = i18n.GetMsgByKey("TYPE_RUNTIME")
errMap["name"] = runtime.Name
diff --git a/agent/app/task/task.go b/agent/app/task/task.go
index 9c0e10e20..ba4b1836b 100644
--- a/agent/app/task/task.go
+++ b/agent/app/task/task.go
@@ -80,6 +80,7 @@ const (
TaskScopeCompose = "Compose"
TaskScopeImage = "Image"
TaskScopeRuntimeExtension = "RuntimeExtension"
+ TaskScopeCustomAppstore = "CustomAppstore"
)
func GetTaskName(resourceName, operate, scope string) string {
diff --git a/agent/i18n/lang/zh.yaml b/agent/i18n/lang/zh.yaml
index 9e65f8766..cd9818d20 100644
--- a/agent/i18n/lang/zh.yaml
+++ b/agent/i18n/lang/zh.yaml
@@ -96,6 +96,8 @@ CustomAppStoreNotFound: "应用商店包获取失败,请检查是否存在"
CustomAppStoreFileValid: "应用商店包需要 .tar.gz 格式"
PullImageTimeout: "拉取镜像超时,请尝试增加镜像加速或者更换其他镜像加速"
ErrAppIsDown: "{{ .name }} 应用状态异常,请检查"
+ErrCustomApps: "存在已经安装的应用,请先卸载"
+ErrCustomRuntimes: "存在已经安装的运行环境,请先删除"
#file
ErrFileCanNotRead: "此文件不支持预览"
@@ -316,6 +318,7 @@ LocalApp: "本地应用"
SubTask: "子任务"
RuntimeExtension: "运行环境扩展"
TaskIsExecuting: "任务正在运行"
+CustomAppstore: "自定义应用仓库"
# task - ai
OllamaModelPull: "拉取 Ollama 模型 {{ .name }} "
diff --git a/agent/utils/files/file_op.go b/agent/utils/files/file_op.go
index 9c01942d5..44f26644c 100644
--- a/agent/utils/files/file_op.go
+++ b/agent/utils/files/file_op.go
@@ -771,3 +771,33 @@ func (f FileOp) TarGzExtractPro(src, dst string, secret string) error {
}
return cmd.ExecCmdWithDir(commands, dst)
}
+
+func CopyFileWithName(src, dst string, withName bool) error {
+ source, err := os.Open(src)
+ if err != nil {
+ return err
+ }
+ defer source.Close()
+
+ if path.Base(src) != path.Base(dst) && !withName {
+ dst = path.Join(dst, path.Base(src))
+ }
+ if _, err := os.Stat(path.Dir(dst)); err != nil {
+ if os.IsNotExist(err) {
+ _ = os.MkdirAll(path.Dir(dst), os.ModePerm)
+ }
+ }
+ target, err := os.OpenFile(dst+"_temp", os.O_RDWR|os.O_CREATE|os.O_TRUNC, constant.FilePerm)
+ if err != nil {
+ return err
+ }
+ defer target.Close()
+
+ if _, err = io.Copy(target, source); err != nil {
+ return err
+ }
+ if err = os.Rename(dst+"_temp", dst); err != nil {
+ return err
+ }
+ return nil
+}
diff --git a/core/i18n/lang/zh.yaml b/core/i18n/lang/zh.yaml
index da28d4a9f..a0f03eed2 100644
--- a/core/i18n/lang/zh.yaml
+++ b/core/i18n/lang/zh.yaml
@@ -30,6 +30,7 @@ ErrGroupIsDefault: "默认分组,无法删除"
ErrGroupIsInUse: "分组正被使用,无法删除"
ErrLocalDelete: "无法删除本地节点!"
ErrPortInUsed: "{{ .name }} 端口已被占用!"
+ErrInternalServerKey: "服务内部错误:"
#app
CustomAppStoreFileValid: "应用商店包需要 .tar.gz 格式"
diff --git a/core/utils/req_helper/proxy_local/req_to_local.go b/core/utils/req_helper/proxy_local/req_to_local.go
index 81ca707cb..cb2eb3419 100644
--- a/core/utils/req_helper/proxy_local/req_to_local.go
+++ b/core/utils/req_helper/proxy_local/req_to_local.go
@@ -3,14 +3,16 @@ package proxy_local
import (
"context"
"encoding/json"
+ "errors"
"fmt"
+ "github.com/1Panel-dev/1Panel/core/app/dto"
+ "github.com/1Panel-dev/1Panel/core/i18n"
"io"
"net"
"net/http"
"net/url"
"os"
-
- "github.com/1Panel-dev/1Panel/core/app/dto"
+ "strings"
)
func NewLocalClient(reqUrl, reqMethod string, body io.Reader) (interface{}, error) {
@@ -62,7 +64,7 @@ func NewLocalClient(reqUrl, reqMethod string, body io.Reader) (interface{}, erro
return nil, fmt.Errorf("json umarshal resp data failed, err: %v", err)
}
if respJson.Code != http.StatusOK {
- return nil, fmt.Errorf("do request success but handle failed, err: %v", respJson.Message)
+ return nil, errors.New(strings.ReplaceAll(respJson.Message, i18n.Get("ErrInternalServerKey"), ""))
}
return respJson.Data, nil
diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts
index 6f6d3fde8..d468f1fb7 100644
--- a/frontend/src/lang/modules/en.ts
+++ b/frontend/src/lang/modules/en.ts
@@ -2064,8 +2064,9 @@ const message = {
webUIConfig: 'Please add the access address in the application parameters or the app store settings',
toLink: 'Open',
customAppHelper:
- 'The current package is from the main node app store, please modify the configuration on the main node',
+ 'Before installing a custom app store package, please ensure that there are no installed apps.',
forceUninstall: 'Force Uninstall',
+ syncCustomApp: 'Sync Custom App',
},
website: {
primaryDomain: 'Primary Domain',
diff --git a/frontend/src/lang/modules/ja.ts b/frontend/src/lang/modules/ja.ts
index f61ea2d9a..3fdd69350 100644
--- a/frontend/src/lang/modules/ja.ts
+++ b/frontend/src/lang/modules/ja.ts
@@ -1921,8 +1921,9 @@ const message = {
webUIConfig: 'アプリパラメータまたはアプリストア設定でアクセスアドレスを追加してください',
toLink: 'ジャンプ',
customAppHelper:
- '現在のアプリはメインノードストアパッケージを使用しています。設定を変更するにはメインノードで操作してください。',
+ 'カスタムアプリストアパッケージをインストールする前に、インストールされているアプリがないことを確認してください。',
forceUninstall: '強制アンインストール',
+ syncCustomApp: 'カスタムアプリを同期',
},
website: {
primaryDomain: 'プライマリドメイン',
diff --git a/frontend/src/lang/modules/ko.ts b/frontend/src/lang/modules/ko.ts
index 50d6ea2e2..60cb5dad5 100644
--- a/frontend/src/lang/modules/ko.ts
+++ b/frontend/src/lang/modules/ko.ts
@@ -1890,9 +1890,9 @@ const message = {
defaultWebDomainHepler: '애플리케이션 포트가 8080인 경우 접속 주소는 http(s)://기본 접속 주소:8080입니다',
webUIConfig: '애플리케이션 매개변수 또는 앱 스토어 설정에서 접속 주소를 추가하세요',
toLink: '이동',
- customAppHelper:
- '현재 애플리케이션은 메인 노드 스토어 패키지를 사용합니다. 설정을 변경하려면 메인 노드에서 작업하세요.',
+ customAppHelper: '사용자 정의 앱 스토어 패키지를 설치하기 전에 설치된 앱이 없는지 확인하십시오.',
forceUninstall: '강제 제거',
+ syncCustomApp: 'カスタムアプリを同期',
},
website: {
primaryDomain: '기본 도메인',
diff --git a/frontend/src/lang/modules/ms.ts b/frontend/src/lang/modules/ms.ts
index 774c17f91..8a34eec1c 100644
--- a/frontend/src/lang/modules/ms.ts
+++ b/frontend/src/lang/modules/ms.ts
@@ -1975,8 +1975,10 @@ const message = {
'Jika port aplikasi adalah 8080, alamat loncatan akan menjadi http(s)://alamat akses lalai:8080',
webUIConfig: 'Sila tambah alamat akses di parameter aplikasi atau tetapan kedai aplikasi',
toLink: 'Loncat',
- customAppHelper: 'Aplikasi semasa menggunakan pakej kedai nod utama. Sila ubah konfigurasi di nod utama.',
+ customAppHelper:
+ 'Sebelum memasang pakej kedai aplikasi tersuai, sila pastikan tidak ada aplikasi yang dipasang.',
forceUninstall: 'Paksa Nyahpasang',
+ syncCustomApp: 'Segerakan Aplikasi Tersuai',
},
website: {
primaryDomain: 'Domain Utama',
diff --git a/frontend/src/lang/modules/pt-br.ts b/frontend/src/lang/modules/pt-br.ts
index ed26d9e7e..41456b683 100644
--- a/frontend/src/lang/modules/pt-br.ts
+++ b/frontend/src/lang/modules/pt-br.ts
@@ -1967,8 +1967,9 @@ const message = {
'Adicione o endereço de acesso nos parâmetros do aplicativo ou nas configurações da loja de aplicativos',
toLink: 'Ir para',
customAppHelper:
- 'O aplicativo atual usa o pacote da loja do nó principal. Modifique a configuração no nó principal.',
+ 'Antes de instalar um pacote de loja de aplicativos personalizado, certifique-se de que não há aplicativos instalados.',
forceUninstall: 'Desinstalação Forçada',
+ syncCustomApp: 'Sincronizar Aplicativo Personalizado',
},
website: {
primaryDomain: 'Domínio principal',
diff --git a/frontend/src/lang/modules/ru.ts b/frontend/src/lang/modules/ru.ts
index 1095d5c74..73af72425 100644
--- a/frontend/src/lang/modules/ru.ts
+++ b/frontend/src/lang/modules/ru.ts
@@ -1968,8 +1968,9 @@ const message = {
webUIConfig: 'Добавьте адрес доступа в параметры приложения или настройки магазина приложений',
toLink: 'Перейти',
customAppHelper:
- 'Текущее приложение использует пакет магазина главного узла. Измените конфигурацию на главном узле.',
+ 'Перед установкой пользовательского пакета из магазина приложений убедитесь, что нет установленных приложений.',
forceUninstall: 'Принудительное удаление',
+ syncCustomApp: 'Синхронизировать пользовательское приложение',
},
website: {
primaryDomain: 'Основной домен',
diff --git a/frontend/src/lang/modules/zh-Hant.ts b/frontend/src/lang/modules/zh-Hant.ts
index f514a15ce..92bd3f9a3 100644
--- a/frontend/src/lang/modules/zh-Hant.ts
+++ b/frontend/src/lang/modules/zh-Hant.ts
@@ -1910,8 +1910,9 @@ const message = {
'默認訪問用於應用端口跳轉,例如應用端口為 8080 則跳轉地址為 http(s)://默認訪問地址:8080',
webUIConfig: '請在應用參數或者應用商店設置處添加訪問地址',
toLink: '連結',
- customAppHelper: '當前使用的是主節點應用商店包,修改配置請在主節點操作',
+ customAppHelper: '在安裝自訂應用商店包之前,請確保沒有任何已安裝的應用。',
forceUninstall: '強制卸載',
+ syncCustomApp: '同步自訂應用',
},
website: {
primaryDomain: '主域名',
diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts
index 15869edbe..6ff550aa1 100644
--- a/frontend/src/lang/modules/zh.ts
+++ b/frontend/src/lang/modules/zh.ts
@@ -1900,8 +1900,9 @@ const message = {
defaultWebDomainHepler: '如果应用端口为 8080,则跳转地址为 http(s)://默认访问地址:8080',
webUIConfig: '请在应用参数或者应用商店设置处添加访问地址',
toLink: '跳转',
- customAppHelper: '当前使用的是主节点应用商店包,修改配置请在主节点操作',
+ customAppHelper: '在使用自定义应用商店仓库之前,请确保没有任何已安装的应用。',
forceUninstall: '强制卸载',
+ syncCustomApp: '同步自定义应用',
},
website: {
primaryDomain: '主域名',
diff --git a/frontend/src/views/app-store/apps/index.vue b/frontend/src/views/app-store/apps/index.vue
index 147eb7e21..ed5b6b123 100644
--- a/frontend/src/views/app-store/apps/index.vue
+++ b/frontend/src/views/app-store/apps/index.vue
@@ -54,7 +54,7 @@
- {{ $t('app.syncAppList') }}
+ {{ syncCustomAppstore ? $t('app.syncCustomApp') : $t('app.syncAppList') }}
{{ $t('app.syncLocalApp') }}
@@ -167,7 +167,7 @@
-
+