Skip to content

Commit b1adafe

Browse files
feat(appstore): Handle Website Directory During Second Installation of OpenResty (#7649)
1 parent dc02049 commit b1adafe

File tree

18 files changed

+60
-35
lines changed

18 files changed

+60
-35
lines changed

agent/app/api/v2/file.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,3 +804,13 @@ func (b *BaseApi) BatchChangeModeAndOwner(c *gin.Context) {
804804
}
805805
helper.SuccessWithOutData(c)
806806
}
807+
808+
func (b *BaseApi) GetPathByType(c *gin.Context) {
809+
pathType, ok := c.Params.Get("type")
810+
if !ok {
811+
helper.BadRequest(c, errors.New("error pathType id in path"))
812+
return
813+
}
814+
resPath := fileService.GetPathByType(pathType)
815+
helper.SuccessWithData(c, resPath)
816+
}

agent/app/model/app_install.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,6 @@ func (i *AppInstall) GetPath() string {
3131
return path.Join(i.GetAppPath(), i.Name)
3232
}
3333

34-
//func (i *AppInstall) GetSiteDir() string {
35-
// var data map[string]interface{}
36-
// err := json.Unmarshal([]byte(i.Env), &data)
37-
// if err != nil {
38-
// return path.Join(i.GetAppPath(), i.Name, "www")
39-
// }
40-
// websiteDir, ok := data["WEBSITE_DIR"].(string)
41-
// if !ok || websiteDir == "" {
42-
// return path.Join(i.GetAppPath(), i.Name, "www")
43-
// }
44-
// return websiteDir
45-
//}
46-
4734
func (i *AppInstall) GetComposePath() string {
4835
return path.Join(i.GetAppPath(), i.Name, "docker-compose.yml")
4936
}

agent/app/service/app.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,11 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App
359359
siteDir = path.Join(constant.DataDir, dir.(string))
360360
}
361361
req.Params["WEBSITE_DIR"] = siteDir
362-
_ = settingRepo.Create("WEBSITE_DIR", siteDir)
362+
oldWebStePath, _ := settingRepo.GetValueByKey("WEBSITE_DIR")
363+
if oldWebStePath != "" && oldWebStePath != siteDir {
364+
_ = files.NewFileOp().Rename(oldWebStePath, siteDir)
365+
}
366+
_ = settingRepo.UpdateOrCreate("WEBSITE_DIR", siteDir)
363367
}
364368
}
365369
for key := range req.Params {

agent/app/service/app_utils.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ func deleteAppInstall(deleteReq request.AppInstallDelete) error {
384384
return err
385385
}
386386

387-
if deleteReq.DeleteDB {
387+
resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithAppInstallId(install.ID))
388+
if deleteReq.DeleteDB && len(resources) > 0 {
388389
del := dto.DelAppLink{
389390
Ctx: ctx,
390391
Install: &install,
@@ -1062,8 +1063,9 @@ func upApp(task *task.Task, appInstall *model.AppInstall, pullImages bool) error
10621063
}
10631064
}
10641065
appInstall.Message = errMsg + out
1065-
task.LogFailedWithErr(i18n.GetMsgByKey("PullImage"), err)
1066-
return err
1066+
installErr := errors.New(appInstall.Message)
1067+
task.LogFailedWithErr(i18n.GetMsgByKey("PullImage"), installErr)
1068+
return installErr
10671069
} else {
10681070
task.Log(i18n.GetMsgByKey("PullImageSuccess"))
10691071
}
@@ -1316,7 +1318,7 @@ func handleErr(install model.AppInstall, err error, out string) error {
13161318

13171319
func doNotNeedSync(installed model.AppInstall) bool {
13181320
return installed.Status == constant.Installing || installed.Status == constant.Rebuilding || installed.Status == constant.Upgrading ||
1319-
installed.Status == constant.Syncing || installed.Status == constant.Uninstalling
1321+
installed.Status == constant.Syncing || installed.Status == constant.Uninstalling || installed.Status == constant.InstallErr
13201322
}
13211323

13221324
func synAppInstall(containers map[string]types.Container, appInstall *model.AppInstall, force bool) {

agent/app/service/file.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type IFileService interface {
5151
ChangeMode(op request.FileCreate) error
5252
BatchChangeModeAndOwner(op request.FileRoleReq) error
5353
ReadLogByLine(req request.FileReadByLineReq) (*response.FileLineContent, error)
54+
55+
GetPathByType(pathType string) string
5456
}
5557

5658
var filteredPaths = []string{
@@ -483,3 +485,14 @@ func (f *FileService) ReadLogByLine(req request.FileReadByLineReq) (*response.Fi
483485
}
484486
return res, nil
485487
}
488+
489+
func (f *FileService) GetPathByType(pathType string) string {
490+
if pathType == "websiteDir" {
491+
value, _ := settingRepo.GetValueByKey("WEBSITE_DIR")
492+
if value == "" {
493+
return path.Join(global.CONF.System.BaseDir, "www")
494+
}
495+
return value
496+
}
497+
return ""
498+
}

agent/app/service/website_utils.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,6 @@ func createIndexFile(website *model.Website, runtime *model.Runtime) error {
9191
}
9292

9393
func createProxyFile(website *model.Website) error {
94-
//nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
95-
//if err != nil {
96-
// return err
97-
//}
98-
//
99-
//proxyFolder := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "www", "sites", website.Alias, "proxy")
10094
proxyFolder := GetSitePath(*website, SiteProxyDir)
10195
filePath := path.Join(proxyFolder, "root.conf")
10296
fileOp := files.NewFileOp()
@@ -282,10 +276,6 @@ func createWafConfig(website *model.Website, domains []model.WebsiteDomain) erro
282276
if err != nil {
283277
return err
284278
}
285-
286-
if !common.CompareVersion(nginxInstall.Version, "1.21.4.3-2-0") {
287-
return nil
288-
}
289279
wafDataPath := path.Join(nginxInstall.GetPath(), "1pwaf", "data")
290280
fileOp := files.NewFileOp()
291281
if !fileOp.Stat(wafDataPath) {

agent/i18n/lang/en.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ErrDockerComposeNotValid: "docker-compose file format error!"
3030
ErrUpdateBuWebsite: "The application was updated successfully, but the modification of the website configuration file failed, please check the configuration!"
3131
Err1PanelNetworkFailed: "Default container network creation failed! {{ .detail }}"
3232
ErrFileParse: "Application docker-compose file parsing failed!"
33-
ErrInstallDirNotFound: "installation directory does not exist"
33+
ErrInstallDirNotFound: "The installation directory does not exist. To uninstall it, please choose to force uninstall."
3434
AppStoreIsUpToDate: "The app store is already up to date!"
3535
LocalAppVersionNull: "The {{.name}} app is not synced to version! Could not add to application list"
3636
LocalAppVersionErr: "{{.name}} failed to sync version {{.version}}! {{.err}}"

agent/i18n/lang/zh-Hant.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ErrDockerComposeNotValid: "docker-compose 文件格式錯誤"
3131
ErrUpdateBuWebsite: "應用更新成功,但是網站配置文件修改失敗,請檢查配置!"
3232
Err1PanelNetworkFailed: "默認容器網絡創建失敗!{{ .detail }}"
3333
ErrFileParse: "應用 docker-compose 文件解析失敗!"
34-
ErrInstallDirNotFound: "安裝目錄不存在"
34+
ErrInstallDirNotFound: "安裝目錄不存在,如需卸載,請選擇強制卸載"
3535
AppStoreIsUpToDate: "應用商店已經是最新版本"
3636
LocalAppVersionNull: "{{.name}} 應用未同步到版本!無法添加到應用列表"
3737
LocalAppVersionErr: "{{.name}} 同步版本 {{.version}} 失敗!{{.err}}"

agent/i18n/lang/zh.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ErrDockerComposeNotValid: "docker-compose 文件格式错误"
3030
ErrUpdateBuWebsite: "应用更新成功,但是网站配置文件修改失败,请检查配置!"
3131
Err1PanelNetworkFailed: "默认容器网络创建失败!{{ .detail }}"
3232
ErrFileParse: "应用 docker-compose 文件解析失败!"
33-
ErrInstallDirNotFound: "安装目录不存在"
33+
ErrInstallDirNotFound: "安装目录不存在,如需卸载,请选择强制卸载"
3434
AppStoreIsUpToDate: "应用商店已经是最新版本"
3535
LocalAppVersionNull: "{{.name}} 应用未同步到版本!无法添加到应用列表"
3636
LocalAppVersionErr: "{{.name}} 同步版本 {{.version}} 失败!{{.err}}"

agent/router/ro_file.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ func (f *FileRouter) InitRouter(Router *gin.RouterGroup) {
4747
fileRouter.POST("/favorite", baseApi.CreateFavorite)
4848
fileRouter.POST("/favorite/del", baseApi.DeleteFavorite)
4949

50+
fileRouter.GET("/path/:type", baseApi.GetPathByType)
5051
}
5152
}

0 commit comments

Comments
 (0)