Skip to content

Commit

Permalink
feat(sys-client): remove api-app proxy; add runtime version & memory
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Nov 12, 2021
1 parent 3e29e95 commit 5063b2e
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 111 deletions.
5 changes: 1 addition & 4 deletions packages/system-client/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@
ENV = 'development'

# sys api base url
VUE_APP_BASE_API_SYS = '/sys-api'

# app api base url
VUE_APP_BASE_API_APP = '/app-api'
VUE_APP_BASE_API_SYS = '/sys-api'
5 changes: 1 addition & 4 deletions packages/system-client/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@
ENV = 'production'

# sys api base url
VUE_APP_BASE_API_SYS = '/sys-api'

# app api base url
VUE_APP_BASE_API_APP = '/app-api'
VUE_APP_BASE_API_SYS = '/sys-api'
5 changes: 1 addition & 4 deletions packages/system-client/.env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@ NODE_ENV = production
ENV = 'staging'

# sys api base url
VUE_APP_BASE_API_SYS = '/sys-api'

# app api base url
VUE_APP_BASE_API_APP = '/app-api'
VUE_APP_BASE_API_SYS = '/sys-api'
2 changes: 2 additions & 0 deletions packages/system-client/copy2gateway.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rm -rf ../gateway/dist
cp -r dist ../gateway/dist
65 changes: 0 additions & 65 deletions packages/system-client/nginx.conf

This file was deleted.

5 changes: 3 additions & 2 deletions packages/system-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
"dev": "vue-cli-service serve",
"lint": "eslint --ext .js,.vue src",
"fix": "eslint --ext .js,.vue src --fix",
"build": "npm run build:prod",
"build": "npm run build:prod && npm run copy2gw",
"build:prod": "vue-cli-service build",
"build:stage": "vue-cli-service build --mode staging",
"preview": "node build/index.js --preview",
"svgo": "svgo -f src/icons/svg --config=src/icons/svgo.yml",
"commit": "commit"
"commit": "commit",
"copy2gw": "sh copy2gateway.sh"
},
"dependencies": {
"axios": "^0.21.1",
Expand Down
9 changes: 5 additions & 4 deletions packages/system-client/src/api/func.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import store from '@/store'
import request from '@/utils/request'
import axios from 'axios'
import { getAppAccessUrl } from './application'

/**
* Get cloud function list
Expand Down Expand Up @@ -158,9 +159,9 @@ export function publishOneFunction(func_id) {
* Debug cloud function
*/
export async function launchFunction(func, param, debug = false) {
const appid = store.state.app.appid
const app_url = getAppAccessUrl()
const res = await axios({
url: process.env.VUE_APP_BASE_API_APP + `/${appid}/func/debug/${func.name}`,
url: app_url + `/func/debug/${func.name}`,
method: 'post',
data: {
func,
Expand All @@ -180,9 +181,9 @@ export async function launchFunction(func, param, debug = false) {
* @returns
*/
export async function loadPackageTypings(packageName) {
const appid = store.state.app.appid
const app_url = getAppAccessUrl()
const res = await axios({
url: process.env.VUE_APP_BASE_API_APP + `/${appid}/typing/package?packageName=${packageName}`,
url: app_url + `/typing/package?packageName=${packageName}`,
method: 'GET'
})

Expand Down
100 changes: 80 additions & 20 deletions packages/system-client/src/views/application/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,54 @@
<div class="app-group">
<div class="app-group-title">我创建的应用</div>
<el-table v-loading="loading" empty-text="还没有创建应用" :data="applications.created" style="width: 100%;margin-top:10px;" stripe>
<el-table-column align="center" label="App ID" width="340">
<el-table-column align="center" label="App ID" width="320">
<template slot-scope="scope">
<div class="table-row">
<div> {{ scope.row.appid }}</div>
<el-tooltip :content="scope.row.appid" effect="light" placement="top">
<div class="table-column-text"> {{ scope.row.appid }}</div>
</el-tooltip>
<i v-clipboard:message="scope.row.appid" v-clipboard:success="onCopy" class="el-icon-document-copy copy-btn" />
</div>
</template>
</el-table-column>
<el-table-column align="center" label="应用名" width="400">
<template slot-scope="{row}">
<span class="link-type" @click="showUpdateForm(row)">{{ row.name }}</span>
<span class="link-type table-column-text" @click="showUpdateForm(row)">{{ row.name }}</span>
</template>
</el-table-column>
<el-table-column align="left" label="Status" width="200">
<el-table-column align="center" label="状态" width="100">
<template slot-scope="scope">
{{ scope.row.status }}
</template>
</el-table-column>
<el-table-column label="服务启停" align="left" width="200" class-name="small-padding">
<el-table-column align="center" label="服务版本" width="100">
<template slot-scope="scope">
{{ getRuntimeVersion(scope.row) }}
</template>
</el-table-column>
<el-table-column align="center" label="运行内存" width="100">
<template slot-scope="scope">
{{ getRuntimeMemory(scope.row) }} M
</template>
</el-table-column>
<el-table-column label="服务启停" align="center" width="300" class-name="small-padding">
<template slot-scope="{row}">
<el-button v-if="row.status !== 'running'" :loading="serviceLoading" plain type="success" size="mini" @click="startApp(row)">
启动
</el-button>
<el-button v-if="row.status === 'running'" :loading="serviceLoading" plain type="danger" size="mini" @click="stopApp(row)">
停止
</el-button>
<el-tooltip content="仅清除应用服务实例,并[不会]删除应用或数据,请放心清除" effect="light" placement="bottom">
<el-button v-if="row.status === 'stopped'" :loading="serviceLoading" plain type="default" size="mini" @click="removeAppService(row)">
清除
<el-tooltip content="仅重启应用进程,并不会删除服务实例容器" effect="light" placement="bottom">
<el-button v-if="row.status === 'running'" :loading="serviceLoading" plain type="default" size="mini" @click="restartApp(row)">
重启
</el-button>
</el-tooltip>
<el-tooltip content="仅重置并重启应用服务实例容器,并不会删除应用或数据" effect="light" placement="bottom">
<el-button :loading="serviceLoading" plain type="info" size="mini" @click="removeAppService(row)">
重置
</el-button>
</el-tooltip>

</template>
</el-table-column>
<el-table-column label="创建时间" align="center">
Expand Down Expand Up @@ -81,35 +97,52 @@
<div class="app-group">
<div class="app-group-title">我加入的应用</div>
<el-table v-loading="loading" empty-text="还没有加入的应用" :data="applications.joined" style="width: 100%;margin-top:10px;" stripe>
<el-table-column align="center" label="App ID" width="340">
<el-table-column align="center" label="App ID" width="320">
<template slot-scope="scope">
<div class="table-row">
<div> {{ scope.row.appid }}</div>
<el-tooltip :content="scope.row.appid" effect="light" placement="top">
<div class="table-column-text"> {{ scope.row.appid }}</div>
</el-tooltip>
<i v-clipboard:message="scope.row.appid" v-clipboard:success="onCopy" class="el-icon-document-copy copy-btn" />
</div>
</template>
</el-table-column>
<el-table-column align="center" label="应用名" width="400">
<template slot-scope="{row}">
<span class="link-type" @click="showUpdateForm(row)">{{ row.name }}</span>
<span class="link-type table-column-text" @click="showUpdateForm(row)">{{ row.name }}</span>
</template>
</el-table-column>
<el-table-column align="left" label="Status" width="200">
<el-table-column align="center" label="状态" width="100">
<template slot-scope="scope">
{{ scope.row.status }}
</template>
</el-table-column>
<el-table-column label="服务启停" align="left" width="200" class-name="small-padding">
<el-table-column align="center" label="服务版本" width="100">
<template slot-scope="scope">
{{ getRuntimeVersion(scope.row) }}
</template>
</el-table-column>
<el-table-column align="center" label="运行内存" width="100">
<template slot-scope="scope">
{{ getRuntimeMemory(scope.row) }} M
</template>
</el-table-column>
<el-table-column label="服务启停" align="center" width="300" class-name="small-padding">
<template slot-scope="{row}">
<el-button v-if="row.status !== 'running'" :loading="serviceLoading" plain type="success" size="mini" @click="startApp(row)">
启动
</el-button>
<el-button v-if="row.status === 'running'" :loading="serviceLoading" plain type="danger" size="mini" @click="stopApp(row)">
停止
</el-button>
<el-tooltip content="仅清除应用服务实例,并[不会]删除应用或数据,请放心清除" effect="light" placement="bottom">
<el-button v-if="row.status === 'stopped'" :loading="serviceLoading" plain type="default" size="mini" @click="removeAppService(row)">
清除
<el-tooltip content="仅重启应用进程,并不会删除服务实例容器" effect="light" placement="bottom">
<el-button v-if="row.status === 'running'" :loading="serviceLoading" plain type="default" size="mini" @click="restartApp(row)">
重启
</el-button>
</el-tooltip>
<el-tooltip content="仅重置并重启应用服务实例容器,并不会删除应用或数据" effect="light" placement="bottom">
<el-button :loading="serviceLoading" plain type="info" size="mini" @click="removeAppService(row)">
重置
</el-button>
</el-tooltip>
</template>
Expand Down Expand Up @@ -387,13 +420,22 @@ export default {
return
}
},
async restartApp(app) {
if (app.status !== 'running') { return }
await this.stopApp(app)
await this.startApp(app)
},
async removeAppService(app) {
await this.$confirm('确认要删除应用服务?', '服务操作确认')
const current_status = app.status
await this.$confirm('仅重置并重启应用服务实例容器,并不会删除应用或数据', '确认要重置应用服务?')
this.serviceLoading = true
const res = await removeApplicationService(app.appid)
.finally(() => { this.serviceLoading = false })
if (res.data) {
this.$notify.success('删除应用服务成功')
this.$notify.success('重置应用服务成功')
if (current_status === 'running') {
await this.startApp(app)
}
this.loadApps()
return
}
Expand Down Expand Up @@ -437,6 +479,19 @@ export default {
} finally {
this.loading = false
}
},
getRuntimeVersion(app) {
const image = app.runtime?.image
if (!image) {
return 'unknow'
}
const [, version] = image.split(':')
return version || 'unknow'
},
getRuntimeMemory(app) {
const memory = app.runtime?.metrics?.memory
return memory || '256'
}
}
}
Expand All @@ -455,6 +510,12 @@ export default {
justify-content: space-between;
}
.table-column-text {
overflow:hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.app-secret {
overflow: hidden;
text-overflow: ellipsis;
Expand All @@ -465,7 +526,6 @@ export default {
.copy-btn {
display: block;
font-size: 16px;
margin-left: 10px;
cursor: pointer;
}
Expand Down
9 changes: 1 addition & 8 deletions packages/system-client/vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,11 @@ module.exports = {
proxy: {
// detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_BASE_API_SYS]: {
target: 'http://localhost:8080/',
target: 'http://console.local-dev.host:8080/',
changeOrigin: true,
// pathRewrite: {
// ['^' + process.env.VUE_APP_BASE_API_SYS]: ''
// }
},
[process.env.VUE_APP_BASE_API_APP]: {
target: 'http://localhost:8080/',
changeOrigin: true
// pathRewrite: {
// ['^' + process.env.VUE_APP_BASE_API_APP]: ''
// }
}
},
disableHostCheck: true
Expand Down

0 comments on commit 5063b2e

Please sign in to comment.