Skip to content

Commit

Permalink
feat(appstore): Handle Website Directory During Second Installation o…
Browse files Browse the repository at this point in the history
…f OpenResty (#7649)
  • Loading branch information
zhengkunwang223 authored Jan 6, 2025
1 parent dc02049 commit b1adafe
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 35 deletions.
10 changes: 10 additions & 0 deletions agent/app/api/v2/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
13 changes: 0 additions & 13 deletions agent/app/model/app_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
6 changes: 5 additions & 1 deletion agent/app/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions agent/app/service/app_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"))
}
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions agent/app/service/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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 ""
}
10 changes: 0 additions & 10 deletions agent/app/service/website_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion agent/i18n/lang/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
Expand Down
2 changes: 1 addition & 1 deletion agent/i18n/lang/zh-Hant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ErrDockerComposeNotValid: "docker-compose 文件格式錯誤"
ErrUpdateBuWebsite: "應用更新成功,但是網站配置文件修改失敗,請檢查配置!"
Err1PanelNetworkFailed: "默認容器網絡創建失敗!{{ .detail }}"
ErrFileParse: "應用 docker-compose 文件解析失敗!"
ErrInstallDirNotFound: "安裝目錄不存在"
ErrInstallDirNotFound: "安裝目錄不存在,如需卸載,請選擇強制卸載"
AppStoreIsUpToDate: "應用商店已經是最新版本"
LocalAppVersionNull: "{{.name}} 應用未同步到版本!無法添加到應用列表"
LocalAppVersionErr: "{{.name}} 同步版本 {{.version}} 失敗!{{.err}}"
Expand Down
2 changes: 1 addition & 1 deletion agent/i18n/lang/zh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ErrDockerComposeNotValid: "docker-compose 文件格式错误"
ErrUpdateBuWebsite: "应用更新成功,但是网站配置文件修改失败,请检查配置!"
Err1PanelNetworkFailed: "默认容器网络创建失败!{{ .detail }}"
ErrFileParse: "应用 docker-compose 文件解析失败!"
ErrInstallDirNotFound: "安装目录不存在"
ErrInstallDirNotFound: "安装目录不存在,如需卸载,请选择强制卸载"
AppStoreIsUpToDate: "应用商店已经是最新版本"
LocalAppVersionNull: "{{.name}} 应用未同步到版本!无法添加到应用列表"
LocalAppVersionErr: "{{.name}} 同步版本 {{.version}} 失败!{{.err}}"
Expand Down
1 change: 1 addition & 0 deletions agent/router/ro_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
4 changes: 4 additions & 0 deletions frontend/src/api/modules/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,7 @@ export const BatchChangeRole = (params: File.FileRole) => {
export const GetRecycleStatus = () => {
return http.get<string>('files/recycle/status');
};

export const GetPathByType = (pathType: string) => {
return http.get<string>(`files/path/${pathType}`);
};
2 changes: 1 addition & 1 deletion frontend/src/components/task-list/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/task-log/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ const message = {
sending: 'Sending',
healthy: 'Normal',
executing: 'Executing',
installerr: 'Install Error',
},
units: {
second: 'Second',
Expand Down Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lang/modules/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ const message = {
sending: '下發中',
healthy: '正',
executing: '執行中',
installerr: '安裝失敗',
},
units: {
second: '秒',
Expand Down Expand Up @@ -1863,6 +1864,8 @@ const message = {
'默認訪問用於應用端口跳轉例如應用端口為 8080 則跳轉地址為 http(s)://默認訪問地址:8080',
webUIConfig: '請在應用參數或者應用商店設置處添加訪問地址',
toLink: '連',
customAppHelper: '當前使用的是主節點應用商店包修改配置請在主節點操作',
forceUninstall: '強制卸載',
},
website: {
website: '網',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ const message = {
sending: '下发中',
healthy: '正',
executing: '执行中',
installerr: '安装失败',
},
units: {
second: '秒',
Expand Down Expand Up @@ -1862,6 +1863,7 @@ const message = {
webUIConfig: '请在应用参数或者应用商店设置处添加访问地址',
toLink: '跳',
customAppHelper: '当前使用的是主节点应用商店包修改配置请在主节点操作',
forceUninstall: '强制卸载',
},
website: {
website: '网',
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/views/app-store/detail/params/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/app-store/installed/delete/index.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<DialogPro v-model="open" :title="$t('commons.button.delete') + ' - ' + appInstallName" @close="handleClose">
<DialogPro v-model="open" :title="$t('commons.button.uninstall') + ' - ' + appInstallName" @close="handleClose">
<el-form ref="deleteForm" label-position="left" v-loading="loading">
<el-form-item>
<el-checkbox v-model="deleteReq.forceDelete" :label="$t('app.forceDelete')" />
<el-checkbox v-model="deleteReq.forceDelete" :label="$t('app.forceUninstall')" />
<span class="input-help">
{{ $t('app.forceDeleteHelper') }}
</span>
Expand Down

0 comments on commit b1adafe

Please sign in to comment.