Add NodeBase function concept

This commit is contained in:
Alex Ellis 2017-04-06 13:19:09 +01:00
parent 8a53bacef2
commit 85a2fe8573
8 changed files with 96 additions and 1 deletions

View File

@ -0,0 +1,18 @@
FROM node:6.9.1-alpine
ADD https://github.com/alexellis/faas/releases/download/0.5.1-alpha/fwatchdog /usr/bin
RUN chmod +x /usr/bin/fwatchdog
WORKDIR /root/
COPY package.json .
# Provides a boot-strap into your function, just add handler.js to derived image
RUN npm i
COPY faas_index.js .
ENV fprocess="node faas_index.js"
HEALTHCHECK --interval=5s CMD [ -e /tmp/.lock ] || exit 1
CMD ["fwatchdog"]

View File

@ -0,0 +1,5 @@
#!/bin/sh
echo "Building functions/nodebase:alpine-6.9.1"
docker build -t functions/nodebase:alpine-6.9.1 .

View File

@ -0,0 +1,29 @@
"use strict"
let getStdin = require('get-stdin');
let handler = require('./handler');
getStdin().then(val => {
let req;
if(process.env.json) {
req = JSON.parse(val);
} else {
req = val
}
handler(req, (err, res) => {
if(err) {
return console.error(err);
}
if(process.env.json) {
console.log(JSON.stringify(res));
} else {
console.log(res);
}
});
}).catch(e => {
console.error(e.stack);
});

View File

@ -0,0 +1,15 @@
{
"name": "NodejsBase",
"version": "1.0.0",
"description": "",
"main": "faas_index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"get-stdin": "^5.0.1"
}
}

View File

@ -0,0 +1,3 @@
FROM functions/nodebase:alpine-6.9.1
COPY handler.js .

View File

@ -0,0 +1,3 @@
#!/bin/bash
docker build -t functions/nodeinfo:func . -f Dockerfile.func

View File

@ -0,0 +1,23 @@
'use strict'
let os = require('os');
let fs = require('fs');
let util = require('util');
module.exports = (content, callback) => {
fs.readFile("/etc/hostname", "utf8", (err, data) => {
let val = "";
val += "Hostname: " + data +"\n";
val += "Platform: " + os.platform()+"\n";
val += "Arch: " + os.arch() + "\n";
val += "CPU count: " + os.cpus().length+ "\n";
val += "Uptime: " + os.uptime()+ "\n";
if (content && content.length && content.indexOf("verbose") > -1) {
val += util.inspect(os.cpus()) + "\n";
val += util.inspect(os.networkInterfaces())+ "\n";
}
callback(null, val);
});
};

View File

@ -1 +0,0 @@
docker build -t nodeinfo . ; docker service rm NodeInfo ; docker service create --network=functions --name NodeInfo nodeinfo