Init: Create & Init dayu Project...
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
4
packages/faas/.gitignore
vendored
Normal file
4
packages/faas/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
/node_modules
|
||||
/dist
|
||||
/package-lock.json
|
||||
/yarn.lock
|
||||
22
packages/faas/.npmignore
Normal file
22
packages/faas/.npmignore
Normal file
@@ -0,0 +1,22 @@
|
||||
src
|
||||
test
|
||||
typings
|
||||
bundled
|
||||
build
|
||||
coverage
|
||||
docs
|
||||
wiki
|
||||
gulpfile.js
|
||||
bower.json
|
||||
karma.conf.js
|
||||
tsconfig.json
|
||||
typings.json
|
||||
CONTRIBUTING.md
|
||||
ISSUE_TEMPLATE.md
|
||||
PULL_REQUEST_TEMPLATE.md
|
||||
tslint.json
|
||||
wallaby.js
|
||||
.travis.yml
|
||||
.gitignore
|
||||
.vscode
|
||||
type_definitions
|
||||
11
packages/faas/README.md
Normal file
11
packages/faas/README.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# `@dayu/faas`
|
||||
|
||||
> TODO: description
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
const core = require('@dayu/faas');
|
||||
|
||||
// TODO: DEMONSTRATE API
|
||||
```
|
||||
27
packages/faas/package.json
Normal file
27
packages/faas/package.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "@dayu/faas",
|
||||
"version": "0.0.1",
|
||||
"description": "> TODO: description",
|
||||
"author": "MiaoWoo <admin@yumc.pw>",
|
||||
"homepage": "https://github.com/circlecloud/dayu",
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"publishConfig": {
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "npx ts-node-dev src/index.ts",
|
||||
"clean": "rimraf dist",
|
||||
"watch": "npx tsc --watch",
|
||||
"build": "yarn clean && npx tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.19.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.3",
|
||||
"ts-node-dev": "^1.0.0-pre.40",
|
||||
"typescript": "^3.5.2"
|
||||
}
|
||||
}
|
||||
28
packages/faas/public/index.html
Normal file
28
packages/faas/public/index.html
Normal file
@@ -0,0 +1,28 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<script src="https://cdn.jsdelivr.net/npm/socket.io-client@2.2.0/dist/socket.io.js"> </script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@3.12.2/dist/xterm.css" />
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@3.12.2/dist/addons/fullscreen/fullscreen.css">
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/xterm@3.12.2/dist/xterm.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/xterm@3.12.2/dist/addons/fit/fit.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/xterm@3.12.2/dist/addons/attach/attach.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/xterm@3.12.2/dist/addons/fullscreen/fullscreen.js"></script>
|
||||
<style>
|
||||
#terminal-container .terminal.xterm {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#terminal-container .xterm-viewport {
|
||||
height: 100% !important;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="terminal" style="height: 100%;"></div>
|
||||
<script type="text/javascript" src="js/index.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
68
packages/faas/public/js/index.js
Normal file
68
packages/faas/public/js/index.js
Normal file
@@ -0,0 +1,68 @@
|
||||
let command = '';
|
||||
Terminal.applyAddon(fit);
|
||||
Terminal.applyAddon(attach);
|
||||
Terminal.applyAddon(fullscreen);
|
||||
var term = new Terminal({
|
||||
experimentalCharAtlas: 'dynamic',
|
||||
cursorBlink: false,
|
||||
});
|
||||
term.open(document.getElementById('terminal'));
|
||||
term.toggleFullScreen();
|
||||
term.fit();
|
||||
|
||||
window.onresize = function() {
|
||||
term.fit();
|
||||
}
|
||||
|
||||
let query = {}
|
||||
location.search.substring(1).split("&").forEach(q => {
|
||||
let qy = q.split("=", 2);
|
||||
query[qy[0]] = qy[1]
|
||||
})
|
||||
|
||||
console.log(query);
|
||||
|
||||
var socket = io('/container', {
|
||||
path: '/ws',
|
||||
transports: ['websocket']
|
||||
});
|
||||
socket.on('connect', () => {
|
||||
term.writeln('connect')
|
||||
if (query.action) {
|
||||
term.writeln(`Recover Action: ${query.action} Data: ${query.data}`)
|
||||
switch (query.action) {
|
||||
case "container":
|
||||
socket.emit('logs', {
|
||||
id: query.data,
|
||||
since: Date.now() / 1000 - 60 * 15,
|
||||
until: Date.now() / 1000,
|
||||
stderr: false,
|
||||
tail: "all"
|
||||
})
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
});
|
||||
term.on('data', async data => {
|
||||
if (data == '\t') {
|
||||
return;
|
||||
}
|
||||
term.write(data);
|
||||
if (data == '\r') {
|
||||
term.write('\n');
|
||||
socket.emit('logs', {
|
||||
id: command
|
||||
})
|
||||
command = '';
|
||||
} else {
|
||||
command += data;
|
||||
}
|
||||
});
|
||||
socket.on('message', data => {
|
||||
term.write(data.toString() + '\r\n');
|
||||
});
|
||||
socket.on('disconnect', () => {
|
||||
term.reset();
|
||||
term.writeln('disconnect');
|
||||
});
|
||||
26
packages/faas/src/api.ts
Normal file
26
packages/faas/src/api.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import * as faas from './interfaces'
|
||||
import axios, { AxiosRequestConfig } from 'axios'
|
||||
|
||||
const instanceConfig: AxiosRequestConfig = {
|
||||
baseURL: 'https://faas.yumc.pw',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Basic YWRtaW46MmQ2MzdiYzQ4MWQxYThhMjg2M2E2ZTIzOTY1ZWRlNDI0ZTRjMTk2OTQyMzU5N2M5MzRlNGQyY2FlZTNkMjk2OA=='
|
||||
},
|
||||
timeout: 5000
|
||||
}
|
||||
|
||||
let api = axios.create(instanceConfig)
|
||||
|
||||
async function get<T>(path: string) {
|
||||
let result = await api.get(path);
|
||||
return result.data as T;
|
||||
}
|
||||
|
||||
export async function getFunctions() {
|
||||
return await get<faas.Function[]>('/system/functions');
|
||||
}
|
||||
|
||||
export async function getFunction(name: string) {
|
||||
return await get<faas.Function>(`/system/function/${name}`);
|
||||
}
|
||||
1
packages/faas/src/index.ts
Normal file
1
packages/faas/src/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './api'
|
||||
13
packages/faas/src/interfaces.ts
Normal file
13
packages/faas/src/interfaces.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export interface Labels {
|
||||
[key: string]: string
|
||||
}
|
||||
export interface Function {
|
||||
name: string;
|
||||
image: string;
|
||||
invocationCount: number;
|
||||
replicas: number;
|
||||
envProcess: string;
|
||||
availableReplicas: number;
|
||||
labels: Labels;
|
||||
annotations?: any;
|
||||
}
|
||||
7
packages/faas/tsconfig.json
Normal file
7
packages/faas/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "src",
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user