Skip to content

Commit

Permalink
feat: 优化 PHP 运行环境日志 (#3286)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengkunwang223 committed Dec 12, 2023
1 parent 745d87a commit 168b6b8
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 26 deletions.
5 changes: 3 additions & 2 deletions backend/app/api/v1/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 21 additions & 18 deletions backend/app/service/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
)
Expand All @@ -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()

Expand All @@ -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
}
}

Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/modules/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/views/website/runtime/php/create/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ const phpSources = [
},
];
const em = defineEmits(['close']);
const em = defineEmits(['close', 'submit']);
const handleClose = () => {
open.value = false;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/views/website/runtime/php/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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) => {
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/views/website/ssl/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 168b6b8

Please sign in to comment.