From a9f1d2009e91eae29782387c301563f230ff5149 Mon Sep 17 00:00:00 2001 From: ToshBrown Date: Tue, 16 May 2017 15:00:30 +0100 Subject: [PATCH 1/5] Chenges for moving to swarm mode --- Dockerfile | 1 + main.js | 26 +++++++++++++++++++------- package.json | 1 + 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 549ae22..cae5c5c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,3 +9,4 @@ LABEL databox.type="arbiter" EXPOSE 8080 CMD ["npm","start"] +#CMD ["sleep","99999"] diff --git a/main.js b/main.js index cc2a883..7e726ed 100644 --- a/main.js +++ b/main.js @@ -11,19 +11,31 @@ var baseCat = require('./base-cat.json'); var PORT = process.env.PORT || 8080; -var HTTPS_SERVER_CERT = process.env.HTTPS_SERVER_CERT || ''; -var HTTPS_SERVER_PRIVATE_KEY = process.env.HTTPS_SERVER_PRIVATE_KEY || ''; +var HTTPS_SECRETS = JSON.parse(fs.readFileSync("/run/secrets/DATABOX_ARBITER_PEM.json") || {}); +var credentials = { + key: HTTPS_SECRETS.clientprivate || '', + cert: HTTPS_SECRETS.clientcert || '', +}; -var CM_KEY = process.env.CM_KEY || ''; +var CM_KEY = fs.readFileSync("/run/secrets/CM_KEY",{encoding:'base64'}); +var LOGSTORE_KEY = fs.readFileSync("/run/secrets/DATABOX_LOGSTORE_KEY",{encoding:'base64'}); +var EXPORT_SERVICE_KEY = fs.readFileSync("/run/secrets/DATABOX_EXPORT_SERVICE_KEY",{encoding:'base64'}); var containers = {}; +//register the datbox logstore +containers['databox-logstore'] = {}; +containers['databox-logstore']['key'] = LOGSTORE_KEY; +containers['databox-logstore']['name'] = 'databox-logstore'; +containers['databox-logstore']['type'] = 'databox-logstore'; +containers['databox-export-service'] = {}; +containers['databox-export-service']['key'] = EXPORT_SERVICE_KEY; +containers['databox-export-service']['name'] = 'databox-export-service'; +containers['databox-export-service']['type'] = 'databox-export-service'; + var app = express(); -var credentials = { - key: HTTPS_SERVER_PRIVATE_KEY, - cert: HTTPS_SERVER_CERT, -}; + // TODO: Check app.enable('trust proxy'); diff --git a/package.json b/package.json index 2d63d64..ffda40b 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "dependencies": { "basic-auth": "^1.1.0", "body-parser": "^1.14.2", + "chokidar": "^1.7.0", "crypto": "0.0.3", "express": "^4.13.4", "macaroons.js": "^0.3.6", From 6137cbb6b918e464f691cd18a2ae4e8a21d39f17 Mon Sep 17 00:00:00 2001 From: ToshBrown Date: Fri, 19 May 2017 14:03:49 +0100 Subject: [PATCH 2/5] Register the CM at startup --- main.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 7e726ed..c9b3217 100644 --- a/main.js +++ b/main.js @@ -23,7 +23,11 @@ var LOGSTORE_KEY = fs.readFileSync("/run/secrets/DATABOX_LOGSTORE_KEY",{encoding var EXPORT_SERVICE_KEY = fs.readFileSync("/run/secrets/DATABOX_EXPORT_SERVICE_KEY",{encoding:'base64'}); var containers = {}; -//register the datbox logstore +//register the databox platform components +containers['databox-container-manager'] = {}; +containers['databox-container-manager']['key'] = CM_KEY; +containers['databox-container-manager']['name'] = 'databox-container-manager'; +containers['databox-container-manager']['type'] = 'CM'; containers['databox-logstore'] = {}; containers['databox-logstore']['key'] = LOGSTORE_KEY; containers['databox-logstore']['name'] = 'databox-logstore'; @@ -124,6 +128,8 @@ app.post('/cm/upsert-container-info', function (req, res) { // TODO: Restrict POSTed data to namespace (else can overwrite catItem) for(var key in data) containers[data.name][key] = data[key]; + + console.log("New container registered",data.name, data.key); res.json(containers[data.name]); }); From 50a8dc7346144be8d50c9e01c684f9e67d533fb9 Mon Sep 17 00:00:00 2001 From: ToshBrown Date: Mon, 22 May 2017 09:39:46 +0000 Subject: [PATCH 3/5] aarch64 support --- Dockerfile-aarch64 | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Dockerfile-aarch64 diff --git a/Dockerfile-aarch64 b/Dockerfile-aarch64 new file mode 100644 index 0000000..c94d36b --- /dev/null +++ b/Dockerfile-aarch64 @@ -0,0 +1,12 @@ +FROM forumi0721alpineaarch64/alpine-aarch64-nodejs + +ADD package.json package.json +RUN npm install +ADD . . + +LABEL databox.type="arbiter" + +EXPOSE 8080 + +CMD ["npm","start"] +#CMD ["sleep","99999"] From c1c5fbba5bdaeaf6234980aacc74d73a66fd72e5 Mon Sep 17 00:00:00 2001 From: ToshBrown Date: Mon, 22 May 2017 13:29:06 +0000 Subject: [PATCH 4/5] armv7l support --- Dockerfile-arm => Dockerfile-armv7l | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Dockerfile-arm => Dockerfile-armv7l (83%) diff --git a/Dockerfile-arm b/Dockerfile-armv7l similarity index 83% rename from Dockerfile-arm rename to Dockerfile-armv7l index f1a3181..e0d2bbd 100644 --- a/Dockerfile-arm +++ b/Dockerfile-armv7l @@ -1,4 +1,4 @@ -FROM hypriot/rpi-node:slim +FROM armhf/node:7.9.0 ADD package.json package.json RUN npm install && npm run clean From 0b70d3275b8d80998736e7a3af6473c027561aea Mon Sep 17 00:00:00 2001 From: ToshBrown Date: Wed, 7 Jun 2017 12:16:19 +0100 Subject: [PATCH 5/5] Fix tests? --- main.js | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/main.js b/main.js index c9b3217..7d22638 100644 --- a/main.js +++ b/main.js @@ -11,16 +11,34 @@ var baseCat = require('./base-cat.json'); var PORT = process.env.PORT || 8080; -var HTTPS_SECRETS = JSON.parse(fs.readFileSync("/run/secrets/DATABOX_ARBITER_PEM.json") || {}); -var credentials = { - key: HTTPS_SECRETS.clientprivate || '', - cert: HTTPS_SECRETS.clientcert || '', -}; - -var CM_KEY = fs.readFileSync("/run/secrets/CM_KEY",{encoding:'base64'}); +let CM_KEY = ''; +let HTTPS_SECRETS = ''; +let LOGSTORE_KEY = ''; +let EXPORT_SERVICE_KEY = '' +let credentials = {}; + +try { + //const ARBITER_KEY = process.env.ARBITER_TOKEN; + CM_KEY = fs.readFileSync("/run/secrets/CM_KEY",{encoding:'base64'}); + LOGSTORE_KEY = fs.readFileSync("/run/secrets/DATABOX_LOGSTORE_KEY",{encoding:'base64'}); + EXPORT_SERVICE_KEY = fs.readFileSync("/run/secrets/DATABOX_EXPORT_SERVICE_KEY",{encoding:'base64'}); + + //HTTPS certs created by the container mangers for this components HTTPS server. + HTTPS_SECRETS = JSON.parse( fs.readFileSync("/run/secrets/DATABOX_ARBITER_PEM.json") ); + credentials = { + key: HTTPS_SECRETS.clientprivate || '', + cert: HTTPS_SECRETS.clientcert || '', + }; +} catch (e) { + //secrets missing ;-( + console.log("secrets missing ;-(",e); + CM_KEY = process.env.CM_KEY || ''; //make the tests work + HTTPS_SECRETS = ''; + LOGSTORE_KEY = ''; + EXPORT_SERVICE_KEY = '' + credentials = {}; +} -var LOGSTORE_KEY = fs.readFileSync("/run/secrets/DATABOX_LOGSTORE_KEY",{encoding:'base64'}); -var EXPORT_SERVICE_KEY = fs.readFileSync("/run/secrets/DATABOX_EXPORT_SERVICE_KEY",{encoding:'base64'}); var containers = {}; //register the databox platform components @@ -355,6 +373,7 @@ app.get('/store/secret', function (req, res) { }); }); +console.log("starting server",credentials); https.createServer(credentials, app).listen(PORT); module.exports = app;