diff --git a/sample-functions/BaseFunctions/R/Dockerfile b/sample-functions/BaseFunctions/R/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..dd925d8efdc0f0bd8fa0e406543d1f492e15aee2 --- /dev/null +++ b/sample-functions/BaseFunctions/R/Dockerfile @@ -0,0 +1,15 @@ +FROM artemklevtsov/r-alpine:latest + +ADD https://github.com/alexellis/faas/releases/download/0.6.1/fwatchdog /usr/bin +RUN chmod +x /usr/bin/fwatchdog + +WORKDIR /root/ + +COPY handler.R . + +ENV fprocess="Rscript handler.R" + +HEALTHCHECK --interval=1s CMD [ -e /tmp/.lock ] || exit 1 + +CMD ["fwatchdog"] + diff --git a/sample-functions/BaseFunctions/R/README.Rmd b/sample-functions/BaseFunctions/R/README.Rmd new file mode 100644 index 0000000000000000000000000000000000000000..c3c037c6eee1f411385eeae098e97812c5bb7e31 --- /dev/null +++ b/sample-functions/BaseFunctions/R/README.Rmd @@ -0,0 +1,42 @@ +--- +title: "BaseFunction for R" +output: github_document +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = TRUE) +``` + +Use this FaaS function using R. + +**Deploy the base R function** + +(Make sure you have already deployed FaaS with ./deploy_stack.sh in the root of this Github repository. + +* Option 1 - click *Create a new function* on the FaaS UI + +* Option 2 - use the [faas-cli](https://github.com/alexellis/faas-cli/) (experimental) + +``` +# curl -sSL https://get.openfaas.com | sudo sh + +# faas-cli -action=deploy -image=functions/base:R-3.4.1-alpine -name=baser +200 OK +URL: http://localhost:8080/function/baser +``` + +**Say Hi with input** + +`curl` is good to test function. + +``` +$ curl http://localhost:8080/function/baser -d "test" +``` + +**Customize the transformation** + +If you want to customise the transformation then edit the Dockerfile or the fprocess variable and create a new function. + +**Remove the function** + +You can remove the function with `docker service rm baser`. \ No newline at end of file diff --git a/sample-functions/BaseFunctions/R/README.md b/sample-functions/BaseFunctions/R/README.md new file mode 100644 index 0000000000000000000000000000000000000000..ba412ab192709f29daecf1ebfd5885f413a89716 --- /dev/null +++ b/sample-functions/BaseFunctions/R/README.md @@ -0,0 +1,34 @@ +BaseFunction for R +================ + +Use this FaaS function using R. + +**Deploy the base R function** + +(Make sure you have already deployed FaaS with ./deploy\_stack.sh in the root of this Github repository. + +- Option 1 - click *Create a new function* on the FaaS UI + +- Option 2 - use the [faas-cli](https://github.com/alexellis/faas-cli/) (experimental) + +<!-- --> + + # curl -sSL https://get.openfaas.com | sudo sh + + # faas-cli -action=deploy -image=functions/base:R-3.4.1-alpine -name=baser + 200 OK + URL: http://localhost:8080/function/baser + +**Say Hi with input** + +`curl` is good to test function. + + $ curl http://localhost:8080/function/baser -d "test" + +**Customize the transformation** + +If you want to customise the transformation then edit the Dockerfile or the fprocess variable and create a new function. + +**Remove the function** + +You can remove the function with `docker service rm baser`. diff --git a/sample-functions/BaseFunctions/R/build.sh b/sample-functions/BaseFunctions/R/build.sh new file mode 100644 index 0000000000000000000000000000000000000000..b66b0de0c5cf27e03916c1c5d6baf4a53bdd6d2a --- /dev/null +++ b/sample-functions/BaseFunctions/R/build.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +echo "Building functions/base:R-3.4.1-alpine" +docker build -t functions/base:R-3.4.1-alpine . + diff --git a/sample-functions/BaseFunctions/R/handler.R b/sample-functions/BaseFunctions/R/handler.R new file mode 100644 index 0000000000000000000000000000000000000000..65f168ba3dfab5136484860a1b5014335912f36d --- /dev/null +++ b/sample-functions/BaseFunctions/R/handler.R @@ -0,0 +1,7 @@ +#!/usr/bin/env Rscript + +f <- file("stdin") +open(f) +line<-readLines(f, n=1, warn = FALSE) + +write(paste0("Hi ", line), stderr())