diff --git a/Dockerfile b/Dockerfile index decbf32..80162d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,7 @@ FROM node:alpine RUN apk add git WORKDIR /service -COPY dist /service/dist -COPY node_modules /service/node_modules +RUN git clone https://gitea.frontblock.me/fb-dist/admin.git dist EXPOSE 8080 20000 ENTRYPOINT ["node", "dist/FrontblockAdmin.js"] \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 3d7edb5..959cc22 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2123,13 +2123,14 @@ } }, "frontblock-generic": { - "version": "0.30.3", - "resolved": "https://registry.npmjs.org/frontblock-generic/-/frontblock-generic-0.30.3.tgz", - "integrity": "sha512-RvgGaG2Bx9AaCVssu9/ZPGCCWg9FCwMFEa+6ZRyNNPvddh5smE5Yo+59KWDMUHKpMkV25HF6JR6Tl9YwQ82z5Q==", + "version": "0.30.6", + "resolved": "https://registry.npmjs.org/frontblock-generic/-/frontblock-generic-0.30.6.tgz", + "integrity": "sha512-ecOwcLpzPuAOThKhIdbdXQm7M7HnF6dtNf1dOr7pxFfkBq5T5h/wxT2mdlC3rUd1HqdKxwrUjqG+1XqKjwVY4g==", "requires": { "@types/lowdb": "^1.0.9", "@types/node": "^12.7.1", "bsock": "^0.1.9", + "express": "^4.17.1", "fs": "0.0.1-security", "http": "0.0.0", "key-file-storage": "^2.2.4", diff --git a/package.json b/package.json index 68044ff..ce158b5 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,8 @@ "start": "npm run build; node dist/FrontblockAdmin.js", "build": "npm run clean; npm run build-backend; npm run build-frontend", "build-backend": "tsc; npm run webpack", - "build-frontend": "npm run build-dashboard; cp ./dist/FrontblockLib.js ./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-widget": "rollup -c src/frontend/widget/rollup.config.js; mkdir -p plugins/PluginManager; cp FrontendPlugin.js plugins/PluginManager", + "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 ../../dist/static; cp -r dist/* ../../dist/static", "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", "webpack": "webpack --config src/backend/webpack.prod.js --progress --colors" @@ -27,7 +26,7 @@ "debug": "^4.1.1", "express": "^4.16.4", "frontblock": "^0.14.0", - "frontblock-generic": "^0.30.3", + "frontblock-generic": "^0.30.6", "git-cherrypicker": "0.0.3", "git-describe": "^4.0.4", "http": "0.0.0", diff --git a/src/backend/Admin.ts b/src/backend/Admin.ts index 0673e26..6effa21 100644 --- a/src/backend/Admin.ts +++ b/src/backend/Admin.ts @@ -4,16 +4,11 @@ import * as Logger from 'log4js' import * as Knex from 'knex' import { FrontblockApiClient, FrontblockApiConf } from 'frontblock'; 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 { Plugin } from 'frontblock-generic/Plugin'; import { socketioRPC } from 'frontblock-generic/RPC'; import { GitUpdater } from './GitUpdater'; -var exec = require('child-process-promise').exec; +import { UpdateManager } from './UpdateManger'; Logger.configure({ appenders: @@ -33,14 +28,9 @@ export type AdminConf = { httpPort: number} export class FrontblockAdmin extends AdminBase{ - private express - private httpServer - private io = bsock.createServer() - private wsServer = http.createServer() - constructor(runningPlugins: Plugin[] = []){ super(runningPlugins) - this.initialize() + this.addPlugin(new UpdateManager(this)) } getDefaultConfig(): { apiConf: FrontblockApiConf; } & AdminConf & { dbConf:Knex.Config; } { @@ -72,16 +62,6 @@ export class FrontblockAdmin extends AdminBase{ return this.apiClient } - private initialize(){ - this.startWebserver() - this.startWebsocket() - } - - private destroy(){ - this.wsServer.close() - this.stopWebserver() - } - exportRPCs():socketioRPC[]{ return [ ...super.exportRPCs(), @@ -107,90 +87,10 @@ export class FrontblockAdmin extends AdminBase{ } 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() { logger.info( "Gracefully shutting down from SIGINT (Ctrl-C)" ); // some other closing procedures go here process.exit( ); - }) \ No newline at end of file +}) \ No newline at end of file diff --git a/src/backend/Installer.ts b/src/backend/Installer.ts index 3683098..ad9743c 100644 --- a/src/backend/Installer.ts +++ b/src/backend/Installer.ts @@ -21,11 +21,11 @@ export type NPMVersion = string export const install = (plugins: Plugin[] = []) => { - const npmPkgs = [['sqlite3', '4.1.0'], ['knex', '0.19.2']] - const deps = npmPkgs.map((pkg) => {return pkg[0] + '@' + pkg[1]} ) - logger.info("Checking npm dependencies..." + deps) + const npmPkgs:[NPMPkgName, NPMVersion][] = [['sqlite3', '4.1.0'], ['knex', '0.19.2']] + const deps = npmPkgs.map(tuple => tuple.join('@') ).join(" ") + 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) const Admin = require("./Admin").FrontblockAdmin