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

feat: 优化 PHP 运行环境日志 (#3286)

This commit is contained in:
zhengkunwang 2023-12-12 15:18:09 +08:00 committed by GitHub
parent 745d87a6d3
commit 168b6b8667
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 26 deletions

View File

@ -46,11 +46,12 @@ func (b *BaseApi) CreateRuntime(c *gin.Context) {
if err := helper.CheckBindAndValidate(&req, c); err != nil { if err := helper.CheckBindAndValidate(&req, c); err != nil {
return return
} }
if err := runtimeService.Create(req); err != nil { ssl, err := runtimeService.Create(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return return
} }
helper.SuccessWithOutData(c) helper.SuccessWithData(c, ssl)
} }
// @Tags Website // @Tags Website

View File

@ -33,7 +33,7 @@ type RuntimeService struct {
type IRuntimeService interface { type IRuntimeService interface {
Page(req request.RuntimeSearch) (int64, []response.RuntimeDTO, error) Page(req request.RuntimeSearch) (int64, []response.RuntimeDTO, error)
Create(create request.RuntimeCreate) error Create(create request.RuntimeCreate) (*model.Runtime, error)
Delete(delete request.RuntimeDelete) error Delete(delete request.RuntimeDelete) error
Update(req request.RuntimeUpdate) error Update(req request.RuntimeUpdate) error
Get(id uint) (res *response.RuntimeDTO, err error) Get(id uint) (res *response.RuntimeDTO, err error)
@ -48,7 +48,7 @@ func NewRuntimeService() IRuntimeService {
return &RuntimeService{} return &RuntimeService{}
} }
func (r *RuntimeService) Create(create request.RuntimeCreate) (err error) { func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, error) {
var ( var (
opts []repo.DBOption opts []repo.DBOption
) )
@ -60,7 +60,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (err error) {
} }
exist, _ := runtimeRepo.GetFirst(opts...) exist, _ := runtimeRepo.GetFirst(opts...)
if exist != nil { if exist != nil {
return buserr.New(constant.ErrNameIsExist) return nil, buserr.New(constant.ErrNameIsExist)
} }
fileOp := files.NewFileOp() fileOp := files.NewFileOp()
@ -74,45 +74,45 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (err error) {
Version: create.Version, Version: create.Version,
Status: constant.RuntimeNormal, Status: constant.RuntimeNormal,
} }
return runtimeRepo.Create(context.Background(), runtime) return nil, runtimeRepo.Create(context.Background(), runtime)
} }
exist, _ = runtimeRepo.GetFirst(runtimeRepo.WithImage(create.Image)) exist, _ = runtimeRepo.GetFirst(runtimeRepo.WithImage(create.Image))
if exist != nil { if exist != nil {
return buserr.New(constant.ErrImageExist) return nil, buserr.New(constant.ErrImageExist)
} }
case constant.RuntimeNode: case constant.RuntimeNode:
if !fileOp.Stat(create.CodeDir) { if !fileOp.Stat(create.CodeDir) {
return buserr.New(constant.ErrPathNotFound) return nil, buserr.New(constant.ErrPathNotFound)
} }
create.Install = true create.Install = true
if err = checkPortExist(create.Port); err != nil { if err := checkPortExist(create.Port); err != nil {
return err return nil, err
} }
for _, export := range create.ExposedPorts { for _, export := range create.ExposedPorts {
if err = checkPortExist(export.HostPort); err != nil { if err := checkPortExist(export.HostPort); err != nil {
return err return nil, err
} }
} }
if containerName, ok := create.Params["CONTAINER_NAME"]; ok { if containerName, ok := create.Params["CONTAINER_NAME"]; ok {
if err := checkContainerName(containerName.(string)); err != nil { if err := checkContainerName(containerName.(string)); err != nil {
return err return nil, err
} }
} }
} }
appDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(create.AppDetailID)) appDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(create.AppDetailID))
if err != nil { if err != nil {
return err return nil, err
} }
app, err := appRepo.GetFirst(commonRepo.WithByID(appDetail.AppId)) app, err := appRepo.GetFirst(commonRepo.WithByID(appDetail.AppId))
if err != nil { if err != nil {
return err return nil, err
} }
appVersionDir := filepath.Join(app.GetAppResourcePath(), appDetail.Version) appVersionDir := filepath.Join(app.GetAppResourcePath(), appDetail.Version)
if !fileOp.Stat(appVersionDir) || appDetail.Update { if !fileOp.Stat(appVersionDir) || appDetail.Update {
if err := downloadApp(app, appDetail, nil); err != nil { if err = downloadApp(app, appDetail, nil); err != nil {
return err return nil, err
} }
} }
@ -128,15 +128,18 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (err error) {
switch create.Type { switch create.Type {
case constant.RuntimePHP: case constant.RuntimePHP:
if err = handlePHP(create, runtime, fileOp, appVersionDir); err != nil { if err = handlePHP(create, runtime, fileOp, appVersionDir); err != nil {
return return nil, err
} }
case constant.RuntimeNode: case constant.RuntimeNode:
runtime.Port = create.Port runtime.Port = create.Port
if err = handleNode(create, runtime, fileOp, appVersionDir); err != nil { if err = handleNode(create, runtime, fileOp, appVersionDir); err != nil {
return return nil, err
} }
} }
return runtimeRepo.Create(context.Background(), runtime) if err := runtimeRepo.Create(context.Background(), runtime); err != nil {
return nil, err
}
return runtime, nil
} }
func (r *RuntimeService) Page(req request.RuntimeSearch) (int64, []response.RuntimeDTO, error) { func (r *RuntimeService) Page(req request.RuntimeSearch) (int64, []response.RuntimeDTO, error) {

View File

@ -8,7 +8,7 @@ export const SearchRuntimes = (req: Runtime.RuntimeReq) => {
}; };
export const CreateRuntime = (req: Runtime.RuntimeCreate) => { export const CreateRuntime = (req: Runtime.RuntimeCreate) => {
return http.post<any>(`/runtimes`, req); return http.post<Runtime.Runtime>(`/runtimes`, req);
}; };
export const DeleteRuntime = (req: Runtime.RuntimeDelete) => { export const DeleteRuntime = (req: Runtime.RuntimeDelete) => {

View File

@ -230,7 +230,7 @@ const phpSources = [
}, },
]; ];
const em = defineEmits(['close']); const em = defineEmits(['close', 'submit']);
const handleClose = () => { const handleClose = () => {
open.value = false; open.value = false;
@ -315,9 +315,10 @@ const submit = async (formEl: FormInstance | undefined) => {
if (mode.value == 'create') { if (mode.value == 'create') {
loading.value = true; loading.value = true;
CreateRuntime(runtime) CreateRuntime(runtime)
.then(() => { .then((res) => {
MsgSuccess(i18n.global.t('commons.msg.createSuccess')); MsgSuccess(i18n.global.t('commons.msg.createSuccess'));
handleClose(); handleClose();
em('submit', res.data.id);
}) })
.finally(() => { .finally(() => {
loading.value = false; loading.value = false;
@ -328,6 +329,7 @@ const submit = async (formEl: FormInstance | undefined) => {
.then(() => { .then(() => {
MsgSuccess(i18n.global.t('commons.msg.updateSuccess')); MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));
handleClose(); handleClose();
em('submit', runtime.id);
}) })
.finally(() => { .finally(() => {
loading.value = false; loading.value = false;

View File

@ -71,7 +71,7 @@
</template> </template>
</LayoutContent> </LayoutContent>
<CreateRuntime ref="createRef" @close="search" /> <CreateRuntime ref="createRef" @close="search" @submit="openCreateLog" />
<OpDialog ref="opRef" @search="search" /> <OpDialog ref="opRef" @search="search" />
<Log ref="logRef" @close="search" /> <Log ref="logRef" @close="search" />
</div> </div>
@ -149,7 +149,11 @@ const openDetail = (row: Runtime.Runtime) => {
}; };
const openLog = (row: Runtime.RuntimeDTO) => { const openLog = (row: Runtime.RuntimeDTO) => {
logRef.value.acceptParams({ id: row.id, type: 'php' }); logRef.value.acceptParams({ id: row.id, type: 'php', tail: row.status == 'building' });
};
const openCreateLog = (id: number) => {
logRef.value.acceptParams({ id: id, type: 'php', tail: true });
}; };
const openDelete = async (row: Runtime.Runtime) => { const openDelete = async (row: Runtime.Runtime) => {

View File

@ -91,7 +91,7 @@
</el-table-column> </el-table-column>
<el-table-column :label="$t('website.log')" width="100px"> <el-table-column :label="$t('website.log')" width="100px">
<template #default="{ row }"> <template #default="{ row }">
<el-button @click="openLog(row.id)" link type="primary"> <el-button @click="openSSLLog(row)" link type="primary" v-if="row.provider != 'manual'">
{{ $t('website.check') }} {{ $t('website.check') }}
</el-button> </el-button>
</template> </template>
@ -320,6 +320,9 @@ const openDetail = (id: number) => {
const openLog = (id: number) => { const openLog = (id: number) => {
logRef.value.acceptParams({ id: id, type: 'ssl', tail: true }); logRef.value.acceptParams({ id: id, type: 'ssl', tail: true });
}; };
const openSSLLog = (row: Website.SSL) => {
logRef.value.acceptParams({ id: row.id, type: 'ssl', tail: row.status === 'applying' });
};
const openCA = () => { const openCA = () => {
caRef.value.acceptParams(); caRef.value.acceptParams();