mirror of
https://github.com/openfaas/faas.git
synced 2025-06-19 12:36:40 +00:00
Light-weight examples for HelloWorld - for on reading an input/request.
This commit is contained in:
12
sample-functions/BaseFunctions/README.md
Normal file
12
sample-functions/BaseFunctions/README.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
## Base function examples
|
||||||
|
|
||||||
|
Examples of base functions are provided here.
|
||||||
|
|
||||||
|
Each one will read the request from the watchdog then print it back resulting in an HTTP 200.
|
||||||
|
|
||||||
|
| Language | Docker image | Notes |
|
||||||
|
|------------------------|------------------------------------|----------------------------------------|
|
||||||
|
| Node.js | functions/node:6.9.1-alpine | Node.js built on Alpine Linux |
|
||||||
|
| Python | functions/python:2.7-alpine | Python 2.7 built on Alpine Linux |
|
||||||
|
| Java | functions/openjdk:8u121-jdk-alpine | OpenJDK built on Alpine Linux |
|
||||||
|
| Busybox / shell | functions/alpine:latest | Busybox contains useful binaries which can be turned into a FaaS function such as `sha512sum` or `cat` |
|
1
sample-functions/BaseFunctions/java/.gitignore
vendored
Normal file
1
sample-functions/BaseFunctions/java/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.class
|
16
sample-functions/BaseFunctions/java/Dockerfile
Normal file
16
sample-functions/BaseFunctions/java/Dockerfile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
FROM openjdk:8u121-jdk-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 Handler.java .
|
||||||
|
RUN javac Handler.java
|
||||||
|
|
||||||
|
ENV fprocess="java Handler"
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=1s CMD [ -e /tmp/.lock ] || exit 1
|
||||||
|
|
||||||
|
CMD ["fwatchdog"]
|
||||||
|
|
30
sample-functions/BaseFunctions/java/Handler.java
Normal file
30
sample-functions/BaseFunctions/java/Handler.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
public class Handler {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
String input = readStdin();
|
||||||
|
System.out.print(input);
|
||||||
|
|
||||||
|
} catch(IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String readStdin() throws IOException {
|
||||||
|
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||||
|
String input = "";
|
||||||
|
while(true) {
|
||||||
|
String line = br.readLine();
|
||||||
|
if(line==null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
input = input + line + "\n";
|
||||||
|
}
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
}
|
4
sample-functions/BaseFunctions/java/build.sh
Executable file
4
sample-functions/BaseFunctions/java/build.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "Building functions/openjdk:8u121-jdk-alpine"
|
||||||
|
docker build -t functions/openjdk:8u121-jdk-alpine .
|
18
sample-functions/BaseFunctions/node/Dockerfile
Normal file
18
sample-functions/BaseFunctions/node/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 .
|
||||||
|
|
||||||
|
RUN npm i
|
||||||
|
COPY handler.js .
|
||||||
|
|
||||||
|
ENV fprocess="node handler.js"
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=1s CMD [ -e /tmp/.lock ] || exit 1
|
||||||
|
|
||||||
|
CMD ["fwatchdog"]
|
||||||
|
|
5
sample-functions/BaseFunctions/node/build.sh
Executable file
5
sample-functions/BaseFunctions/node/build.sh
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "Building functions/node:6.9.1-alpine"
|
||||||
|
docker build -t functions/node:6.9.1-alpine .
|
||||||
|
|
15
sample-functions/BaseFunctions/node/handler.js
Normal file
15
sample-functions/BaseFunctions/node/handler.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
"use strict"
|
||||||
|
|
||||||
|
let getStdin = require('get-stdin');
|
||||||
|
|
||||||
|
let handler = require('./handler');
|
||||||
|
|
||||||
|
let handle = (req) => {
|
||||||
|
console.log(req);
|
||||||
|
};
|
||||||
|
|
||||||
|
getStdin().then(val => {
|
||||||
|
handle(val);
|
||||||
|
}).catch(e => {
|
||||||
|
console.error(e.stack);
|
||||||
|
});
|
15
sample-functions/BaseFunctions/node/package.json
Normal file
15
sample-functions/BaseFunctions/node/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"
|
||||||
|
}
|
||||||
|
}
|
15
sample-functions/BaseFunctions/python/Dockerfile
Normal file
15
sample-functions/BaseFunctions/python/Dockerfile
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
FROM python:2.7-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 handler.py .
|
||||||
|
|
||||||
|
ENV fprocess="python handler.py"
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=1s CMD [ -e /tmp/.lock ] || exit 1
|
||||||
|
|
||||||
|
CMD ["fwatchdog"]
|
||||||
|
|
5
sample-functions/BaseFunctions/python/build.sh
Executable file
5
sample-functions/BaseFunctions/python/build.sh
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "Building functions/python:2.7-alpine"
|
||||||
|
docker build -t functions/python:2.7-alpine .
|
||||||
|
|
11
sample-functions/BaseFunctions/python/handler.py
Normal file
11
sample-functions/BaseFunctions/python/handler.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
def get_stdin():
|
||||||
|
buf = ""
|
||||||
|
for line in sys.stdin:
|
||||||
|
buf = buf + line
|
||||||
|
return buf
|
||||||
|
|
||||||
|
if(__name__ == "__main__"):
|
||||||
|
st = get_stdin()
|
||||||
|
print(st)
|
Reference in New Issue
Block a user