self update and serve static/dist

This commit is contained in:
peter
2019-08-28 00:24:30 +02:00
parent fc0bae15ed
commit 997ae629b6
5 changed files with 15 additions and 116 deletions
+1 -2
View File
@@ -2,8 +2,7 @@ FROM node:alpine
RUN apk add git RUN apk add git
WORKDIR /service WORKDIR /service
COPY dist /service/dist RUN git clone https://gitea.frontblock.me/fb-dist/admin.git dist
COPY node_modules /service/node_modules
EXPOSE 8080 20000 EXPOSE 8080 20000
ENTRYPOINT ["node", "dist/FrontblockAdmin.js"] ENTRYPOINT ["node", "dist/FrontblockAdmin.js"]
+4 -3
View File
@@ -2123,13 +2123,14 @@
} }
}, },
"frontblock-generic": { "frontblock-generic": {
"version": "0.30.3", "version": "0.30.6",
"resolved": "https://registry.npmjs.org/frontblock-generic/-/frontblock-generic-0.30.3.tgz", "resolved": "https://registry.npmjs.org/frontblock-generic/-/frontblock-generic-0.30.6.tgz",
"integrity": "sha512-RvgGaG2Bx9AaCVssu9/ZPGCCWg9FCwMFEa+6ZRyNNPvddh5smE5Yo+59KWDMUHKpMkV25HF6JR6Tl9YwQ82z5Q==", "integrity": "sha512-ecOwcLpzPuAOThKhIdbdXQm7M7HnF6dtNf1dOr7pxFfkBq5T5h/wxT2mdlC3rUd1HqdKxwrUjqG+1XqKjwVY4g==",
"requires": { "requires": {
"@types/lowdb": "^1.0.9", "@types/lowdb": "^1.0.9",
"@types/node": "^12.7.1", "@types/node": "^12.7.1",
"bsock": "^0.1.9", "bsock": "^0.1.9",
"express": "^4.17.1",
"fs": "0.0.1-security", "fs": "0.0.1-security",
"http": "0.0.0", "http": "0.0.0",
"key-file-storage": "^2.2.4", "key-file-storage": "^2.2.4",
+3 -4
View File
@@ -7,9 +7,8 @@
"start": "npm run build; node dist/FrontblockAdmin.js", "start": "npm run build; node dist/FrontblockAdmin.js",
"build": "npm run clean; npm run build-backend; npm run build-frontend", "build": "npm run clean; npm run build-backend; npm run build-frontend",
"build-backend": "tsc; npm run webpack", "build-backend": "tsc; npm run webpack",
"build-frontend": "npm run build-dashboard; cp ./dist/FrontblockLib.js ./static", "build-frontend": "npm run build-dashboard; cp ./dist/FrontblockLib.js ./dist/static",
"build-dashboard": "git submodule init && git submodule update --merge; cd src/frontend; npm i && npm run build; mkdir ../../static; cp -r dist/* ../../static", "build-dashboard": "git submodule init && git submodule update --merge; cd src/frontend; npm i && npm run build; mkdir ../../dist/static; cp -r dist/* ../../dist/static",
"build-widget": "rollup -c src/frontend/widget/rollup.config.js; mkdir -p plugins/PluginManager; cp FrontendPlugin.js plugins/PluginManager",
"clean": "rm -rf lib static plugins conf dist widget .rpt2_cache *.js *.ts src/frontend/dist", "clean": "rm -rf lib static plugins conf dist widget .rpt2_cache *.js *.ts src/frontend/dist",
"update-frontblock": "rm -rf node_modules/frontblock*; npm install", "update-frontblock": "rm -rf node_modules/frontblock*; npm install",
"webpack": "webpack --config src/backend/webpack.prod.js --progress --colors" "webpack": "webpack --config src/backend/webpack.prod.js --progress --colors"
@@ -27,7 +26,7 @@
"debug": "^4.1.1", "debug": "^4.1.1",
"express": "^4.16.4", "express": "^4.16.4",
"frontblock": "^0.14.0", "frontblock": "^0.14.0",
"frontblock-generic": "^0.30.3", "frontblock-generic": "^0.30.6",
"git-cherrypicker": "0.0.3", "git-cherrypicker": "0.0.3",
"git-describe": "^4.0.4", "git-describe": "^4.0.4",
"http": "0.0.0", "http": "0.0.0",
+2 -102
View File
@@ -4,16 +4,11 @@ import * as Logger from 'log4js'
import * as Knex from 'knex' import * as Knex from 'knex'
import { FrontblockApiClient, FrontblockApiConf } from 'frontblock'; import { FrontblockApiClient, FrontblockApiConf } from 'frontblock';
import { AdminBase } from 'frontblock-generic/Admin'; import { AdminBase } from 'frontblock-generic/Admin';
import express = require('express');
import http = require('http');
import bsock = require('bsock');
import { promises as fs } from "fs"
import * as path from "path"
import { FrontblockApi } from 'frontblock-generic/Api'; import { FrontblockApi } from 'frontblock-generic/Api';
import { Plugin } from 'frontblock-generic/Plugin'; import { Plugin } from 'frontblock-generic/Plugin';
import { socketioRPC } from 'frontblock-generic/RPC'; import { socketioRPC } from 'frontblock-generic/RPC';
import { GitUpdater } from './GitUpdater'; import { GitUpdater } from './GitUpdater';
var exec = require('child-process-promise').exec; import { UpdateManager } from './UpdateManger';
Logger.configure({ Logger.configure({
appenders: appenders:
@@ -33,14 +28,9 @@ export type AdminConf = { httpPort: number}
export class FrontblockAdmin extends AdminBase<AdminConf>{ export class FrontblockAdmin extends AdminBase<AdminConf>{
private express
private httpServer
private io = bsock.createServer()
private wsServer = http.createServer()
constructor(runningPlugins: Plugin[] = []){ constructor(runningPlugins: Plugin[] = []){
super(runningPlugins) super(runningPlugins)
this.initialize() this.addPlugin(new UpdateManager(this))
} }
getDefaultConfig(): { apiConf: FrontblockApiConf; } & AdminConf & { dbConf:Knex.Config; } { getDefaultConfig(): { apiConf: FrontblockApiConf; } & AdminConf & { dbConf:Knex.Config; } {
@@ -72,16 +62,6 @@ export class FrontblockAdmin extends AdminBase<AdminConf>{
return this.apiClient return this.apiClient
} }
private initialize(){
this.startWebserver()
this.startWebsocket()
}
private destroy(){
this.wsServer.close()
this.stopWebserver()
}
exportRPCs():socketioRPC[]{ exportRPCs():socketioRPC[]{
return [ return [
...super.exportRPCs(), ...super.exportRPCs(),
@@ -107,86 +87,6 @@ export class FrontblockAdmin extends AdminBase<AdminConf>{
} }
return status return status
} }
private startWebserver(){
if(this.httpServer != null || this.express != null){
logger.warn("Webserver is already running")
return
}
let port:number = this.getConfig().httpPort
this.express = express()
this.express.use('/', express.static('static'))
/**
* get the compiled FrontendPlugins.js
*/
this.express.get('/plugins/:id'+".js", async (request, response) => {
const pth = path.resolve("plugins/"+request.params.id, "FrontendPlugin.js");
const file = await fs.readFile(pth)
const frontend = file.toString()
response.status(200)
response.set('Content-Type', 'application/javascript')
response.send(frontend)
})
/**
* serve the index.html from the static folder
*/
this.express.get("/", (request, response) => {
response.status(200)
response.sendFile('index.html');
})
/**
* redirect all the other traffic to the single
* page app to the main entry point from where
* a webpacked and rolled up index.html is serverd
* and angular takes over routing
*/
this.express.get("*", (request, response) => {
response.status(301)
response.redirect('/')
})
this.httpServer = new http.Server(this.express)
this.httpServer.listen(port, () => {
logger.info('Admin panel listening for HTTP on *'+port)
})
}
private stopWebserver(){
if(this.httpServer == null || this.express == null){
logger.warn("Webserver is not running")
return
}
this.httpServer.close()
this.httpServer = null
this.express = null
logger.info("Webserver stopped")
}
private startWebsocket(){
try{
this.io.attach(this.wsServer)
this.io.on('socket', (socket) => {
logger.info("New Websocket connection on port", socket.port)
const handleError = (e: any) => {
logger.info("Websocket closing", String(e))
socket.close()
}
socket.on('error', handleError)
this.initApis(socket)
})
logger.info('Admin websocket listening on *20000')
this.wsServer.listen(20000)
}catch(e){
logger.error(String(e))
}
}
} }
process.on( 'SIGINT', function() { process.on( 'SIGINT', function() {
+4 -4
View File
@@ -21,11 +21,11 @@ export type NPMVersion = string
export const install = (plugins: Plugin[] = []) => { export const install = (plugins: Plugin[] = []) => {
const npmPkgs = [['sqlite3', '4.1.0'], ['knex', '0.19.2']] const npmPkgs:[NPMPkgName, NPMVersion][] = [['sqlite3', '4.1.0'], ['knex', '0.19.2']]
const deps = npmPkgs.map((pkg) => {return pkg[0] + '@' + pkg[1]} ) const deps = npmPkgs.map(tuple => tuple.join('@') ).join(" ")
logger.info("Checking npm dependencies..." + deps) logger.info("Installing plaform dependencies: "+deps)
exec("npm i --prefix ./plugins " + deps.join(' ')).then(process => { exec("npm i --prefix ./plugins " + deps).then(process => {
logger.debug(process.stdout) logger.debug(process.stdout)
const Admin = require("./Admin").FrontblockAdmin const Admin = require("./Admin").FrontblockAdmin