Skip to content

Commit e5660a0

Browse files
feat: merge from dev (#7238)
1 parent 841d1a3 commit e5660a0

File tree

51 files changed

+1245
-352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1245
-352
lines changed

agent/app/dto/app.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ type Tag struct {
115115
}
116116

117117
type AppForm struct {
118-
FormFields []AppFormFields `json:"formFields"`
118+
FormFields []AppFormFields `json:"formFields"`
119+
SupportVersion float64 `json:"supportVersion"`
119120
}
120121

121122
type AppFormFields struct {

agent/app/dto/dashboard.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type DashboardCurrent struct {
9393
NetBytesRecv uint64 `json:"netBytesRecv"`
9494

9595
GPUData []GPUInfo `json:"gpuData"`
96+
XPUData []XPUInfo `json:"xpuData"`
9697

9798
ShotTime time.Time `json:"shotTime"`
9899
}
@@ -141,6 +142,7 @@ type AppLauncher struct {
141142
IsRecommend bool `json:"isRecommend"`
142143
Detail []InstallDetail `json:"detail"`
143144
}
145+
144146
type InstallDetail struct {
145147
InstallID uint `json:"installID"`
146148
DetailID uint `json:"detailID"`
@@ -152,7 +154,18 @@ type InstallDetail struct {
152154
HttpPort int `json:"httpPort"`
153155
HttpsPort int `json:"httpsPort"`
154156
}
157+
155158
type LauncherOption struct {
156159
Key string `json:"key"`
157160
IsShow bool `json:"isShow"`
158161
}
162+
163+
type XPUInfo struct {
164+
DeviceID int `json:"deviceID"`
165+
DeviceName string `json:"deviceName"`
166+
Memory string `json:"memory"`
167+
Temperature string `json:"temperature"`
168+
MemoryUsed string `json:"memoryUsed"`
169+
Power string `json:"power"`
170+
MemoryUtil string `json:"memoryUtil"`
171+
}

agent/app/dto/request/website.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,21 +199,22 @@ type WebsiteUpdateDirPermission struct {
199199
}
200200

201201
type WebsiteProxyConfig struct {
202-
ID uint `json:"id" validate:"required"`
203-
Operate string `json:"operate" validate:"required"`
204-
Enable bool `json:"enable" `
205-
Cache bool `json:"cache" `
206-
CacheTime int `json:"cacheTime" `
207-
CacheUnit string `json:"cacheUnit"`
208-
Name string `json:"name" validate:"required"`
209-
Modifier string `json:"modifier"`
210-
Match string `json:"match" validate:"required"`
211-
ProxyPass string `json:"proxyPass" validate:"required"`
212-
ProxyHost string `json:"proxyHost" validate:"required"`
213-
Content string `json:"content"`
214-
FilePath string `json:"filePath"`
215-
Replaces map[string]string `json:"replaces"`
216-
SNI bool `json:"sni"`
202+
ID uint `json:"id" validate:"required"`
203+
Operate string `json:"operate" validate:"required"`
204+
Enable bool `json:"enable" `
205+
Cache bool `json:"cache" `
206+
CacheTime int `json:"cacheTime" `
207+
CacheUnit string `json:"cacheUnit"`
208+
Name string `json:"name" validate:"required"`
209+
Modifier string `json:"modifier"`
210+
Match string `json:"match" validate:"required"`
211+
ProxyPass string `json:"proxyPass" validate:"required"`
212+
ProxyHost string `json:"proxyHost" validate:"required"`
213+
Content string `json:"content"`
214+
FilePath string `json:"filePath"`
215+
Replaces map[string]string `json:"replaces"`
216+
SNI bool `json:"sni"`
217+
ProxySSLName string `json:"proxySSLName"`
217218
}
218219

219220
type WebsiteProxyReq struct {

agent/app/dto/request/website_ssl.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type WebsiteSSLApply struct {
4141
ID uint `json:"ID" validate:"required"`
4242
SkipDNSCheck bool `json:"skipDNSCheck"`
4343
Nameservers []string `json:"nameservers"`
44+
DisableLog bool `json:"disableLog"`
4445
}
4546

4647
type WebsiteAcmeAccountCreate struct {

agent/app/service/app.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,10 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
863863
settingService := NewISettingService()
864864
_ = settingService.Update("AppStoreSyncStatus", constant.Syncing)
865865

866+
setting, err := settingService.GetSettingInfo()
867+
if err != nil {
868+
return err
869+
}
866870
var (
867871
tags []*model.Tag
868872
appTags []*model.AppTag
@@ -886,10 +890,6 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
886890
transport := xpack.LoadRequestTransport()
887891
baseRemoteUrl := fmt.Sprintf("%s/%s/1panel", global.CONF.System.AppRepo, global.CONF.System.Mode)
888892

889-
setting, err := NewISettingService().GetSettingInfo()
890-
if err != nil {
891-
return err
892-
}
893893
appsMap := getApps(oldApps, list.Apps, setting.SystemVersion, t)
894894

895895
t.LogStart(i18n.GetMsgByKey("SyncAppDetail"))
@@ -919,7 +919,13 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
919919
version := v.Name
920920
detail := detailsMap[version]
921921
versionUrl := fmt.Sprintf("%s/%s/%s", baseRemoteUrl, app.Key, version)
922-
922+
paramByte, _ := json.Marshal(v.AppForm)
923+
var appForm dto.AppForm
924+
_ = json.Unmarshal(paramByte, &appForm)
925+
if appForm.SupportVersion > 0 && common.CompareVersion(strconv.FormatFloat(appForm.SupportVersion, 'f', -1, 64), setting.SystemVersion) {
926+
delete(detailsMap, version)
927+
continue
928+
}
923929
if _, ok := InitTypes[app.Type]; ok {
924930
dockerComposeUrl := fmt.Sprintf("%s/%s", versionUrl, "docker-compose.yml")
925931
_, composeRes, err := httpUtil.HandleGetWithTransport(dockerComposeUrl, http.MethodGet, transport, constant.TimeOut20s)
@@ -931,7 +937,6 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
931937
detail.DockerCompose = ""
932938
}
933939

934-
paramByte, _ := json.Marshal(v.AppForm)
935940
detail.Params = string(paramByte)
936941
detail.DownloadUrl = fmt.Sprintf("%s/%s", versionUrl, app.Key+"-"+version+".tar.gz")
937942
detail.DownloadCallBackUrl = v.DownloadCallBackUrl

agent/app/service/app_utils.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ func upgradeInstall(req request.AppInstallUpgrade) error {
597597
_ = appDetailRepo.Update(context.Background(), detail)
598598
}
599599
go func() {
600-
_, _, _ = httpUtil.HandleGet(detail.DownloadCallBackUrl, http.MethodGet, constant.TimeOut5s)
600+
RequestDownloadCallBack(detail.DownloadCallBackUrl)
601601
}()
602602
}
603603
if install.App.Resource == constant.AppResourceLocal {
@@ -925,7 +925,7 @@ func copyData(task *task.Task, app model.App, appDetail model.AppDetail, appInst
925925
return
926926
}
927927
go func() {
928-
_, _, _ = httpUtil.HandleGet(appDetail.DownloadCallBackUrl, http.MethodGet, constant.TimeOut5s)
928+
RequestDownloadCallBack(appDetail.DownloadCallBackUrl)
929929
}()
930930
}
931931
appKey := app.Key
@@ -1232,11 +1232,7 @@ func handleLocalAppDetail(versionDir string, appDetail *model.AppDetail) error {
12321232
return buserr.WithMap(constant.ErrFileParseApp, map[string]interface{}{"name": "data.yml", "err": err.Error()}, err)
12331233
}
12341234

1235-
additionalProperties, ok := dataMap["additionalProperties"].(map[string]interface{})
1236-
if !ok {
1237-
return buserr.WithName(constant.ErrAppParamKey, "additionalProperties")
1238-
}
1239-
1235+
additionalProperties, _ := dataMap["additionalProperties"].(map[string]interface{})
12401236
formFieldsInterface, ok := additionalProperties["formFields"]
12411237
if ok {
12421238
formFields, ok := formFieldsInterface.([]interface{})
@@ -1463,6 +1459,17 @@ func handleInstalled(appInstallList []model.AppInstall, updated bool, sync bool)
14631459
continue
14641460
}
14651461
lastVersion := versions[0]
1462+
if app.Key == constant.AppMysql {
1463+
for _, version := range versions {
1464+
majorVersion := getMajorVersion(installed.Version)
1465+
if !strings.HasPrefix(version, majorVersion) {
1466+
continue
1467+
} else {
1468+
lastVersion = version
1469+
break
1470+
}
1471+
}
1472+
}
14661473
if common.IsCrossVersion(installed.Version, lastVersion) {
14671474
installDTO.CanUpdate = app.CrossVersionUpdate
14681475
} else {
@@ -1729,3 +1736,10 @@ func ignoreUpdate(installed model.AppInstall) bool {
17291736
}
17301737
return false
17311738
}
1739+
1740+
func RequestDownloadCallBack(downloadCallBackUrl string) {
1741+
if downloadCallBackUrl == "" {
1742+
return
1743+
}
1744+
_, _, _ = httpUtil.HandleGet(downloadCallBackUrl, http.MethodGet, constant.TimeOut5s)
1745+
}

agent/app/service/dashboard.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ func (u *DashboardService) LoadCurrentInfo(ioOption string, netOption string) *d
203203

204204
currentInfo.DiskData = loadDiskInfo()
205205
currentInfo.GPUData = loadGPUInfo()
206+
currentInfo.XPUData = loadXpuInfo()
206207

207208
if ioOption == "all" {
208209
diskInfo, _ := disk.IOCounters()
@@ -501,3 +502,19 @@ func ArryContains(arr []string, element string) bool {
501502
}
502503
return false
503504
}
505+
506+
func loadXpuInfo() []dto.XPUInfo {
507+
list := xpack.LoadXpuInfo()
508+
if len(list) == 0 {
509+
return nil
510+
}
511+
var data []dto.XPUInfo
512+
for _, gpu := range list {
513+
var dataItem dto.XPUInfo
514+
if err := copier.Copy(&dataItem, &gpu); err != nil {
515+
continue
516+
}
517+
data = append(data, dataItem)
518+
}
519+
return data
520+
}

agent/app/service/runtime.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
7575
opts []repo.DBOption
7676
)
7777
if create.Name != "" {
78-
opts = append(opts, commonRepo.WithByLikeName(create.Name))
78+
opts = append(opts, commonRepo.WithByName(create.Name))
7979
}
8080
if create.Type != "" {
8181
opts = append(opts, commonRepo.WithByType(create.Type))
@@ -108,7 +108,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
108108
return nil, err
109109
}
110110
}
111-
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
111+
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython, constant.RuntimeDotNet:
112112
if !fileOp.Stat(create.CodeDir) {
113113
return nil, buserr.New(constant.ErrPathNotFound)
114114
}
@@ -140,7 +140,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
140140
}
141141

142142
appVersionDir := filepath.Join(app.GetAppResourcePath(), appDetail.Version)
143-
if !fileOp.Stat(appVersionDir) || appDetail.Update {
143+
if !fileOp.Stat(appVersionDir) {
144144
if err = downloadApp(app, appDetail, nil, nil); err != nil {
145145
return nil, err
146146
}
@@ -162,7 +162,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
162162
if err = handlePHP(create, runtime, fileOp, appVersionDir); err != nil {
163163
return nil, err
164164
}
165-
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
165+
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython, constant.RuntimeDotNet:
166166
runtime.Port = int(create.Params["port"].(float64))
167167
if err = handleNodeAndJava(create, runtime, fileOp, appVersionDir); err != nil {
168168
return nil, err
@@ -341,7 +341,7 @@ func (r *RuntimeService) Get(id uint) (*response.RuntimeDTO, error) {
341341
}
342342
}
343343
res.AppParams = appParams
344-
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
344+
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython, constant.RuntimeDotNet:
345345
res.Params = make(map[string]interface{})
346346
envs, err := gotenv.Unmarshal(runtime.Env)
347347
if err != nil {
@@ -440,7 +440,7 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error {
440440
if exist != nil {
441441
return buserr.New(constant.ErrImageExist)
442442
}
443-
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
443+
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython, constant.RuntimeDotNet:
444444
if runtime.Port != req.Port {
445445
if err = checkPortExist(req.Port); err != nil {
446446
return err
@@ -516,7 +516,7 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error {
516516
return err
517517
}
518518
go buildRuntime(runtime, imageID, oldEnv, req.Rebuild)
519-
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
519+
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython, constant.RuntimeDotNet:
520520
runtime.Version = req.Version
521521
runtime.CodeDir = req.CodeDir
522522
runtime.Port = req.Port
@@ -682,7 +682,7 @@ func (r *RuntimeService) SyncRuntimeStatus() error {
682682
return err
683683
}
684684
for _, runtime := range runtimes {
685-
if runtime.Type == constant.RuntimeNode || runtime.Type == constant.RuntimeJava || runtime.Type == constant.RuntimeGo || runtime.Type == constant.RuntimePython {
685+
if runtime.Type == constant.RuntimeNode || runtime.Type == constant.RuntimeJava || runtime.Type == constant.RuntimeGo || runtime.Type == constant.RuntimePython || runtime.Type == constant.RuntimeDotNet {
686686
_ = SyncRuntimeContainerStatus(&runtime)
687687
}
688688
}

agent/app/service/runtime_utils.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package service
33
import (
44
"bufio"
55
"bytes"
6+
"context"
67
"encoding/json"
78
"fmt"
89
"github.com/1Panel-dev/1Panel/agent/app/dto"
@@ -17,12 +18,10 @@ import (
1718
"github.com/1Panel-dev/1Panel/agent/utils/compose"
1819
"github.com/1Panel-dev/1Panel/agent/utils/docker"
1920
"github.com/1Panel-dev/1Panel/agent/utils/files"
20-
httpUtil "github.com/1Panel-dev/1Panel/agent/utils/http"
2121
"github.com/pkg/errors"
2222
"github.com/subosito/gotenv"
2323
"gopkg.in/yaml.v3"
2424
"io"
25-
"net/http"
2625
"os"
2726
"os/exec"
2827
"path"
@@ -61,10 +60,7 @@ func handleNodeAndJava(create request.RuntimeCreate, runtime *model.Runtime, fil
6160
}
6261

6362
go func() {
64-
if _, _, err := httpUtil.HandleGet(nodeDetail.DownloadCallBackUrl, http.MethodGet, constant.TimeOut5s); err != nil {
65-
global.LOG.Errorf("http request failed(handleNode), err: %v", err)
66-
return
67-
}
63+
RequestDownloadCallBack(nodeDetail.DownloadCallBackUrl)
6864
}()
6965
go startRuntime(runtime)
7066

@@ -221,7 +217,10 @@ func buildRuntime(runtime *model.Runtime, oldImageID string, oldEnv string, rebu
221217
_ = logFile.Close()
222218
}()
223219

224-
cmd := exec.Command("docker", "compose", "-f", composePath, "build")
220+
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Hour)
221+
defer cancel()
222+
223+
cmd := exec.CommandContext(ctx, "docker-compose", "-f", composePath, "build")
225224
cmd.Stdout = logFile
226225
var stderrBuf bytes.Buffer
227226
multiWriterStderr := io.MultiWriter(&stderrBuf, logFile)
@@ -231,8 +230,10 @@ func buildRuntime(runtime *model.Runtime, oldImageID string, oldEnv string, rebu
231230
if err != nil {
232231
runtime.Status = constant.RuntimeError
233232
runtime.Message = buserr.New(constant.ErrImageBuildErr).Error() + ":" + stderrBuf.String()
234-
if stderrBuf.String() == "" {
235-
runtime.Message = buserr.New(constant.ErrImageBuildErr).Error() + ":" + err.Error()
233+
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
234+
runtime.Message = buserr.New(constant.ErrImageBuildErr).Error() + ":" + buserr.New("ErrCmdTimeout").Error()
235+
} else {
236+
runtime.Message = buserr.New(constant.ErrImageBuildErr).Error() + ":" + stderrBuf.String()
236237
}
237238
} else {
238239
if err = runComposeCmdWithLog(constant.RuntimeDown, runtime.GetComposePath(), runtime.GetLogPath()); err != nil {
@@ -393,6 +394,14 @@ func handleParams(create request.RuntimeCreate, projectDir string) (composeConte
393394
if err != nil {
394395
return
395396
}
397+
case constant.RuntimeDotNet:
398+
create.Params["CODE_DIR"] = create.CodeDir
399+
create.Params["DOTNET_VERSION"] = create.Version
400+
create.Params["PANEL_APP_PORT_HTTP"] = create.Port
401+
composeContent, err = handleCompose(env, composeContent, create, projectDir)
402+
if err != nil {
403+
return
404+
}
396405
}
397406

398407
newMap := make(map[string]string)
@@ -438,7 +447,7 @@ func handleCompose(env gotenv.Env, composeContent []byte, create request.Runtime
438447
ports = append(ports, "${HOST_IP}:${PANEL_APP_PORT_HTTP}:${JAVA_APP_PORT}")
439448
case constant.RuntimeGo:
440449
ports = append(ports, "${HOST_IP}:${PANEL_APP_PORT_HTTP}:${GO_APP_PORT}")
441-
case constant.RuntimePython:
450+
case constant.RuntimePython, constant.RuntimeDotNet:
442451
ports = append(ports, "${HOST_IP}:${PANEL_APP_PORT_HTTP}:${APP_PORT}")
443452

444453
}

0 commit comments

Comments
 (0)