mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
feat: 优化 PHP 运行环境日志 (#3286)
This commit is contained in:
parent
745d87a6d3
commit
168b6b8667
@ -46,11 +46,12 @@ func (b *BaseApi) CreateRuntime(c *gin.Context) {
|
||||
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
||||
return
|
||||
}
|
||||
if err := runtimeService.Create(req); err != nil {
|
||||
ssl, err := runtimeService.Create(req)
|
||||
if err != nil {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
||||
return
|
||||
}
|
||||
helper.SuccessWithOutData(c)
|
||||
helper.SuccessWithData(c, ssl)
|
||||
}
|
||||
|
||||
// @Tags Website
|
||||
|
@ -33,7 +33,7 @@ type RuntimeService struct {
|
||||
|
||||
type IRuntimeService interface {
|
||||
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
|
||||
Update(req request.RuntimeUpdate) error
|
||||
Get(id uint) (res *response.RuntimeDTO, err error)
|
||||
@ -48,7 +48,7 @@ func NewRuntimeService() IRuntimeService {
|
||||
return &RuntimeService{}
|
||||
}
|
||||
|
||||
func (r *RuntimeService) Create(create request.RuntimeCreate) (err error) {
|
||||
func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, error) {
|
||||
var (
|
||||
opts []repo.DBOption
|
||||
)
|
||||
@ -60,7 +60,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (err error) {
|
||||
}
|
||||
exist, _ := runtimeRepo.GetFirst(opts...)
|
||||
if exist != nil {
|
||||
return buserr.New(constant.ErrNameIsExist)
|
||||
return nil, buserr.New(constant.ErrNameIsExist)
|
||||
}
|
||||
fileOp := files.NewFileOp()
|
||||
|
||||
@ -74,45 +74,45 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (err error) {
|
||||
Version: create.Version,
|
||||
Status: constant.RuntimeNormal,
|
||||
}
|
||||
return runtimeRepo.Create(context.Background(), runtime)
|
||||
return nil, runtimeRepo.Create(context.Background(), runtime)
|
||||
}
|
||||
exist, _ = runtimeRepo.GetFirst(runtimeRepo.WithImage(create.Image))
|
||||
if exist != nil {
|
||||
return buserr.New(constant.ErrImageExist)
|
||||
return nil, buserr.New(constant.ErrImageExist)
|
||||
}
|
||||
case constant.RuntimeNode:
|
||||
if !fileOp.Stat(create.CodeDir) {
|
||||
return buserr.New(constant.ErrPathNotFound)
|
||||
return nil, buserr.New(constant.ErrPathNotFound)
|
||||
}
|
||||
create.Install = true
|
||||
if err = checkPortExist(create.Port); err != nil {
|
||||
return err
|
||||
if err := checkPortExist(create.Port); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, export := range create.ExposedPorts {
|
||||
if err = checkPortExist(export.HostPort); err != nil {
|
||||
return err
|
||||
if err := checkPortExist(export.HostPort); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if containerName, ok := create.Params["CONTAINER_NAME"]; ok {
|
||||
if err := checkContainerName(containerName.(string)); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
appDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(create.AppDetailID))
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
app, err := appRepo.GetFirst(commonRepo.WithByID(appDetail.AppId))
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
appVersionDir := filepath.Join(app.GetAppResourcePath(), appDetail.Version)
|
||||
if !fileOp.Stat(appVersionDir) || appDetail.Update {
|
||||
if err := downloadApp(app, appDetail, nil); err != nil {
|
||||
return err
|
||||
if err = downloadApp(app, appDetail, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,15 +128,18 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (err error) {
|
||||
switch create.Type {
|
||||
case constant.RuntimePHP:
|
||||
if err = handlePHP(create, runtime, fileOp, appVersionDir); err != nil {
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
case constant.RuntimeNode:
|
||||
runtime.Port = create.Port
|
||||
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) {
|
||||
|
@ -8,7 +8,7 @@ export const SearchRuntimes = (req: Runtime.RuntimeReq) => {
|
||||
};
|
||||
|
||||
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) => {
|
||||
|
@ -230,7 +230,7 @@ const phpSources = [
|
||||
},
|
||||
];
|
||||
|
||||
const em = defineEmits(['close']);
|
||||
const em = defineEmits(['close', 'submit']);
|
||||
|
||||
const handleClose = () => {
|
||||
open.value = false;
|
||||
@ -315,9 +315,10 @@ const submit = async (formEl: FormInstance | undefined) => {
|
||||
if (mode.value == 'create') {
|
||||
loading.value = true;
|
||||
CreateRuntime(runtime)
|
||||
.then(() => {
|
||||
.then((res) => {
|
||||
MsgSuccess(i18n.global.t('commons.msg.createSuccess'));
|
||||
handleClose();
|
||||
em('submit', res.data.id);
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
@ -328,6 +329,7 @@ const submit = async (formEl: FormInstance | undefined) => {
|
||||
.then(() => {
|
||||
MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));
|
||||
handleClose();
|
||||
em('submit', runtime.id);
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
|
@ -71,7 +71,7 @@
|
||||
</template>
|
||||
</LayoutContent>
|
||||
|
||||
<CreateRuntime ref="createRef" @close="search" />
|
||||
<CreateRuntime ref="createRef" @close="search" @submit="openCreateLog" />
|
||||
<OpDialog ref="opRef" @search="search" />
|
||||
<Log ref="logRef" @close="search" />
|
||||
</div>
|
||||
@ -149,7 +149,11 @@ const openDetail = (row: Runtime.Runtime) => {
|
||||
};
|
||||
|
||||
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) => {
|
||||
|
@ -91,7 +91,7 @@
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('website.log')" width="100px">
|
||||
<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') }}
|
||||
</el-button>
|
||||
</template>
|
||||
@ -320,6 +320,9 @@ const openDetail = (id: number) => {
|
||||
const openLog = (id: number) => {
|
||||
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 = () => {
|
||||
caRef.value.acceptParams();
|
||||
|
Loading…
x
Reference in New Issue
Block a user