From b1adafec2ddd16b5462683318cdb5e13cbcddffb Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Mon, 6 Jan 2025 17:09:48 +0800 Subject: [PATCH] feat(appstore): Handle Website Directory During Second Installation of OpenResty (#7649) --- agent/app/api/v2/file.go | 10 ++++++++++ agent/app/model/app_install.go | 13 ------------- agent/app/service/app.go | 6 +++++- agent/app/service/app_utils.go | 10 ++++++---- agent/app/service/file.go | 13 +++++++++++++ agent/app/service/website_utils.go | 10 ---------- agent/i18n/lang/en.yaml | 2 +- agent/i18n/lang/zh-Hant.yaml | 2 +- agent/i18n/lang/zh.yaml | 2 +- agent/router/ro_file.go | 1 + frontend/src/api/modules/files.ts | 4 ++++ frontend/src/components/task-list/index.vue | 2 +- frontend/src/components/task-log/index.vue | 1 - frontend/src/lang/modules/en.ts | 4 ++++ frontend/src/lang/modules/tw.ts | 3 +++ frontend/src/lang/modules/zh.ts | 2 ++ .../src/views/app-store/detail/params/index.vue | 6 ++++++ .../src/views/app-store/installed/delete/index.vue | 4 ++-- 18 files changed, 60 insertions(+), 35 deletions(-) diff --git a/agent/app/api/v2/file.go b/agent/app/api/v2/file.go index 90ccbded7..c148ee0a9 100644 --- a/agent/app/api/v2/file.go +++ b/agent/app/api/v2/file.go @@ -804,3 +804,13 @@ func (b *BaseApi) BatchChangeModeAndOwner(c *gin.Context) { } helper.SuccessWithOutData(c) } + +func (b *BaseApi) GetPathByType(c *gin.Context) { + pathType, ok := c.Params.Get("type") + if !ok { + helper.BadRequest(c, errors.New("error pathType id in path")) + return + } + resPath := fileService.GetPathByType(pathType) + helper.SuccessWithData(c, resPath) +} diff --git a/agent/app/model/app_install.go b/agent/app/model/app_install.go index 846e06885..d753003b0 100644 --- a/agent/app/model/app_install.go +++ b/agent/app/model/app_install.go @@ -31,19 +31,6 @@ func (i *AppInstall) GetPath() string { return path.Join(i.GetAppPath(), i.Name) } -//func (i *AppInstall) GetSiteDir() string { -// var data map[string]interface{} -// err := json.Unmarshal([]byte(i.Env), &data) -// if err != nil { -// return path.Join(i.GetAppPath(), i.Name, "www") -// } -// websiteDir, ok := data["WEBSITE_DIR"].(string) -// if !ok || websiteDir == "" { -// return path.Join(i.GetAppPath(), i.Name, "www") -// } -// return websiteDir -//} - func (i *AppInstall) GetComposePath() string { return path.Join(i.GetAppPath(), i.Name, "docker-compose.yml") } diff --git a/agent/app/service/app.go b/agent/app/service/app.go index fad0f6c94..6863c6cb4 100644 --- a/agent/app/service/app.go +++ b/agent/app/service/app.go @@ -359,7 +359,11 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App siteDir = path.Join(constant.DataDir, dir.(string)) } req.Params["WEBSITE_DIR"] = siteDir - _ = settingRepo.Create("WEBSITE_DIR", siteDir) + oldWebStePath, _ := settingRepo.GetValueByKey("WEBSITE_DIR") + if oldWebStePath != "" && oldWebStePath != siteDir { + _ = files.NewFileOp().Rename(oldWebStePath, siteDir) + } + _ = settingRepo.UpdateOrCreate("WEBSITE_DIR", siteDir) } } for key := range req.Params { diff --git a/agent/app/service/app_utils.go b/agent/app/service/app_utils.go index efed7c8d4..8d5fdac90 100644 --- a/agent/app/service/app_utils.go +++ b/agent/app/service/app_utils.go @@ -384,7 +384,8 @@ func deleteAppInstall(deleteReq request.AppInstallDelete) error { return err } - if deleteReq.DeleteDB { + resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithAppInstallId(install.ID)) + if deleteReq.DeleteDB && len(resources) > 0 { del := dto.DelAppLink{ Ctx: ctx, Install: &install, @@ -1062,8 +1063,9 @@ func upApp(task *task.Task, appInstall *model.AppInstall, pullImages bool) error } } appInstall.Message = errMsg + out - task.LogFailedWithErr(i18n.GetMsgByKey("PullImage"), err) - return err + installErr := errors.New(appInstall.Message) + task.LogFailedWithErr(i18n.GetMsgByKey("PullImage"), installErr) + return installErr } else { task.Log(i18n.GetMsgByKey("PullImageSuccess")) } @@ -1316,7 +1318,7 @@ func handleErr(install model.AppInstall, err error, out string) error { func doNotNeedSync(installed model.AppInstall) bool { return installed.Status == constant.Installing || installed.Status == constant.Rebuilding || installed.Status == constant.Upgrading || - installed.Status == constant.Syncing || installed.Status == constant.Uninstalling + installed.Status == constant.Syncing || installed.Status == constant.Uninstalling || installed.Status == constant.InstallErr } func synAppInstall(containers map[string]types.Container, appInstall *model.AppInstall, force bool) { diff --git a/agent/app/service/file.go b/agent/app/service/file.go index 0c749aa8d..3e45347c8 100644 --- a/agent/app/service/file.go +++ b/agent/app/service/file.go @@ -51,6 +51,8 @@ type IFileService interface { ChangeMode(op request.FileCreate) error BatchChangeModeAndOwner(op request.FileRoleReq) error ReadLogByLine(req request.FileReadByLineReq) (*response.FileLineContent, error) + + GetPathByType(pathType string) string } var filteredPaths = []string{ @@ -483,3 +485,14 @@ func (f *FileService) ReadLogByLine(req request.FileReadByLineReq) (*response.Fi } return res, nil } + +func (f *FileService) GetPathByType(pathType string) string { + if pathType == "websiteDir" { + value, _ := settingRepo.GetValueByKey("WEBSITE_DIR") + if value == "" { + return path.Join(global.CONF.System.BaseDir, "www") + } + return value + } + return "" +} diff --git a/agent/app/service/website_utils.go b/agent/app/service/website_utils.go index 739595eda..527f94b6c 100644 --- a/agent/app/service/website_utils.go +++ b/agent/app/service/website_utils.go @@ -91,12 +91,6 @@ func createIndexFile(website *model.Website, runtime *model.Runtime) error { } func createProxyFile(website *model.Website) error { - //nginxInstall, err := getAppInstallByKey(constant.AppOpenresty) - //if err != nil { - // return err - //} - // - //proxyFolder := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "www", "sites", website.Alias, "proxy") proxyFolder := GetSitePath(*website, SiteProxyDir) filePath := path.Join(proxyFolder, "root.conf") fileOp := files.NewFileOp() @@ -282,10 +276,6 @@ func createWafConfig(website *model.Website, domains []model.WebsiteDomain) erro if err != nil { return err } - - if !common.CompareVersion(nginxInstall.Version, "1.21.4.3-2-0") { - return nil - } wafDataPath := path.Join(nginxInstall.GetPath(), "1pwaf", "data") fileOp := files.NewFileOp() if !fileOp.Stat(wafDataPath) { diff --git a/agent/i18n/lang/en.yaml b/agent/i18n/lang/en.yaml index c71fbad5b..acf63c7e1 100644 --- a/agent/i18n/lang/en.yaml +++ b/agent/i18n/lang/en.yaml @@ -30,7 +30,7 @@ ErrDockerComposeNotValid: "docker-compose file format error!" ErrUpdateBuWebsite: "The application was updated successfully, but the modification of the website configuration file failed, please check the configuration!" Err1PanelNetworkFailed: "Default container network creation failed! {{ .detail }}" ErrFileParse: "Application docker-compose file parsing failed!" -ErrInstallDirNotFound: "installation directory does not exist" +ErrInstallDirNotFound: "The installation directory does not exist. To uninstall it, please choose to force uninstall." AppStoreIsUpToDate: "The app store is already up to date!" LocalAppVersionNull: "The {{.name}} app is not synced to version! Could not add to application list" LocalAppVersionErr: "{{.name}} failed to sync version {{.version}}! {{.err}}" diff --git a/agent/i18n/lang/zh-Hant.yaml b/agent/i18n/lang/zh-Hant.yaml index be55844a8..4c352cd97 100644 --- a/agent/i18n/lang/zh-Hant.yaml +++ b/agent/i18n/lang/zh-Hant.yaml @@ -31,7 +31,7 @@ ErrDockerComposeNotValid: "docker-compose 文件格式錯誤" ErrUpdateBuWebsite: "應用更新成功,但是網站配置文件修改失敗,請檢查配置!" Err1PanelNetworkFailed: "默認容器網絡創建失敗!{{ .detail }}" ErrFileParse: "應用 docker-compose 文件解析失敗!" -ErrInstallDirNotFound: "安裝目錄不存在" +ErrInstallDirNotFound: "安裝目錄不存在,如需卸載,請選擇強制卸載" AppStoreIsUpToDate: "應用商店已經是最新版本" LocalAppVersionNull: "{{.name}} 應用未同步到版本!無法添加到應用列表" LocalAppVersionErr: "{{.name}} 同步版本 {{.version}} 失敗!{{.err}}" diff --git a/agent/i18n/lang/zh.yaml b/agent/i18n/lang/zh.yaml index 98f9202ec..afd85ae2d 100644 --- a/agent/i18n/lang/zh.yaml +++ b/agent/i18n/lang/zh.yaml @@ -30,7 +30,7 @@ ErrDockerComposeNotValid: "docker-compose 文件格式错误" ErrUpdateBuWebsite: "应用更新成功,但是网站配置文件修改失败,请检查配置!" Err1PanelNetworkFailed: "默认容器网络创建失败!{{ .detail }}" ErrFileParse: "应用 docker-compose 文件解析失败!" -ErrInstallDirNotFound: "安装目录不存在" +ErrInstallDirNotFound: "安装目录不存在,如需卸载,请选择强制卸载" AppStoreIsUpToDate: "应用商店已经是最新版本" LocalAppVersionNull: "{{.name}} 应用未同步到版本!无法添加到应用列表" LocalAppVersionErr: "{{.name}} 同步版本 {{.version}} 失败!{{.err}}" diff --git a/agent/router/ro_file.go b/agent/router/ro_file.go index df432711b..2f5794703 100644 --- a/agent/router/ro_file.go +++ b/agent/router/ro_file.go @@ -47,5 +47,6 @@ func (f *FileRouter) InitRouter(Router *gin.RouterGroup) { fileRouter.POST("/favorite", baseApi.CreateFavorite) fileRouter.POST("/favorite/del", baseApi.DeleteFavorite) + fileRouter.GET("/path/:type", baseApi.GetPathByType) } } diff --git a/frontend/src/api/modules/files.ts b/frontend/src/api/modules/files.ts index 2f88d4af2..4b958bd0b 100644 --- a/frontend/src/api/modules/files.ts +++ b/frontend/src/api/modules/files.ts @@ -124,3 +124,7 @@ export const BatchChangeRole = (params: File.FileRole) => { export const GetRecycleStatus = () => { return http.get('files/recycle/status'); }; + +export const GetPathByType = (pathType: string) => { + return http.get(`files/path/${pathType}`); +}; diff --git a/frontend/src/components/task-list/index.vue b/frontend/src/components/task-list/index.vue index c2162a840..2b0f55cb3 100644 --- a/frontend/src/components/task-list/index.vue +++ b/frontend/src/components/task-list/index.vue @@ -87,7 +87,7 @@ const search = async () => { }; const openTaskLog = (row: Log.Task) => { - taskLogRef.value.openWithTaskID(row.id, !(row.status == 'Executing')); + taskLogRef.value.openWithTaskID(row.id, row.status == 'Executing'); }; const acceptParams = () => { diff --git a/frontend/src/components/task-log/index.vue b/frontend/src/components/task-log/index.vue index b25ad8c93..5d331e609 100644 --- a/frontend/src/components/task-log/index.vue +++ b/frontend/src/components/task-log/index.vue @@ -43,7 +43,6 @@ const open = ref(false); const showTail = ref(true); const openWithTaskID = (id: string, tail: boolean) => { - console.log('openWithTaskID', id, tail); config.taskID = id; if (tail === undefined) { config.tail = true; diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 151938b02..58b9cc17f 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -302,6 +302,7 @@ const message = { sending: 'Sending', healthy: 'Normal', executing: 'Executing', + installerr: 'Install Error', }, units: { second: 'Second', @@ -2007,6 +2008,9 @@ const message = { 'The default access is used for application port forwarding. For example, if the application port is 8080, the forwarding address would be http(s)://default-access-address:8080', 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', + forceUninstall: 'Force Uninstall', }, website: { website: 'Website', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 79e4a3103..2fc8ea6ee 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -297,6 +297,7 @@ const message = { sending: '下發中', healthy: '正常', executing: '執行中', + installerr: '安裝失敗', }, units: { second: '秒', @@ -1863,6 +1864,8 @@ const message = { '默認訪問用於應用端口跳轉,例如應用端口為 8080 則跳轉地址為 http(s)://默認訪問地址:8080', webUIConfig: '請在應用參數或者應用商店設置處添加訪問地址', toLink: '連結', + customAppHelper: '當前使用的是主節點應用商店包,修改配置請在主節點操作', + forceUninstall: '強制卸載', }, website: { website: '網站', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 33e56f007..53d83ae09 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -297,6 +297,7 @@ const message = { sending: '下发中', healthy: '正常', executing: '执行中', + installerr: '安装失败', }, units: { second: '秒', @@ -1862,6 +1863,7 @@ const message = { webUIConfig: '请在应用参数或者应用商店设置处添加访问地址', toLink: '跳转', customAppHelper: '当前使用的是主节点应用商店包,修改配置请在主节点操作', + forceUninstall: '强制卸载', }, website: { website: '网站', diff --git a/frontend/src/views/app-store/detail/params/index.vue b/frontend/src/views/app-store/detail/params/index.vue index 609daae6c..ae5169611 100644 --- a/frontend/src/views/app-store/detail/params/index.vue +++ b/frontend/src/views/app-store/detail/params/index.vue @@ -114,6 +114,7 @@ import { GetAppService } from '@/api/modules/app'; import { Rules } from '@/global/form-rules'; import { App } from '@/api/interface/app'; import { getDBName } from '@/utils/util'; +import { GetPathByType } from '@/api/modules/files'; interface ParamObj extends App.FromField { services: App.AppService[]; @@ -186,6 +187,11 @@ const handleParams = () => { } else { form[p.envKey] = p.default; } + if (p.type == 'text' && p.envKey == 'WEBSITE_DIR') { + GetPathByType('websiteDir').then((res) => { + form[p.envKey] = res.data; + }); + } if (p.required) { if (p.type === 'service' || p.type === 'apps') { rules[p.envKey] = [Rules.requiredSelect]; diff --git a/frontend/src/views/app-store/installed/delete/index.vue b/frontend/src/views/app-store/installed/delete/index.vue index 1e98be4c4..211b6524d 100644 --- a/frontend/src/views/app-store/installed/delete/index.vue +++ b/frontend/src/views/app-store/installed/delete/index.vue @@ -1,8 +1,8 @@