From ae4662cf262cd1bf278cf36f38ac71f87d555976 Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Mon, 21 Nov 2022 11:27:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20docker=20network?= =?UTF-8?q?=20=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/model/website.go | 1 + backend/app/service/app_utils.go | 5 +- backend/app/service/website.go | 4 ++ backend/constant/website.go | 5 ++ backend/init/app/app.go | 47 +++++++++++++++++++ backend/init/viper/viper.go | 27 ----------- backend/server/server.go | 2 + frontend/src/lang/modules/zh.ts | 5 +- .../config/basic/default-doc/index.vue | 2 +- .../website/config/basic/https/index.vue | 2 +- .../website/config/basic/limit-conn/index.vue | 2 +- .../views/website/website/create/index.vue | 12 ++--- 12 files changed, 72 insertions(+), 42 deletions(-) create mode 100644 backend/init/app/app.go diff --git a/backend/app/model/website.go b/backend/app/model/website.go index 927c6ea42..3a026e72f 100644 --- a/backend/app/model/website.go +++ b/backend/app/model/website.go @@ -4,6 +4,7 @@ import "time" type WebSite struct { BaseModel + Protocol string `gorm:"type:varchar(64);not null" json:"protocol"` PrimaryDomain string `gorm:"type:varchar(128);not null" json:"primaryDomain"` Type string `gorm:"type:varchar(64);not null" json:"type"` Alias string `gorm:"type:varchar(128);not null" json:"alias"` diff --git a/backend/app/service/app_utils.go b/backend/app/service/app_utils.go index 355cae065..46f678a0a 100644 --- a/backend/app/service/app_utils.go +++ b/backend/app/service/app_utils.go @@ -264,10 +264,7 @@ func backupInstall(ctx context.Context, install model.AppInstall) error { backup.AppDetailId = install.AppDetailId backup.Param = install.Param - if err := appInstallBackupRepo.Create(ctx, backup); err != nil { - return err - } - return nil + return appInstallBackupRepo.Create(ctx, backup) } func restoreInstall(install model.AppInstall, backupId uint) error { diff --git a/backend/app/service/website.go b/backend/app/service/website.go index 435c771d7..910ebc491 100644 --- a/backend/app/service/website.go +++ b/backend/app/service/website.go @@ -44,6 +44,7 @@ func (w WebsiteService) CreateWebsite(create dto.WebSiteCreate) error { ExpireDate: defaultDate, AppInstallID: create.AppInstallID, WebSiteGroupID: create.WebSiteGroupID, + Protocol: constant.ProtocolHTTP, } if create.AppType == dto.NewApp { @@ -313,9 +314,12 @@ func (w WebsiteService) OpWebsiteHTTPS(req dto.WebsiteHTTPSOp) (dto.WebsiteHTTPS } if req.Enable { + website.Protocol = constant.ProtocolHTTPS if err := applySSL(website, ssl); err != nil { return dto.WebsiteHTTPS{}, err } + } else { + website.Protocol = constant.ProtocolHTTP } return res, nil diff --git a/backend/constant/website.go b/backend/constant/website.go index 020beb20d..af04115fe 100644 --- a/backend/constant/website.go +++ b/backend/constant/website.go @@ -9,3 +9,8 @@ const ( DateLayout = "2006-01-02" DefaultDate = "1970-01-01" ) + +const ( + ProtocolHTTP = "HTTP" + ProtocolHTTPS = "HTTPS" +) diff --git a/backend/init/app/app.go b/backend/init/app/app.go new file mode 100644 index 000000000..cfdeec192 --- /dev/null +++ b/backend/init/app/app.go @@ -0,0 +1,47 @@ +package app + +import ( + "fmt" + "github.com/1Panel-dev/1Panel/backend/constant" + "github.com/1Panel-dev/1Panel/backend/utils/docker" + "github.com/1Panel-dev/1Panel/backend/utils/files" + "path" +) + +func Init() { + constant.DefaultDataDir = "/opt/1Panel/data" + constant.ResourceDir = path.Join(constant.DefaultDataDir, "resource") + constant.AppResourceDir = path.Join(constant.ResourceDir, "apps") + constant.AppInstallDir = path.Join(constant.DefaultDataDir, "apps") + constant.BackupDir = path.Join(constant.DefaultDataDir, "backup") + constant.AppBackupDir = path.Join(constant.BackupDir, "apps") + + dirs := []string{constant.DefaultDataDir, constant.ResourceDir, constant.AppResourceDir, constant.AppInstallDir, constant.BackupDir, constant.AppBackupDir} + + fileOp := files.NewFileOp() + for _, dir := range dirs { + createDir(fileOp, dir) + } + + createDefaultDockerNetwork() +} + +func createDir(fileOp files.FileOp, dirPath string) { + if !fileOp.Stat(dirPath) { + _ = fileOp.CreateDir(dirPath, 0755) + } +} + +func createDefaultDockerNetwork() { + cli, err := docker.NewClient() + if err != nil { + fmt.Println("init docker client error", err.Error()) + return + } + if !cli.NetworkExist("1panel") { + if err := cli.CreateNetwork("1panel"); err != nil { + fmt.Println("init docker client error", err.Error()) + return + } + } +} diff --git a/backend/init/viper/viper.go b/backend/init/viper/viper.go index 2cd11f0be..e362b676a 100644 --- a/backend/init/viper/viper.go +++ b/backend/init/viper/viper.go @@ -3,11 +3,7 @@ package viper import ( "fmt" "github.com/1Panel-dev/1Panel/backend/configs" - "github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/global" - "github.com/1Panel-dev/1Panel/backend/utils/files" - "path" - "github.com/fsnotify/fsnotify" "github.com/spf13/viper" ) @@ -32,27 +28,4 @@ func Init() { panic(err) } global.CONF = serverConfig - InitDir() -} - -func InitDir() { - constant.DefaultDataDir = "/opt/1Panel/data" - constant.ResourceDir = path.Join(constant.DefaultDataDir, "resource") - constant.AppResourceDir = path.Join(constant.ResourceDir, "apps") - constant.AppInstallDir = path.Join(constant.DefaultDataDir, "apps") - constant.BackupDir = path.Join(constant.DefaultDataDir, "backup") - constant.AppBackupDir = path.Join(constant.BackupDir, "apps") - - dirs := []string{constant.DefaultDataDir, constant.ResourceDir, constant.AppResourceDir, constant.AppInstallDir, constant.BackupDir, constant.AppBackupDir} - - fileOp := files.NewFileOp() - for _, dir := range dirs { - createDir(fileOp, dir) - } -} - -func createDir(fileOp files.FileOp, dirPath string) { - if !fileOp.Stat(dirPath) { - _ = fileOp.CreateDir(dirPath, 0755) - } } diff --git a/backend/server/server.go b/backend/server/server.go index f559ebabf..70d664a58 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -3,6 +3,7 @@ package server import ( "encoding/gob" "fmt" + "github.com/1Panel-dev/1Panel/backend/init/app" "time" "github.com/1Panel-dev/1Panel/backend/cron" @@ -23,6 +24,7 @@ import ( ) func Start() { + app.Init() viper.Init() log.Init() db.Init() diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 489b375ba..6edac7f34 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -672,14 +672,14 @@ export default { delete: '删除', deleteWarn: '删除操作会把数据一并删除,此操作不可回滚,是否继续?', syncSuccess: '同步成功', - canUpdate: '可更新', + canUpdate: '可升级', backup: '备份', backupName: '文件名称', backupPath: '文件路径', backupdate: '备份时间', restore: '回滚', restoreWarn: '回滚操作会重启应用,并替换数据,此操作不可回滚,是否继续?', - update: '更新', + update: '升级', versioneSelect: '请选择版本', }, website: { @@ -740,5 +740,6 @@ export default { renewSuccess: '续签证书', config: '配置', enableHTTPS: '启用HTTPS', + aliasHelper: '代号是网站目录的文件夹名称', }, }; diff --git a/frontend/src/views/website/website/config/basic/default-doc/index.vue b/frontend/src/views/website/website/config/basic/default-doc/index.vue index cf988ef4c..1dc2befd6 100644 --- a/frontend/src/views/website/website/config/basic/default-doc/index.vue +++ b/frontend/src/views/website/website/config/basic/default-doc/index.vue @@ -73,7 +73,7 @@ const search = (req: WebSite.NginxConfigReq) => { loading.value = true; GetNginxConfig(req) .then((res) => { - if (res.data.length > 0) { + if (res.data && res.data.length > 0) { const indexParam = res.data[0]; let values = ''; for (const param of indexParam.params) { diff --git a/frontend/src/views/website/website/config/basic/https/index.vue b/frontend/src/views/website/website/config/basic/https/index.vue index 93f40099e..f4173f444 100644 --- a/frontend/src/views/website/website/config/basic/https/index.vue +++ b/frontend/src/views/website/website/config/basic/https/index.vue @@ -108,7 +108,7 @@ const get = () => { if (res.data) { form.enable = res.data.enable; } - if (res.data?.SSL) { + if (res.data?.SSL && res.data?.SSL.id > 0) { form.websiteSSLId = res.data.SSL.id; websiteSSL.value = res.data.SSL; } diff --git a/frontend/src/views/website/website/config/basic/limit-conn/index.vue b/frontend/src/views/website/website/config/basic/limit-conn/index.vue index 9ef9f0640..1f42a1781 100644 --- a/frontend/src/views/website/website/config/basic/limit-conn/index.vue +++ b/frontend/src/views/website/website/config/basic/limit-conn/index.vue @@ -64,7 +64,7 @@ const search = (req: WebSite.NginxConfigReq) => { loading.value = true; GetNginxConfig(req) .then((res) => { - if (res.data.length > 0) { + if (res.data && res.data.length > 0) { enable.value = true; for (const param of res.data) { if (param.name === 'limit_conn') { diff --git a/frontend/src/views/website/website/create/index.vue b/frontend/src/views/website/website/create/index.vue index a886c9abe..41764746f 100644 --- a/frontend/src/views/website/website/create/index.vue +++ b/frontend/src/views/website/website/create/index.vue @@ -8,7 +8,7 @@ - + - + - + @@ -129,8 +129,8 @@ const website = ref({ alias: '', remark: '', appType: 'installed', - appInstallID: 0, - webSiteGroupID: 1, + appInstallId: 0, + webSiteGroupId: 1, otherDomains: '', appinstall: { appID: 0, @@ -180,7 +180,7 @@ const searchAppInstalled = () => { SearchAppInstalled({ type: 'website' }).then((res) => { appInstalles.value = res.data; if (res.data.length > 0) { - website.value.appInstallID = res.data[0].id; + website.value.appInstallId = res.data[0].id; } }); };