mirror of
https://github.com/openfaas/faas.git
synced 2025-06-15 11:46:46 +00:00
Add NodeBase function concept
This commit is contained in:
parent
8a53bacef2
commit
85a2fe8573
18
sample-functions/NodeBaseFunction/Dockerfile
Normal file
18
sample-functions/NodeBaseFunction/Dockerfile
Normal 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"]
|
5
sample-functions/NodeBaseFunction/build.sh
Executable file
5
sample-functions/NodeBaseFunction/build.sh
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "Building functions/nodebase:alpine-6.9.1"
|
||||||
|
docker build -t functions/nodebase:alpine-6.9.1 .
|
||||||
|
|
29
sample-functions/NodeBaseFunction/faas_index.js
Normal file
29
sample-functions/NodeBaseFunction/faas_index.js
Normal 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);
|
||||||
|
});
|
15
sample-functions/NodeBaseFunction/package.json
Normal file
15
sample-functions/NodeBaseFunction/package.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
3
sample-functions/NodeInfo/Dockerfile.func
Normal file
3
sample-functions/NodeInfo/Dockerfile.func
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
FROM functions/nodebase:alpine-6.9.1
|
||||||
|
|
||||||
|
COPY handler.js .
|
3
sample-functions/NodeInfo/build.func.sh
Executable file
3
sample-functions/NodeInfo/build.func.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
docker build -t functions/nodeinfo:func . -f Dockerfile.func
|
23
sample-functions/NodeInfo/handler.js
Normal file
23
sample-functions/NodeInfo/handler.js
Normal 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);
|
||||||
|
});
|
||||||
|
};
|
@ -1 +0,0 @@
|
|||||||
docker build -t nodeinfo . ; docker service rm NodeInfo ; docker service create --network=functions --name NodeInfo nodeinfo
|
|
Loading…
x
Reference in New Issue
Block a user