Skip to content

Commit 57fa817

Browse files
committed
feat(app-service): add appid & runtime version to app;
1 parent 2911cc1 commit 57fa817

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

packages/app-service/src/cloud-sdk/index.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { createFileStorage } from "../lib/storage"
1212
import { CloudFunction } from "../lib/function"
1313
import { WebSocket } from "ws"
1414
import { WebSocketAgent } from "../lib/ws"
15+
import Config from "../config"
1516

1617

1718
export type InvokeFunctionType = (name: string, param: FunctionContext) => Promise<any>
@@ -32,6 +33,8 @@ export interface CloudSdkInterface {
3233

3334
/**
3435
* 获取一个文件存储管理器
36+
*
37+
* @deprecated
3538
* @param bucket 文件 Bucket 名字,默认为 'public'
3639
*/
3740
storage(bucket?: string): FileStorageInterface
@@ -94,9 +97,14 @@ export interface CloudSdkInterface {
9497
mongo: MongoDriverObject
9598

9699
/**
97-
* WebSocket 连接例表
100+
* WebSocket 连接列表
98101
*/
99102
sockets: Set<WebSocket>
103+
104+
/**
105+
* App ID
106+
*/
107+
appid: string
100108
}
101109

102110

@@ -131,7 +139,8 @@ export function create() {
131139
client: DatabaseAgent.accessor.conn,
132140
db: DatabaseAgent.accessor.db
133141
},
134-
sockets: WebSocketAgent.clients
142+
sockets: WebSocketAgent.clients,
143+
appid: Config.APP_ID
135144
}
136145
return cloud
137146
}

packages/app-service/src/config.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ export default class Config {
107107
return (process.env.FUNCTION_LOG_EXPIRED_TIME ?? 3600 * 24 * 30) as number
108108
}
109109

110-
static get APP_VERSION(): number {
111-
return process.env.APP_VERSION as any as number
110+
static get RUNTIME_VERSION(): number {
111+
return process.env.RUNTIME_VERSION as any as number
112+
}
113+
114+
static get APP_ID(): string {
115+
return process.env.APP_ID
112116
}
113117
}

packages/app-service/src/router/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
22
* @Author: Maslow<[email protected]>
33
* @Date: 2021-07-30 10:30:29
4-
* @LastEditTime: 2021-10-06 21:49:49
4+
* @LastEditTime: 2021-12-07 13:13:40
55
* @Description:
66
*/
77

88
import { Router } from 'express'
9+
import Config from '../config'
910
import { DatabaseAgent } from '../lib/database'
1011
import { EntryRouter } from './entry'
1112
import { FileRouter } from './file/index'
@@ -22,5 +23,8 @@ router.use('/health-check', (_req, res) => {
2223
if (!DatabaseAgent.db) {
2324
return res.status(400).send('no db connection')
2425
}
25-
return res.status(200).send('ok')
26+
return res.send({
27+
APP_ID: Config.APP_ID,
28+
RUNTIME_VERSION: Config.RUNTIME_VERSION
29+
})
2630
})

packages/system-client/src/views/application/index.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ export default {
382382
async deleteApp(row) {
383383
await this.$confirm('应用被删除后,暂不可恢复,确定释放?', '确认释放应用?')
384384
console.log(row)
385-
if (row.status !== 'cleared' && row.status !== 'created') { return showError('请先停止并清除该应用的服务') }
385+
if (row.status === 'running') { return showError('请先停止该应用服务') }
386386
this.loading = true
387387
388388
const res = await removeApplication(row.appid)
@@ -423,7 +423,7 @@ export default {
423423
},
424424
async removeAppService(app) {
425425
const current_status = app.status
426-
await this.$confirm('仅重置并重启应用服务实例容器,并不会删除应用或数据', '确认要重置应用服务?')
426+
await this.$confirm('仅重置应用服务实例容器,并不会删除应用或数据', '确认要重置应用服务?')
427427
this.serviceLoading = true
428428
const res = await removeApplicationService(app.appid)
429429
.finally(() => { this.serviceLoading = false })

packages/system-server/src/lib/service-driver/container.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export class DockerContainerServiceDriver {
3232

3333
const container = await this.docker.createContainer({
3434
Image: imageName,
35-
// Cmd: ['node', `--max_old_space_size=${max_old_space_size}`, './dist/index.js'],
3635
Cmd: ['sh', '/app/start.sh'],
3736
name: `app_${app.appid}`,
3837
Env: [
@@ -41,7 +40,9 @@ export class DockerContainerServiceDriver {
4140
`LOG_LEVEL=${logLevel}`,
4241
`ENABLE_CLOUD_FUNCTION_LOG=always`,
4342
`SERVER_SECRET_SALT=${app.config.server_secret_salt}`,
44-
`FLAGS=--max_old_space_size=${max_old_space_size}`
43+
`FLAGS=--max_old_space_size=${max_old_space_size}`,
44+
`APP_ID=${app.appid}`,
45+
`RUNTIME_VERSION=${app.runtime?.image}`
4546
],
4647
ExposedPorts: {
4748
"8000/tcp": {}

0 commit comments

Comments
 (0)