Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: merge from dev #7238

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion agent/app/dto/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ type Tag struct {
}

type AppForm struct {
FormFields []AppFormFields `json:"formFields"`
FormFields []AppFormFields `json:"formFields"`
SupportVersion float64 `json:"supportVersion"`
}

type AppFormFields struct {
Expand Down
13 changes: 13 additions & 0 deletions agent/app/dto/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type DashboardCurrent struct {
NetBytesRecv uint64 `json:"netBytesRecv"`

GPUData []GPUInfo `json:"gpuData"`
XPUData []XPUInfo `json:"xpuData"`

ShotTime time.Time `json:"shotTime"`
}
Expand Down Expand Up @@ -141,6 +142,7 @@ type AppLauncher struct {
IsRecommend bool `json:"isRecommend"`
Detail []InstallDetail `json:"detail"`
}

type InstallDetail struct {
InstallID uint `json:"installID"`
DetailID uint `json:"detailID"`
Expand All @@ -152,7 +154,18 @@ type InstallDetail struct {
HttpPort int `json:"httpPort"`
HttpsPort int `json:"httpsPort"`
}

type LauncherOption struct {
Key string `json:"key"`
IsShow bool `json:"isShow"`
}

type XPUInfo struct {
DeviceID int `json:"deviceID"`
DeviceName string `json:"deviceName"`
Memory string `json:"memory"`
Temperature string `json:"temperature"`
MemoryUsed string `json:"memoryUsed"`
Power string `json:"power"`
MemoryUtil string `json:"memoryUtil"`
}
31 changes: 16 additions & 15 deletions agent/app/dto/request/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,22 @@ type WebsiteUpdateDirPermission struct {
}

type WebsiteProxyConfig struct {
ID uint `json:"id" validate:"required"`
Operate string `json:"operate" validate:"required"`
Enable bool `json:"enable" `
Cache bool `json:"cache" `
CacheTime int `json:"cacheTime" `
CacheUnit string `json:"cacheUnit"`
Name string `json:"name" validate:"required"`
Modifier string `json:"modifier"`
Match string `json:"match" validate:"required"`
ProxyPass string `json:"proxyPass" validate:"required"`
ProxyHost string `json:"proxyHost" validate:"required"`
Content string `json:"content"`
FilePath string `json:"filePath"`
Replaces map[string]string `json:"replaces"`
SNI bool `json:"sni"`
ID uint `json:"id" validate:"required"`
Operate string `json:"operate" validate:"required"`
Enable bool `json:"enable" `
Cache bool `json:"cache" `
CacheTime int `json:"cacheTime" `
CacheUnit string `json:"cacheUnit"`
Name string `json:"name" validate:"required"`
Modifier string `json:"modifier"`
Match string `json:"match" validate:"required"`
ProxyPass string `json:"proxyPass" validate:"required"`
ProxyHost string `json:"proxyHost" validate:"required"`
Content string `json:"content"`
FilePath string `json:"filePath"`
Replaces map[string]string `json:"replaces"`
SNI bool `json:"sni"`
ProxySSLName string `json:"proxySSLName"`
}

type WebsiteProxyReq struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry, but it seems you've sent an incomplete code snippet containing multiple lines that doesn't provide enough context to analyze whether there is irregularity, issue, or need for optimization. You also didn't mention what platform you're referring to (like GoLand/VSCode etc.) which is essential when discussing code files with known file types.

For instance:

  • If the code represents C++ classes and methods, we might suggest checking against existing standards or guidelines.
    • If this was written for Python using Django, we would focus more on django's documentation.

So please paste back the full codes or give us the platforms and languages involved so I can better assist you!

Expand Down
1 change: 1 addition & 0 deletions agent/app/dto/request/website_ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type WebsiteSSLApply struct {
ID uint `json:"ID" validate:"required"`
SkipDNSCheck bool `json:"skipDNSCheck"`
Nameservers []string `json:"nameservers"`
DisableLog bool `json:"disableLog"`
}

type WebsiteAcmeAccountCreate struct {
Expand Down
17 changes: 11 additions & 6 deletions agent/app/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,10 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
settingService := NewISettingService()
_ = settingService.Update("AppStoreSyncStatus", constant.Syncing)

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

setting, err := NewISettingService().GetSettingInfo()
if err != nil {
return err
}
appsMap := getApps(oldApps, list.Apps, setting.SystemVersion, t)

t.LogStart(i18n.GetMsgByKey("SyncAppDetail"))
Expand Down Expand Up @@ -919,7 +919,13 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
version := v.Name
detail := detailsMap[version]
versionUrl := fmt.Sprintf("%s/%s/%s", baseRemoteUrl, app.Key, version)

paramByte, _ := json.Marshal(v.AppForm)
var appForm dto.AppForm
_ = json.Unmarshal(paramByte, &appForm)
if appForm.SupportVersion > 0 && common.CompareVersion(strconv.FormatFloat(appForm.SupportVersion, 'f', -1, 64), setting.SystemVersion) {
delete(detailsMap, version)
continue
}
if _, ok := InitTypes[app.Type]; ok {
dockerComposeUrl := fmt.Sprintf("%s/%s", versionUrl, "docker-compose.yml")
_, composeRes, err := httpUtil.HandleGetWithTransport(dockerComposeUrl, http.MethodGet, transport, constant.TimeOut20s)
Expand All @@ -931,7 +937,6 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
detail.DockerCompose = ""
}

paramByte, _ := json.Marshal(v.AppForm)
detail.Params = string(paramByte)
detail.DownloadUrl = fmt.Sprintf("%s/%s", versionUrl, app.Key+"-"+version+".tar.gz")
detail.DownloadCallBackUrl = v.DownloadCallBackUrl
Expand Down
28 changes: 21 additions & 7 deletions agent/app/service/app_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ func upgradeInstall(req request.AppInstallUpgrade) error {
_ = appDetailRepo.Update(context.Background(), detail)
}
go func() {
_, _, _ = httpUtil.HandleGet(detail.DownloadCallBackUrl, http.MethodGet, constant.TimeOut5s)
RequestDownloadCallBack(detail.DownloadCallBackUrl)
}()
}
if install.App.Resource == constant.AppResourceLocal {
Expand Down Expand Up @@ -925,7 +925,7 @@ func copyData(task *task.Task, app model.App, appDetail model.AppDetail, appInst
return
}
go func() {
_, _, _ = httpUtil.HandleGet(appDetail.DownloadCallBackUrl, http.MethodGet, constant.TimeOut5s)
RequestDownloadCallBack(appDetail.DownloadCallBackUrl)
}()
}
appKey := app.Key
Expand Down Expand Up @@ -1232,11 +1232,7 @@ func handleLocalAppDetail(versionDir string, appDetail *model.AppDetail) error {
return buserr.WithMap(constant.ErrFileParseApp, map[string]interface{}{"name": "data.yml", "err": err.Error()}, err)
}

additionalProperties, ok := dataMap["additionalProperties"].(map[string]interface{})
if !ok {
return buserr.WithName(constant.ErrAppParamKey, "additionalProperties")
}

additionalProperties, _ := dataMap["additionalProperties"].(map[string]interface{})
formFieldsInterface, ok := additionalProperties["formFields"]
if ok {
formFields, ok := formFieldsInterface.([]interface{})
Expand Down Expand Up @@ -1463,6 +1459,17 @@ func handleInstalled(appInstallList []model.AppInstall, updated bool, sync bool)
continue
}
lastVersion := versions[0]
if app.Key == constant.AppMysql {
for _, version := range versions {
majorVersion := getMajorVersion(installed.Version)
if !strings.HasPrefix(version, majorVersion) {
continue
} else {
lastVersion = version
break
}
}
}
if common.IsCrossVersion(installed.Version, lastVersion) {
installDTO.CanUpdate = app.CrossVersionUpdate
} else {
Expand Down Expand Up @@ -1729,3 +1736,10 @@ func ignoreUpdate(installed model.AppInstall) bool {
}
return false
}

func RequestDownloadCallBack(downloadCallBackUrl string) {
if downloadCallBackUrl == "" {
return
}
_, _, _ = httpUtil.HandleGet(downloadCallBackUrl, http.MethodGet, constant.TimeOut5s)
}
17 changes: 17 additions & 0 deletions agent/app/service/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func (u *DashboardService) LoadCurrentInfo(ioOption string, netOption string) *d

currentInfo.DiskData = loadDiskInfo()
currentInfo.GPUData = loadGPUInfo()
currentInfo.XPUData = loadXpuInfo()

if ioOption == "all" {
diskInfo, _ := disk.IOCounters()
Expand Down Expand Up @@ -501,3 +502,19 @@ func ArryContains(arr []string, element string) bool {
}
return false
}

func loadXpuInfo() []dto.XPUInfo {
list := xpack.LoadXpuInfo()
if len(list) == 0 {
return nil
}
var data []dto.XPUInfo
for _, gpu := range list {
var dataItem dto.XPUInfo
if err := copier.Copy(&dataItem, &gpu); err != nil {
continue
}
data = append(data, dataItem)
}
return data
}
16 changes: 8 additions & 8 deletions agent/app/service/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
opts []repo.DBOption
)
if create.Name != "" {
opts = append(opts, commonRepo.WithByLikeName(create.Name))
opts = append(opts, commonRepo.WithByName(create.Name))
}
if create.Type != "" {
opts = append(opts, commonRepo.WithByType(create.Type))
Expand Down Expand Up @@ -108,7 +108,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
return nil, err
}
}
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython, constant.RuntimeDotNet:
if !fileOp.Stat(create.CodeDir) {
return nil, buserr.New(constant.ErrPathNotFound)
}
Expand Down Expand Up @@ -140,7 +140,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
}

appVersionDir := filepath.Join(app.GetAppResourcePath(), appDetail.Version)
if !fileOp.Stat(appVersionDir) || appDetail.Update {
if !fileOp.Stat(appVersionDir) {
if err = downloadApp(app, appDetail, nil, nil); err != nil {
return nil, err
}
Expand All @@ -162,7 +162,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
if err = handlePHP(create, runtime, fileOp, appVersionDir); err != nil {
return nil, err
}
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython, constant.RuntimeDotNet:
runtime.Port = int(create.Params["port"].(float64))
if err = handleNodeAndJava(create, runtime, fileOp, appVersionDir); err != nil {
return nil, err
Expand Down Expand Up @@ -341,7 +341,7 @@ func (r *RuntimeService) Get(id uint) (*response.RuntimeDTO, error) {
}
}
res.AppParams = appParams
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython, constant.RuntimeDotNet:
res.Params = make(map[string]interface{})
envs, err := gotenv.Unmarshal(runtime.Env)
if err != nil {
Expand Down Expand Up @@ -440,7 +440,7 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error {
if exist != nil {
return buserr.New(constant.ErrImageExist)
}
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython, constant.RuntimeDotNet:
if runtime.Port != req.Port {
if err = checkPortExist(req.Port); err != nil {
return err
Expand Down Expand Up @@ -516,7 +516,7 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error {
return err
}
go buildRuntime(runtime, imageID, oldEnv, req.Rebuild)
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython, constant.RuntimeDotNet:
runtime.Version = req.Version
runtime.CodeDir = req.CodeDir
runtime.Port = req.Port
Expand Down Expand Up @@ -682,7 +682,7 @@ func (r *RuntimeService) SyncRuntimeStatus() error {
return err
}
for _, runtime := range runtimes {
if runtime.Type == constant.RuntimeNode || runtime.Type == constant.RuntimeJava || runtime.Type == constant.RuntimeGo || runtime.Type == constant.RuntimePython {
if runtime.Type == constant.RuntimeNode || runtime.Type == constant.RuntimeJava || runtime.Type == constant.RuntimeGo || runtime.Type == constant.RuntimePython || runtime.Type == constant.RuntimeDotNet {
_ = SyncRuntimeContainerStatus(&runtime)
}
}
Expand Down
29 changes: 19 additions & 10 deletions agent/app/service/runtime_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package service
import (
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/1Panel-dev/1Panel/agent/app/dto"
Expand All @@ -17,12 +18,10 @@ import (
"github.com/1Panel-dev/1Panel/agent/utils/compose"
"github.com/1Panel-dev/1Panel/agent/utils/docker"
"github.com/1Panel-dev/1Panel/agent/utils/files"
httpUtil "github.com/1Panel-dev/1Panel/agent/utils/http"
"github.com/pkg/errors"
"github.com/subosito/gotenv"
"gopkg.in/yaml.v3"
"io"
"net/http"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -61,10 +60,7 @@ func handleNodeAndJava(create request.RuntimeCreate, runtime *model.Runtime, fil
}

go func() {
if _, _, err := httpUtil.HandleGet(nodeDetail.DownloadCallBackUrl, http.MethodGet, constant.TimeOut5s); err != nil {
global.LOG.Errorf("http request failed(handleNode), err: %v", err)
return
}
RequestDownloadCallBack(nodeDetail.DownloadCallBackUrl)
}()
go startRuntime(runtime)

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

cmd := exec.Command("docker", "compose", "-f", composePath, "build")
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Hour)
defer cancel()

cmd := exec.CommandContext(ctx, "docker-compose", "-f", composePath, "build")
cmd.Stdout = logFile
var stderrBuf bytes.Buffer
multiWriterStderr := io.MultiWriter(&stderrBuf, logFile)
Expand All @@ -231,8 +230,10 @@ func buildRuntime(runtime *model.Runtime, oldImageID string, oldEnv string, rebu
if err != nil {
runtime.Status = constant.RuntimeError
runtime.Message = buserr.New(constant.ErrImageBuildErr).Error() + ":" + stderrBuf.String()
if stderrBuf.String() == "" {
runtime.Message = buserr.New(constant.ErrImageBuildErr).Error() + ":" + err.Error()
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
runtime.Message = buserr.New(constant.ErrImageBuildErr).Error() + ":" + buserr.New("ErrCmdTimeout").Error()
} else {
runtime.Message = buserr.New(constant.ErrImageBuildErr).Error() + ":" + stderrBuf.String()
}
} else {
if err = runComposeCmdWithLog(constant.RuntimeDown, runtime.GetComposePath(), runtime.GetLogPath()); err != nil {
Expand Down Expand Up @@ -393,6 +394,14 @@ func handleParams(create request.RuntimeCreate, projectDir string) (composeConte
if err != nil {
return
}
case constant.RuntimeDotNet:
create.Params["CODE_DIR"] = create.CodeDir
create.Params["DOTNET_VERSION"] = create.Version
create.Params["PANEL_APP_PORT_HTTP"] = create.Port
composeContent, err = handleCompose(env, composeContent, create, projectDir)
if err != nil {
return
}
}

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

}
Expand Down
Loading