Skip to content
Snippets Groups Projects
Commit 85a2fe85 authored by Alex Ellis's avatar Alex Ellis
Browse files

Add NodeBase function concept

parent 8a53bace
No related branches found
No related tags found
No related merge requests found
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"]
#!/bin/sh
echo "Building functions/nodebase:alpine-6.9.1"
docker build -t functions/nodebase:alpine-6.9.1 .
"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);
});
{
"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"
}
}
FROM functions/nodebase:alpine-6.9.1
COPY handler.js .
#!/bin/bash
docker build -t functions/nodeinfo:func . -f Dockerfile.func
'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);
});
};
docker build -t nodeinfo . ; docker service rm NodeInfo ; docker service create --network=functions --name NodeInfo nodeinfo
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment