Skip to content

Commit

Permalink
feat(app-service): add appid & runtime version to app;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Dec 7, 2021
1 parent 2911cc1 commit 57fa817
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
13 changes: 11 additions & 2 deletions packages/app-service/src/cloud-sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { createFileStorage } from "../lib/storage"
import { CloudFunction } from "../lib/function"
import { WebSocket } from "ws"
import { WebSocketAgent } from "../lib/ws"
import Config from "../config"


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

/**
* 获取一个文件存储管理器
*
* @deprecated
* @param bucket 文件 Bucket 名字,默认为 'public'
*/
storage(bucket?: string): FileStorageInterface
Expand Down Expand Up @@ -94,9 +97,14 @@ export interface CloudSdkInterface {
mongo: MongoDriverObject

/**
* WebSocket 连接例表
* WebSocket 连接列表
*/
sockets: Set<WebSocket>

/**
* App ID
*/
appid: string
}


Expand Down Expand Up @@ -131,7 +139,8 @@ export function create() {
client: DatabaseAgent.accessor.conn,
db: DatabaseAgent.accessor.db
},
sockets: WebSocketAgent.clients
sockets: WebSocketAgent.clients,
appid: Config.APP_ID
}
return cloud
}
Expand Down
8 changes: 6 additions & 2 deletions packages/app-service/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ export default class Config {
return (process.env.FUNCTION_LOG_EXPIRED_TIME ?? 3600 * 24 * 30) as number
}

static get APP_VERSION(): number {
return process.env.APP_VERSION as any as number
static get RUNTIME_VERSION(): number {
return process.env.RUNTIME_VERSION as any as number
}

static get APP_ID(): string {
return process.env.APP_ID
}
}
8 changes: 6 additions & 2 deletions packages/app-service/src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*
* @Author: Maslow<wangfugen@126.com>
* @Date: 2021-07-30 10:30:29
* @LastEditTime: 2021-10-06 21:49:49
* @LastEditTime: 2021-12-07 13:13:40
* @Description:
*/

import { Router } from 'express'
import Config from '../config'
import { DatabaseAgent } from '../lib/database'
import { EntryRouter } from './entry'
import { FileRouter } from './file/index'
Expand All @@ -22,5 +23,8 @@ router.use('/health-check', (_req, res) => {
if (!DatabaseAgent.db) {
return res.status(400).send('no db connection')
}
return res.status(200).send('ok')
return res.send({
APP_ID: Config.APP_ID,
RUNTIME_VERSION: Config.RUNTIME_VERSION
})
})
4 changes: 2 additions & 2 deletions packages/system-client/src/views/application/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ export default {
async deleteApp(row) {
await this.$confirm('应用被删除后,暂不可恢复,确定释放?', '确认释放应用?')
console.log(row)
if (row.status !== 'cleared' && row.status !== 'created') { return showError('请先停止并清除该应用的服务') }
if (row.status === 'running') { return showError('请先停止该应用服务') }
this.loading = true
const res = await removeApplication(row.appid)
Expand Down Expand Up @@ -423,7 +423,7 @@ export default {
},
async removeAppService(app) {
const current_status = app.status
await this.$confirm('仅重置并重启应用服务实例容器,并不会删除应用或数据', '确认要重置应用服务?')
await this.$confirm('仅重置应用服务实例容器,并不会删除应用或数据', '确认要重置应用服务?')
this.serviceLoading = true
const res = await removeApplicationService(app.appid)
.finally(() => { this.serviceLoading = false })
Expand Down
5 changes: 3 additions & 2 deletions packages/system-server/src/lib/service-driver/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export class DockerContainerServiceDriver {

const container = await this.docker.createContainer({
Image: imageName,
// Cmd: ['node', `--max_old_space_size=${max_old_space_size}`, './dist/index.js'],
Cmd: ['sh', '/app/start.sh'],
name: `app_${app.appid}`,
Env: [
Expand All @@ -41,7 +40,9 @@ export class DockerContainerServiceDriver {
`LOG_LEVEL=${logLevel}`,
`ENABLE_CLOUD_FUNCTION_LOG=always`,
`SERVER_SECRET_SALT=${app.config.server_secret_salt}`,
`FLAGS=--max_old_space_size=${max_old_space_size}`
`FLAGS=--max_old_space_size=${max_old_space_size}`,
`APP_ID=${app.appid}`,
`RUNTIME_VERSION=${app.runtime?.image}`
],
ExposedPorts: {
"8000/tcp": {}
Expand Down

0 comments on commit 57fa817

Please sign in to comment.