Browse Source

self update and serve static/dist

master
peter 2 years ago
parent
commit
997ae629b6
5 changed files with 15 additions and 116 deletions
  1. 1
    2
      Dockerfile
  2. 4
    3
      package-lock.json
  3. 3
    4
      package.json
  4. 3
    103
      src/backend/Admin.ts
  5. 4
    4
      src/backend/Installer.ts

+ 1
- 2
Dockerfile View File

@@ -2,8 +2,7 @@ FROM node:alpine
2 2
 RUN apk add git 
3 3
 
4 4
 WORKDIR /service 
5
-COPY dist /service/dist
6
-COPY node_modules /service/node_modules
5
+RUN git clone https://gitea.frontblock.me/fb-dist/admin.git dist
7 6
 
8 7
 EXPOSE 8080 20000
9 8
 ENTRYPOINT ["node", "dist/FrontblockAdmin.js"]

+ 4
- 3
package-lock.json View File

@@ -2123,13 +2123,14 @@
2123 2123
       }
2124 2124
     },
2125 2125
     "frontblock-generic": {
2126
-      "version": "0.30.3",
2127
-      "resolved": "https://registry.npmjs.org/frontblock-generic/-/frontblock-generic-0.30.3.tgz",
2128
-      "integrity": "sha512-RvgGaG2Bx9AaCVssu9/ZPGCCWg9FCwMFEa+6ZRyNNPvddh5smE5Yo+59KWDMUHKpMkV25HF6JR6Tl9YwQ82z5Q==",
2126
+      "version": "0.30.6",
2127
+      "resolved": "https://registry.npmjs.org/frontblock-generic/-/frontblock-generic-0.30.6.tgz",
2128
+      "integrity": "sha512-ecOwcLpzPuAOThKhIdbdXQm7M7HnF6dtNf1dOr7pxFfkBq5T5h/wxT2mdlC3rUd1HqdKxwrUjqG+1XqKjwVY4g==",
2129 2129
       "requires": {
2130 2130
         "@types/lowdb": "^1.0.9",
2131 2131
         "@types/node": "^12.7.1",
2132 2132
         "bsock": "^0.1.9",
2133
+        "express": "^4.17.1",
2133 2134
         "fs": "0.0.1-security",
2134 2135
         "http": "0.0.0",
2135 2136
         "key-file-storage": "^2.2.4",

+ 3
- 4
package.json View File

@@ -7,9 +7,8 @@
7 7
     "start": "npm run build; node dist/FrontblockAdmin.js",
8 8
     "build": "npm run clean; npm run build-backend; npm run build-frontend",
9 9
     "build-backend": "tsc; npm run webpack",
10
-    "build-frontend": "npm run build-dashboard; cp ./dist/FrontblockLib.js ./static",
11
-    "build-dashboard": "git submodule init && git submodule update --merge; cd src/frontend; npm i && npm run build; mkdir ../../static; cp -r dist/* ../../static",
12
-    "build-widget": "rollup -c src/frontend/widget/rollup.config.js; mkdir -p plugins/PluginManager; cp FrontendPlugin.js plugins/PluginManager",
10
+    "build-frontend": "npm run build-dashboard; cp ./dist/FrontblockLib.js ./dist/static",
11
+    "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",
13 12
     "clean": "rm -rf lib static plugins conf dist widget .rpt2_cache *.js *.ts src/frontend/dist",
14 13
     "update-frontblock": "rm -rf node_modules/frontblock*; npm install",
15 14
     "webpack": "webpack  --config src/backend/webpack.prod.js --progress --colors"
@@ -27,7 +26,7 @@
27 26
     "debug": "^4.1.1",
28 27
     "express": "^4.16.4",
29 28
     "frontblock": "^0.14.0",
30
-    "frontblock-generic": "^0.30.3",
29
+    "frontblock-generic": "^0.30.6",
31 30
     "git-cherrypicker": "0.0.3",
32 31
     "git-describe": "^4.0.4",
33 32
     "http": "0.0.0",

+ 3
- 103
src/backend/Admin.ts View File

@@ -4,16 +4,11 @@ import * as Logger from 'log4js'
4 4
 import * as Knex from 'knex'
5 5
 import { FrontblockApiClient, FrontblockApiConf } from 'frontblock';
6 6
 import { AdminBase } from 'frontblock-generic/Admin';
7
-import express = require('express');
8
-import http = require('http');
9
-import bsock = require('bsock');
10
-import { promises as fs } from "fs"
11
-import * as path from "path"
12 7
 import { FrontblockApi } from 'frontblock-generic/Api';
13 8
 import { Plugin } from 'frontblock-generic/Plugin';
14 9
 import { socketioRPC } from 'frontblock-generic/RPC';
15 10
 import { GitUpdater } from './GitUpdater';
16
-var exec = require('child-process-promise').exec;
11
+import { UpdateManager } from './UpdateManger';
17 12
 
18 13
 Logger.configure({
19 14
     appenders: 
@@ -33,14 +28,9 @@ export type AdminConf = { httpPort: number}
33 28
 
34 29
 export class FrontblockAdmin extends AdminBase<AdminConf>{
35 30
    
36
-    private express
37
-    private httpServer
38
-    private io = bsock.createServer()
39
-    private wsServer = http.createServer()
40
-
41 31
     constructor(runningPlugins: Plugin[] = []){
42 32
         super(runningPlugins)
43
-        this.initialize()
33
+        this.addPlugin(new UpdateManager(this))
44 34
     }
45 35
 
46 36
     getDefaultConfig(): { apiConf: FrontblockApiConf; } & AdminConf & { dbConf:Knex.Config; } {
@@ -72,16 +62,6 @@ export class FrontblockAdmin extends AdminBase<AdminConf>{
72 62
         return this.apiClient    
73 63
     }
74 64
 
75
-    private initialize(){
76
-        this.startWebserver()
77
-        this.startWebsocket()
78
-    }
79
-
80
-    private destroy(){
81
-        this.wsServer.close()
82
-        this.stopWebserver()
83
-    }
84
-
85 65
     exportRPCs():socketioRPC[]{
86 66
         return [
87 67
             ...super.exportRPCs(),
@@ -107,90 +87,10 @@ export class FrontblockAdmin extends AdminBase<AdminConf>{
107 87
         }
108 88
         return status
109 89
     }
110
-
111
-    private startWebserver(){
112
-        if(this.httpServer != null || this.express != null){
113
-            logger.warn("Webserver is already running")
114
-            return
115
-        }
116
-        
117
-        let port:number = this.getConfig().httpPort
118
-        this.express = express()
119
-        this.express.use('/', express.static('static'))
120
-
121
-        /**
122
-         * get the compiled FrontendPlugins.js
123
-         */
124
-        this.express.get('/plugins/:id'+".js", async (request, response) => {
125
-            const pth = path.resolve("plugins/"+request.params.id, "FrontendPlugin.js");
126
-            const file = await fs.readFile(pth)
127
-            const frontend = file.toString()
128
-
129
-            response.status(200)
130
-            response.set('Content-Type', 'application/javascript')
131
-            response.send(frontend)
132
-        })
133
-
134
-        /**
135
-         * serve the index.html from the static folder
136
-         */
137
-        this.express.get("/", (request, response) => {
138
-            response.status(200)
139
-            response.sendFile('index.html');
140
-        })
141
-
142
-        /**
143
-         * redirect all the other traffic to the single
144
-         * page app to the main entry point from where
145
-         * a webpacked and rolled up index.html is serverd
146
-         * and angular takes over routing
147
-         */
148
-        this.express.get("*", (request, response) => {
149
-            response.status(301)
150
-            response.redirect('/')
151
-        })
152
-
153
-        this.httpServer = new http.Server(this.express)
154
-        this.httpServer.listen(port, () => {
155
-            logger.info('Admin panel listening for HTTP on *'+port)
156
-        })
157
-    }
158
-
159
-    private stopWebserver(){
160
-        if(this.httpServer == null || this.express == null){
161
-            logger.warn("Webserver is not running")
162
-            return
163
-        }
164
-        this.httpServer.close()
165
-        this.httpServer = null
166
-        this.express = null
167
-        logger.info("Webserver stopped")
168
-    }
169
-
170
-    private startWebsocket(){
171
-        try{
172
-            this.io.attach(this.wsServer)
173
-            this.io.on('socket', (socket) => {
174
-                logger.info("New Websocket connection on port", socket.port)
175
-
176
-                const handleError = (e: any) => {
177
-                    logger.info("Websocket closing", String(e))
178
-                    socket.close()
179
-                }
180
-                
181
-                socket.on('error', handleError)
182
-                this.initApis(socket)
183
-            })
184
-            logger.info('Admin websocket listening on *20000')
185
-            this.wsServer.listen(20000)
186
-        }catch(e){
187
-            logger.error(String(e))
188
-        }
189
-    }
190 90
 }
191 91
 
192 92
 process.on( 'SIGINT', function() {
193 93
     logger.info( "Gracefully shutting down from SIGINT (Ctrl-C)" );
194 94
     // some other closing procedures go here
195 95
     process.exit( );
196
-  })
96
+})

+ 4
- 4
src/backend/Installer.ts View File

@@ -21,11 +21,11 @@ export type NPMVersion = string
21 21
 
22 22
 export const install = (plugins: Plugin[] = []) => {
23 23
     
24
-    const npmPkgs = [['sqlite3', '4.1.0'], ['knex', '0.19.2']]
25
-    const deps = npmPkgs.map((pkg) => {return pkg[0] + '@' + pkg[1]} )
26
-    logger.info("Checking npm dependencies..." + deps)
24
+    const npmPkgs:[NPMPkgName, NPMVersion][] = [['sqlite3', '4.1.0'], ['knex', '0.19.2']]
25
+    const deps = npmPkgs.map(tuple => tuple.join('@') ).join(" ")
26
+    logger.info("Installing plaform dependencies: "+deps)
27 27
 
28
-    exec("npm i --prefix ./plugins " + deps.join(' ')).then(process => {
28
+    exec("npm i --prefix ./plugins " + deps).then(process => {
29 29
     
30 30
         logger.debug(process.stdout)    
31 31
         const Admin = require("./Admin").FrontblockAdmin

Loading…
Cancel
Save