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/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"] 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 diff --git a/main.js b/main.js index cc2a883..7d22638 100644 --- a/main.js +++ b/main.js @@ -11,19 +11,53 @@ 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 CM_KEY = process.env.CM_KEY || ''; +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 containers = {}; +//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'; +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'); @@ -112,6 +146,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]); }); @@ -337,6 +373,7 @@ app.get('/store/secret', function (req, res) { }); }); +console.log("starting server",credentials); https.createServer(credentials, app).listen(PORT); module.exports = app; 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",