1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-02-07 17:10:07 +08:00

feat(appstore): Handle Website Directory During Second Installation of OpenResty (#7649)

This commit is contained in:
zhengkunwang 2025-01-06 17:09:48 +08:00 committed by GitHub
parent dc020499b8
commit b1adafec2d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 60 additions and 35 deletions

View File

@ -804,3 +804,13 @@ func (b *BaseApi) BatchChangeModeAndOwner(c *gin.Context) {
} }
helper.SuccessWithOutData(c) 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)
}

View File

@ -31,19 +31,6 @@ func (i *AppInstall) GetPath() string {
return path.Join(i.GetAppPath(), i.Name) 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 { func (i *AppInstall) GetComposePath() string {
return path.Join(i.GetAppPath(), i.Name, "docker-compose.yml") return path.Join(i.GetAppPath(), i.Name, "docker-compose.yml")
} }

View File

@ -359,7 +359,11 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App
siteDir = path.Join(constant.DataDir, dir.(string)) siteDir = path.Join(constant.DataDir, dir.(string))
} }
req.Params["WEBSITE_DIR"] = siteDir 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 { for key := range req.Params {

View File

@ -384,7 +384,8 @@ func deleteAppInstall(deleteReq request.AppInstallDelete) error {
return err return err
} }
if deleteReq.DeleteDB { resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithAppInstallId(install.ID))
if deleteReq.DeleteDB && len(resources) > 0 {
del := dto.DelAppLink{ del := dto.DelAppLink{
Ctx: ctx, Ctx: ctx,
Install: &install, Install: &install,
@ -1062,8 +1063,9 @@ func upApp(task *task.Task, appInstall *model.AppInstall, pullImages bool) error
} }
} }
appInstall.Message = errMsg + out appInstall.Message = errMsg + out
task.LogFailedWithErr(i18n.GetMsgByKey("PullImage"), err) installErr := errors.New(appInstall.Message)
return err task.LogFailedWithErr(i18n.GetMsgByKey("PullImage"), installErr)
return installErr
} else { } else {
task.Log(i18n.GetMsgByKey("PullImageSuccess")) 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 { func doNotNeedSync(installed model.AppInstall) bool {
return installed.Status == constant.Installing || installed.Status == constant.Rebuilding || installed.Status == constant.Upgrading || 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) { func synAppInstall(containers map[string]types.Container, appInstall *model.AppInstall, force bool) {

View File

@ -51,6 +51,8 @@ type IFileService interface {
ChangeMode(op request.FileCreate) error ChangeMode(op request.FileCreate) error
BatchChangeModeAndOwner(op request.FileRoleReq) error BatchChangeModeAndOwner(op request.FileRoleReq) error
ReadLogByLine(req request.FileReadByLineReq) (*response.FileLineContent, error) ReadLogByLine(req request.FileReadByLineReq) (*response.FileLineContent, error)
GetPathByType(pathType string) string
} }
var filteredPaths = []string{ var filteredPaths = []string{
@ -483,3 +485,14 @@ func (f *FileService) ReadLogByLine(req request.FileReadByLineReq) (*response.Fi
} }
return res, nil 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 ""
}

View File

@ -91,12 +91,6 @@ func createIndexFile(website *model.Website, runtime *model.Runtime) error {
} }
func createProxyFile(website *model.Website) 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) proxyFolder := GetSitePath(*website, SiteProxyDir)
filePath := path.Join(proxyFolder, "root.conf") filePath := path.Join(proxyFolder, "root.conf")
fileOp := files.NewFileOp() fileOp := files.NewFileOp()
@ -282,10 +276,6 @@ func createWafConfig(website *model.Website, domains []model.WebsiteDomain) erro
if err != nil { if err != nil {
return err return err
} }
if !common.CompareVersion(nginxInstall.Version, "1.21.4.3-2-0") {
return nil
}
wafDataPath := path.Join(nginxInstall.GetPath(), "1pwaf", "data") wafDataPath := path.Join(nginxInstall.GetPath(), "1pwaf", "data")
fileOp := files.NewFileOp() fileOp := files.NewFileOp()
if !fileOp.Stat(wafDataPath) { if !fileOp.Stat(wafDataPath) {

View File

@ -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!" 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 }}" Err1PanelNetworkFailed: "Default container network creation failed! {{ .detail }}"
ErrFileParse: "Application docker-compose file parsing failed!" 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" AppStoreIsUpToDate: "The app store is already up to date"
LocalAppVersionNull: "The {{.name}} app is not synced to version! Could not add to application list" LocalAppVersionNull: "The {{.name}} app is not synced to version! Could not add to application list"
LocalAppVersionErr: "{{.name}} failed to sync version {{.version}}! {{.err}}" LocalAppVersionErr: "{{.name}} failed to sync version {{.version}}! {{.err}}"

View File

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

View File

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

View File

@ -47,5 +47,6 @@ func (f *FileRouter) InitRouter(Router *gin.RouterGroup) {
fileRouter.POST("/favorite", baseApi.CreateFavorite) fileRouter.POST("/favorite", baseApi.CreateFavorite)
fileRouter.POST("/favorite/del", baseApi.DeleteFavorite) fileRouter.POST("/favorite/del", baseApi.DeleteFavorite)
fileRouter.GET("/path/:type", baseApi.GetPathByType)
} }
} }

View File

@ -124,3 +124,7 @@ export const BatchChangeRole = (params: File.FileRole) => {
export const GetRecycleStatus = () => { export const GetRecycleStatus = () => {
return http.get<string>('files/recycle/status'); return http.get<string>('files/recycle/status');
}; };
export const GetPathByType = (pathType: string) => {
return http.get<string>(`files/path/${pathType}`);
};

View File

@ -87,7 +87,7 @@ const search = async () => {
}; };
const openTaskLog = (row: Log.Task) => { const openTaskLog = (row: Log.Task) => {
taskLogRef.value.openWithTaskID(row.id, !(row.status == 'Executing')); taskLogRef.value.openWithTaskID(row.id, row.status == 'Executing');
}; };
const acceptParams = () => { const acceptParams = () => {

View File

@ -43,7 +43,6 @@ const open = ref(false);
const showTail = ref(true); const showTail = ref(true);
const openWithTaskID = (id: string, tail: boolean) => { const openWithTaskID = (id: string, tail: boolean) => {
console.log('openWithTaskID', id, tail);
config.taskID = id; config.taskID = id;
if (tail === undefined) { if (tail === undefined) {
config.tail = true; config.tail = true;

View File

@ -302,6 +302,7 @@ const message = {
sending: 'Sending', sending: 'Sending',
healthy: 'Normal', healthy: 'Normal',
executing: 'Executing', executing: 'Executing',
installerr: 'Install Error',
}, },
units: { units: {
second: 'Second', 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', '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', webUIConfig: 'Please add the access address in the application parameters or the app store settings',
toLink: 'Open', 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: 'Website', website: 'Website',

View File

@ -297,6 +297,7 @@ const message = {
sending: '下發中', sending: '下發中',
healthy: '正常', healthy: '正常',
executing: '執行中', executing: '執行中',
installerr: '安裝失敗',
}, },
units: { units: {
second: '秒', second: '秒',
@ -1863,6 +1864,8 @@ const message = {
'默認訪問用於應用端口跳轉例如應用端口為 8080 則跳轉地址為 http(s)://默認訪問地址:8080', '默認訪問用於應用端口跳轉例如應用端口為 8080 則跳轉地址為 http(s)://默認訪問地址:8080',
webUIConfig: '請在應用參數或者應用商店設置處添加訪問地址', webUIConfig: '請在應用參數或者應用商店設置處添加訪問地址',
toLink: '連結', toLink: '連結',
customAppHelper: '當前使用的是主節點應用商店包修改配置請在主節點操作',
forceUninstall: '強制卸載',
}, },
website: { website: {
website: '網站', website: '網站',

View File

@ -297,6 +297,7 @@ const message = {
sending: '下发中', sending: '下发中',
healthy: '正常', healthy: '正常',
executing: '执行中', executing: '执行中',
installerr: '安装失败',
}, },
units: { units: {
second: '秒', second: '秒',
@ -1862,6 +1863,7 @@ const message = {
webUIConfig: '请在应用参数或者应用商店设置处添加访问地址', webUIConfig: '请在应用参数或者应用商店设置处添加访问地址',
toLink: '跳转', toLink: '跳转',
customAppHelper: '当前使用的是主节点应用商店包修改配置请在主节点操作', customAppHelper: '当前使用的是主节点应用商店包修改配置请在主节点操作',
forceUninstall: '强制卸载',
}, },
website: { website: {
website: '网站', website: '网站',

View File

@ -114,6 +114,7 @@ import { GetAppService } from '@/api/modules/app';
import { Rules } from '@/global/form-rules'; import { Rules } from '@/global/form-rules';
import { App } from '@/api/interface/app'; import { App } from '@/api/interface/app';
import { getDBName } from '@/utils/util'; import { getDBName } from '@/utils/util';
import { GetPathByType } from '@/api/modules/files';
interface ParamObj extends App.FromField { interface ParamObj extends App.FromField {
services: App.AppService[]; services: App.AppService[];
@ -186,6 +187,11 @@ const handleParams = () => {
} else { } else {
form[p.envKey] = p.default; 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.required) {
if (p.type === 'service' || p.type === 'apps') { if (p.type === 'service' || p.type === 'apps') {
rules[p.envKey] = [Rules.requiredSelect]; rules[p.envKey] = [Rules.requiredSelect];

View File

@ -1,8 +1,8 @@
<template> <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 ref="deleteForm" label-position="left" v-loading="loading">
<el-form-item> <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"> <span class="input-help">
{{ $t('app.forceDeleteHelper') }} {{ $t('app.forceDeleteHelper') }}
</span> </span>