Skip to content

Commit

Permalink
Merge pull request #28 from me-box/fet/swarm
Browse files Browse the repository at this point in the history
Fet/swarm
  • Loading branch information
Toshbrown authored Jun 7, 2017
2 parents 9caf886 + 0b70d32 commit 01258b6
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ LABEL databox.type="arbiter"
EXPOSE 8080

CMD ["npm","start"]
#CMD ["sleep","99999"]
12 changes: 12 additions & 0 deletions Dockerfile-aarch64
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion Dockerfile-arm → Dockerfile-armv7l
Original file line number Diff line number Diff line change
@@ -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
Expand Down
53 changes: 45 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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]);
});
Expand Down Expand Up @@ -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;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 01258b6

Please sign in to comment.