Git Product home page Git Product logo

templates's Introduction

OpenFaaS Classic templates

Build Status

To find out more about the OpenFaaS templates see the faas-cli.

Note: The templates are completely customizable - so if you want to alter them please do fork them and use faas template pull to make use of your updated versions.

Classic Templates

This repository contains the Classic OpenFaaS templates, but many more are available in the Template Store.

Most of the original Classic Templates are retained or backwards compatibility, but are deprecated.

See: faas-cli template store list to see which templates are both: recommended and official for the language you wish to use.

Name Language Version Linux base Watchdog Link
dockerfile Dockerfile N/A Alpine Linux classic Dockerfile template
go Go 1.22 Alpine Linux classic Legacy Go template (deprecated)
node14 NodeJS 14 Alpine Linux of-watchdog NodeJS template (deprecated)
node16 NodeJS 16 Alpine Linux of-watchdog NodeJS template (deprecated)
node17 NodeJS 17 Alpine Linux of-watchdog NodeJS template (deprecated)
node18 NodeJS 18 Alpine Linux of-watchdog NodeJS template (deprecated)
node20 NodeJS 20 Alpine Linux of-watchdog NodeJS template
bun-express Bun 1.0 Alpine Linux of-watchdog NodeJS template
node NodeJS 20 Alpine Linux classic Legacy NodeJS template (deprecated)
python3 Python 3 Alpine Linux classic Legacy Python 3 template
python3-debian Python 3 Debian Linux classic Legacy Python 3 Debian template
python27 Python 2.7.18 Alpine Linux classic Python 2.7 template (deprecated)
java11-vert-x Java and Vert.x 11 Debian GNU/Linux of-watchdog Java LTS template
java11 Java 11 Debian GNU/Linux of-watchdog Java LTS template
ruby Ruby 2.7 Alpine Linux classic Ruby template
php7 PHP 7.4 Alpine Linux classic PHP 7 template
php8 PHP 8.2 Alpine Linux classic PHP 8 template
csharp C# N/A Debian GNU/Linux 9 classic Legacy C# template (deprecated)

For more information on the templates check out the docs.

Classic vs of-watchdog templates

The current version of OpenFaaS templates use the original watchdog which forks processes - a bit like CGI. The newer watchdog of-watchdog is more similar to fastCGI/HTTP and should be used for any benchmarking or performance testing along with one of the newer templates. Contact the project for more information.

Submit your own template to the template store

This repository is for templates supported by the project maintainers, if you'd like to submit your own template to the OpenFaaS Template Store then checkout the store:

Contribute to this repository

See contributing guide.

License

This project is part of the OpenFaaS project licensed under the MIT License.

templates's People

Contributors

alexellis avatar andrew-s avatar burtonr avatar codecutteruk avatar dergoegge avatar imumesh18 avatar itscaro avatar ivanayov avatar johnmccabe avatar kwojcicki avatar lucasroesler avatar martindekov avatar mattnelson avatar meacu1pa avatar moqimoqidea avatar nitishkumar71 avatar omerzamir avatar padiazg avatar rdimitrov avatar rgee0 avatar richierich1610 avatar roncrivera avatar rosskevin avatar spekulatius avatar tpei avatar utsavanand2 avatar viveksyngh avatar waterdrips avatar welteki avatar zeerorg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

templates's Issues

Proxy settings for java8 template

Gradle needs proxy options to be specified explicitly, ignores http_proxy, https_proxy and no_proxy environment variables.

Expected Behaviour

Grable run the build successfully

Step 9/24 : RUN gradle build
 ---> Running in 0f347861cbc9

Welcome to Gradle 4.8.1!

...

Download https://jcenter.bintray.com/com/google/guava/guava/23.0/guava-23.0.pom
...
> Task :model:compileJava

Download ...
...

> Task :function:compileJava
> Task :entrypoint:compileJava
> Task :entrypoint:processResources NO-SOURCE
> Task :entrypoint:classes
> Task :entrypoint:jar
> Task :entrypoint:startScripts
> Task :function:processResources NO-SOURCE
> Task :function:classes
> Task :function:jar
> Task :model:processResources NO-SOURCE
> Task :model:classes
> Task :model:jar
> Task :entrypoint:distTar
> Task :entrypoint:distZip
> Task :entrypoint:assemble
Download ...
> Task :entrypoint:compileTestJava
> Task :entrypoint:processTestResources NO-SOURCE
> Task :entrypoint:testClasses
> Task :entrypoint:test NO-SOURCE
> Task :entrypoint:check UP-TO-DATE
> Task :entrypoint:build
> Task :function:assemble
> Task :function:compileTestJava
> Task :function:processTestResources NO-SOURCE
> Task :function:testClasses
> Task :function:test
> Task :function:check
> Task :function:build
> Task :model:assemble
> Task :model:compileTestJava
> Task :model:processTestResources NO-SOURCE
> Task :model:testClasses
> Task :model:test
> Task :model:check
> Task :model:build

BUILD SUCCESSFUL in 50s
14 actionable tasks: 14 executed

Current Behaviour

Gradle fails when trying to download modules

Step 9/24 : RUN gradle build
 ---> Running in 3cb02b281333

Welcome to Gradle 4.8.1!

...

> Task :model:compileJava
> Task :model:compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':model:compileClasspath'.
> Could not resolve org.apache.commons:commons-math3:3.6.1.
  Required by:
      project :model
   > Could not resolve org.apache.commons:commons-math3:3.6.1.
      > Could not get resource 'https://jcenter.bintray.com/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.pom'.
         > Could not GET 'https://jcenter.bintray.com/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.pom'.
            > Connect to jcenter.bintray.com:443 [jcenter.bintray.com/75.126.118.188] failed: Connection refused (Connection refused)
   > Could not resolve org.apache.commons:commons-math3:3.6.1.
      > Could not get resource 'https://jcenter.bintray.com/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.pom'.
         > Could not GET 'https://jcenter.bintray.com/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.pom'.
            > Connect to jcenter.bintray.com:443 [jcenter.bintray.com/75.126.118.188] failed: Connection refused (Connection refused)
> Could not resolve com.google.guava:guava:23.0.
  Required by:
      project :model
   > Could not resolve com.google.guava:guava:23.0.
      > Could not get resource 'https://jcenter.bintray.com/com/google/guava/guava/23.0/guava-23.0.pom'.
         > Could not GET 'https://jcenter.bintray.com/com/google/guava/guava/23.0/guava-23.0.pom'.
            > Connect to jcenter.bintray.com:443 [jcenter.bintray.com/75.126.118.188] failed: Connection refused (Connection refused)
   > Could not resolve com.google.guava:guava:23.0.
      > Could not get resource 'https://jcenter.bintray.com/com/google/guava/guava/23.0/guava-23.0.pom'.
         > Could not GET 'https://jcenter.bintray.com/com/google/guava/guava/23.0/guava-23.0.pom'.
            > Connect to jcenter.bintray.com:443 [jcenter.bintray.com/75.126.118.188] failed: Connection refused (Connection refused)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 47s
1 actionable task: 1 executed
The command '/bin/sh -c gradle build' returned a non-zero code: 1
2018/12/20 11:13:54 ERROR - Could not execute command: [docker build --build-arg http_proxy=http://10.118.1.80:3128/ --build-arg https_proxy=http://10.118.1.80:3128/ -t padiazg/crc-bcp:latest .]

Possible Solution

Two successful options:
a) Update GRADLE_OPTS in the Dockerfile like this

ENV GRADLE_OPTS="-Dorg.gradle.daemon=false -Dhttp.proxyHost=10.118.1.80 -Dhttp.proxyPort=3128 -Dhttps.proxyHost=10.118.1.80 -Dhttps.proxyPort=3128"

b) Create gradle.properties at the root if the java8 template with following content:

systemProp.http.proxyHost=10.118.1.80
systemProp.http.proxyPort=3128
systemProp.http.nonProxyHosts=localhost|127.0.0.1|10.22.*|10.118.*
systemProp.https.proxyHost=10.118.1.80
systemProp.https.proxyPort=3128
systemProp.https.nonProxyHosts=localhost|127.0.0.1|10.22.*|10.118.*

Steps to Reproduce (for bugs)

You must be behind a proxy, without direct access to the Internet.

$ faas-cli new test-function --lang java8
$ faas-cli build

Context

Both solutions proposed above works, but you have to modify the template after it is downloaded.
You need to do this for every project you are creating, of if for some reason you download the template again.
Also the template folder is specified in .gitignore, so this configuration wont be saved to your git repository.

Your Environment

  • Docker version docker version (e.g. Docker 17.0.05 ):
Client: Docker Engine - Community
 Version:           18.09.0
 API version:       1.39
 Go version:        go1.10.4
 Git commit:        4d60db4
 Built:             Wed Nov  7 00:47:51 2018
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.0
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.4
  Git commit:       4d60db4
  Built:            Wed Nov  7 00:55:00 2018
  OS/Arch:          linux/amd64
  Experimental:     false
  • Are you using Docker Swarm or Kubernetes (FaaS-netes)?
    Docker Swarm and Kubernetes

  • Operating System and version (e.g. Linux, Windows, MacOS):
    Windows and Linux

  • Link to your project or a code example to reproduce issue:

Additional tweaks to php7 template docs

Expected Behaviour

As discussed with @alexellis, some additional tweaks to the php7 template before the upcoming talks.

Current Behaviour

n/a

Possible Solution

n/a

Steps to Reproduce (for bugs)

n/a

Context

Some cosmetic changes to the docs for consistency.

Your Environment

n/a

Build error .NET Core

Error "ERROR - Could not execute command: [docker build -t function1:latest .]" when trying to build a .NET Core function.

Expected Behaviour

N/A

Current Behaviour

Possible Solution

Steps to Reproduce (for bugs)

  1. Create a .NET Core function in a folder faas-cli new --lang csharp function1
  2. cd to the function1 directory
  3. Building/deploying the vanilla created function works
  4. Open the folder with the Function.csproj + FunctionHandler.cs in vscode
  5. Adding Nuget package and change the code
  6. Going back to my terminal to the root folder of the created function
  7. Run $ faas-cli -action build -f ./function1.yml
  8. Result:
    FunctionHandler.cs(15,21): error CS0656: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create' [/home/app/src/function/Function.csproj]
    The command '/bin/sh -c dotnet publish -c release -o published' returned a non-zero code: 1
    2019/01/19 20:49:51 ERROR - Could not execute command: [docker build -t function1:latest .]

When trying to build directly in the folder with the csproj and cs file I get:
Restoring packages for /Users/gdillen/code/openfaas-functions/function1/Function.csproj...
Generating MSBuild file /Users/gdillen/code/openfaas-functions/function1/obj/Function.csproj.nuget.g.props.
Generating MSBuild file /Users/gdillen/code/openfaas-functions/function1/obj/Function.csproj.nuget.g.targets.
Restore completed in 528.53 ms for /Users/gdillen/code/openfaas-functions/function1/Function.csproj.
FunctionHandler.cs(15,21): error CS0656: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create' [/Users/gdillen/code/openfaas-functions/function1/Function.csproj]

Build FAILED.

FunctionHandler.cs(15,21): error CS0656: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create' [/Users/gdillen/code/openfaas-functions/function1/Function.csproj]
0 Warning(s)
1 Error(s)

Context

Your Environment

  • FaaS-CLI version ( Full output from: faas-cli version ): 0.8.3

  • Docker version docker version (e.g. Docker 17.0.05 ): 18.09.1

  • Are you using Docker Swarm or Kubernetes (FaaS-netes)? Docker Swarm

  • Operating System and version (e.g. Linux, Windows, MacOS): MacOS 10.14.2

  • Link to your project or a code example to reproduce issue:

  • Please also follow the troubleshooting guide and paste in any other diagnostic information you have:

Support building native modules i.e. C/C++

We would like to stick to a minor build for all templates, but also allow the use of gcc/make/git/musl (Glibc for Alpine), which is currently not supported.

One of the options is to duplicate the templates and have a separate dev build.
This will cost extra support efforts.

The other option is to use build-args and make the dev build optional.
This allows both having a minor build and supporting native C/C++ modules if required.

Any other suggestions are welcome.

Python and Ruby are with highest priority.

For Python, one can test with the Pillow module.
(Also can try NumPy and Pandas)

Ruby isn't running as non-root

Expected Behaviour / Current Behaviour

The Ruby template should be running as a non-root user but I can't see the final USER statement in the Dockerfile.

Possible Solution

Update the Dockerfile and do testing with accessing custom gems.

Steps to Reproduce (for bugs)

  1. Clone the templates repo and edit ruby/Dockerfile
  2. faas-cli new --lang ruby ruby-test
  3. Build / deploy / test
  4. Add a gem that is consumed in the code
  5. Repeat above

Add Java template

Title: Add Java template

Outcomes

As a user I can create a Java function using the CLI and an official template

Example:

CLI usage:

$ faas-cli new --lang java hello-java

Handler.java

Should mimic or be similar to Lambda Java signature:

Here is the exact AWS example:

package com.example.lambda.demo;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;

public class Hello implements RequestHandler<Object, String> {

    @Override
    public String handleRequest(Object input, Context context) {
        context.getLogger().log("Input: " + input);

        // TODO: implement your handler
        return "Hello from Lambda";
    }

}

Ours should be similar, but with our own classes/interfaces.

Constraints

  • Must not expose user to the entrypoint or web-server needed by of-watchdog HTTP mode.

  • Must allow gradle build to run as part of build

  • Must allow for tests to be run in build

Design/UX

  • Build system

Should use gradle

  • JDK version

Should use official OpenJDK image either v8 or v9. Perhaps this should be part of the template name such as: java@jdk9 instead of just java.

As an example see C# HTTP template - https://github.com/BurtonR/csharp-kestrel-template

Update Golang to 1.10

Golang 1.11 is shown as the latest stable Golang version, but there are some issues around needing CGO and GCC which means we should not move (yet). See issue on openfaas/faas - openfaas/faas#875

https://golang.org/dl/

If we have an official Docker image from the Docker Hub then let's try updating and test that.

Alex

Java8 template does not honor container memory limits

The JVM prior to 8u131 did not support cgroup memory limits (reference). This means that the JVM can overrun the memory allocated to it by its container, causing the container to be OOMKilled.

A better description of the issue (and resolution) can be found in this presentation entitled Why youโ€™re going to FAIL running Java on docker!

Expected Behaviour

Invoking the sample function defined below should result in a 200 OK response with the body containing something like Allocated more than 80% (75.5 MiB) of the max allowed JVM memory size (89.0 MiB) without the container crashing.

Current Behaviour

When the function is invoked, its container crashes and a 500 Internal Error Response is returned.

Possible Solution

Upgrade openjdk to at least 8u131 and use the -XX:+UnlockExperimentalVMOptions and -XX:+UseCGroupMemoryLimitForHeap arguments to the java command.

Steps to Reproduce (for bugs)

  1. Create a new function using the java8 template
  2. Use the code at the end of this issue as the implementation
  3. Apply memory limits as described below
  4. Invoke the function via curl
  5. Observe a 500 response

Context

I came across this issue when building another JVM-based template and thought it would be good to share. :)

Your Environment

  • Docker version docker version (e.g. Docker 17.0.05 ):
    Docker CE 18.09.1

  • Are you using Docker Swarm or Kubernetes (FaaS-netes)?
    FaaS-netes

  • Operating System and version (e.g. Linux, Windows, MacOS):
    macOS Mojave 10.14.3

  • Link to your project or a code example to reproduce issue:

Use the following implementation for a java8-based function. This is based on the Java Docker Fail sample.

public static String humanReadableByteCount(long bytes, boolean si) {
    int unit = si ? 1000 : 1024;
    if (bytes < unit)
        return bytes + " B";
    int exp = (int) (Math.log(bytes) / Math.log(unit));
    String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
    return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}

private String bigString() {
    System.out.println("Starting to allocate memory...");
    Runtime rt = Runtime.getRuntime();
    StringBuilder sb = new StringBuilder();
    long maxMemory = rt.maxMemory();
    long usedMemory = 0;
    while (((float) usedMemory / maxMemory) < 0.80) {
        sb.append(System.nanoTime() + sb.toString());
        usedMemory = rt.totalMemory();
    }
    String msg = "Allocated more than 80% (" + humanReadableByteCount(usedMemory, false) + ") of the max allowed JVM memory size ("
            + humanReadableByteCount(maxMemory, false) + ")";
    System.out.println(msg);
    return msg;
}

public IResponse Handle(IRequest req) {
    Response res = new Response();
    res.setBody(bigString());

    return res;
}

You will also need to apply constraints to the function, e.g.:

limits:
  memory: "200Mi"
requests:
  memory: "100Mi"

Add "EXPOSE 8080" to all templates

Expected Behaviour

If we add EXPOSE 8080 to all templates then they will be usable with docker run -P which can bind a random local port for testing / debug.

Current Behaviour

Only some have it.

Move to Alpine 3.8 where possible

Expected Behaviour

Alpine 3.8 should be used instead of 3.7 since it is a newer release

Current Behaviour

We use 3.7.

Possible Solution

Check for breaking updates / incompatibilities and move to newer version if no blocking issues are found.

Go template fails if vendored packages incorrectly formatted

The go template checks for formatting of all .go files using gofmt -l. There is currently logic to exclude any /vendor/ folder in the main template directory, but if the function includes it's own vendor folder that also needs ignoring.

I've worked-up a patch and will submit a PR referencing this issue.

Kotlin Templates

In OpenFaas templates there isn't a template for Kotlin Native. A recommendation was made by @iyovcheva to have Kotlin Native supported via a custom template.

Possible Solution

The prudent course of action would be to create a custom OpenFaaS template that is based on the unofficial Swift OpenFaas template. I already have a initial implementation of the Kotlin Native OpenFaaS template (hasn't been tested yet).

Context

By having a template for Kotlin Native it would speed up the process of creating a Kotlin Native project that can be executed by OpenFaaS, which is less error prone.

Suggestion: CI for the templates

Expected Behaviour

The templates should validate via a travis build. Whenever someone raises a PR, all templates should be used to create the default sample, build it and run it checking the result

Current Behaviour

Manually verified.

Possible Solution

A shell script should be able to do this. Functions can be run using docker run rather than using full OpenFaaS.

Automation would be ideal or some kind of config file. This should be minimal as to not bloat the repository.

java template with external dependencies

Unable to use external dependencies with the java8 template.
https://github.com/openfaas/templates/tree/master/template/java8#external-dependencies

Expected Behaviour

The build should succeed.

Current Behaviour

The command faas-cli build -f jdbc.yml fails.

> Task :model:compileJava
Download http://my-repo/com/oracle/ojdbc8/12.2.0.1/ojdbc8-12.2.0.1.pom
Download http://my-repo/com/oracle/ojdbc8/12.2.0.1/ojdbc8-12.2.0.1.jar
> Task :function:compileJava
> Task :entrypoint:compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':entrypoint:compileClasspath'.
> Could not find com.oracle:ojdbc8:12.2.0.1.
  Required by:
      project :entrypoint > project :function

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 10s
3 actionable tasks: 3 executed
The command '/bin/sh -c gradle build' returned a non-zero code: 1

Possible Solution

Steps to Reproduce (for bugs)

  1. faas-cli new --lang java8 jdbc
  2. Add code snippet below to method stub
  3. Add compile 'com.oracle:ojdbc8:12.2.0.1' to build.gradle

Context

Unable to build java fn from template when using dependencies not from jcenter.

Your Environment

  • Docker version docker version (e.g. Docker 17.0.05 ):
Client:
 Version:           18.06.0-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        0ffa825
 Built:             Wed Jul 18 19:05:26 2018
 OS/Arch:           darwin/amd64
 Experimental:      false
Server:
 Engine:
  Version:          18.06.0-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       0ffa825
  Built:            Wed Jul 18 19:13:46 2018
  OS/Arch:          linux/amd64
  Experimental:     true
  • Are you using Docker Swarm or Kubernetes (FaaS-netes)?
    kube

  • Operating System and version (e.g. Linux, Windows, MacOS):
    MacOS

  • Link to your project or a code example to reproduce issue:

    public IResponse Handle(IRequest req) {
		Response res = new Response();
		try(java.sql.Connection conn = java.sql.DriverManager.getConnection(req.getBody())) {
		  res.setBody("connected");
		} catch (Exception e) {
  	      res.setBody(e.toString());
		}
	    return res;
    }

Run dep init as part of the build for go and go-armhf

Expected Behaviour

Other templates like Node and Python don't make you install the dependencies yourself -- the Docker Build will take care of dependencies as part of the faas-cli build process. However, for go and go-armhf you are required to run dep init before building, or else your dependencies won't be picked up.

Current Behaviour

You are required to run dep init for go and go-armhf.

Possible Solution

Include dep init as part of the Dockerfile for go.

ericstoekl@62c12af

Steps to Reproduce (for bugs)

  1. faas-cli new --lang go gotest; faas-cli new --lang node nodetest
  2. vim gotest/handler.go, Include a dependency in the import section
  3. cd nodetest, include a dependency with npm install <dep> --save, then delete node_modeuls and package-lock.json
  4. faas-cli build each function -- nodetest will work and gotest will fail to build

Context

Ran into this when building go functions

Your Environment

  • Docker version docker version (e.g. Docker 17.0.05 ):
    18.05.0-ce
  • Are you using Docker Swarm or Kubernetes (FaaS-netes)?
    swarm
  • Operating System and version (e.g. Linux, Windows, MacOS):
    Ubuntu 16
  • Link to your project or a code example to reproduce issue:
    https://github.com/ericstoekl/go-functions/

Edit java template to allow resources

Raised on slack.

Resources, located in funcName/src/main/resources, are not available in the image after build.

Expected Behaviour

All resources should be available in the image.

Possible Solution

Follow Gradle documentation (possibly use SourceSet) and edit build.gradle

Steps to Reproduce (for bugs)

  1. faas-cli new funcName --lang java8
  2. Add resources to /src/main/resources
  3. Build
  4. Check that resources are not available

Remove blanks at the end of the lines.

Remove unnecessary blanks at the end of the lines in following files:

README.md
template/dockerfile/function/Dockerfile
template/node-arm64/Dockerfile
template/python-armhf/Dockerfile
template/python3-armhf/Dockerfile
template/python3/Dockerfile

Expected Behaviour

No random blanks in these files.

Current Behaviour

There are random blanks these files.

Possible Solution

Remove them with an editor like VSCode.

Context

The blanks are always highlighted in red by editors like VSCode.

C# template transforms newlines which causes hashing troubles

Expected Behaviour

When using the C# template the input hash should match the signature sent in the header.

Current Behaviour

The newlines in the input are converted, which causes the hash to change.

Possible Solution

Instead of using Console.ReadLine the template should use Console.In.ReadToEnd.

Steps to Reproduce (for bugs)

  1. faas-cli new hashbug --lang csharp
  2. Change the return of the function to return $"Hi there - your input was: {BitConverter.ToString(Encoding.UTF8.GetBytes(input))}";
  3. Build & Deploy the function
  4. Test the function with input with newlines
  5. The result will be displayed in hex. Newlines are only 0A not 0D-0A when they are a CRLF.

Context

I was trying to verify the signature hash on a github webhook and couldn't.

Adding C/C++ template.

As you know C/C++ are popular languages and having template for these languages will be appreciated.
Would you please add C/C++ template?

Add dockerfile-arm32v6 template

Add a dockerfile arm32v6 template based on the existing dockerfile template

Expected Behaviour

ARM users should be able to use an official dockerfile template

Current Behaviour

OpenFaaS don't offer as of now the possibility to run dockerfile functions from an official template on a ARM cluster (like Raspberry pi).

Possible Solution

Add an official template based on arm32v6/alpine instead of alpine
armhf has been deprecated in favor of arm32v6.
Moreover, arm32v6 is compatible with arm32v6, arm32v7 and arm64v8 cpus.

Steps to Reproduce (for bugs)

On an ARM based server,

  1. faas new helloworld --lang dockerfile
  2. faas build --yaml helloworld.yml

Container fail to start
docker logs <helloworld container>
returns
standard_init_linux.go:190: exec user process caused "exec format error"

Context

I was trying to setup an Hello World (dockerfile based) on my Raspberry Pi

Your Environment

  • Docker version docker version (e.g. Docker 17.0.05 ):
Client:
 Version:           18.09.0
 API version:       1.39
 Go version:        go1.10.4
 Git commit:        4d60db4
 Built:             Wed Nov  7 00:57:21 2018
 OS/Arch:           linux/arm
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.0
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.4
  Git commit:       4d60db4
  Built:            Wed Nov  7 00:17:57 2018
  OS/Arch:          linux/arm
  Experimental:     false
  • Are you using Docker Swarm or Kubernetes (FaaS-netes)? Docker Swarm

  • Operating System and version (e.g. Linux, Windows, MacOS): Linux

  • Link to your project or a code example to reproduce issue:

PHP template

PHP template request

Expected Behaviour

Be able to deploy and run PHP functions

Current Behaviour

Missing a template for PHP applications

Possible Solution

Add PHP template

[go] template doesn't download the dependency packages

Dependency package not being downloaded in Dockerfile
which results go code with external library to fail

Expected Behaviour

Dependent library should be downloaded automatically to go GOPATH before the compilation

Current Behaviour

Currently the dependent library aren't being downloaded causing the go build command to fail

Possible Solution

This line can be added in Dockerfile to download the dependent library

go get ... 

Also git need to be available as for github repo, go get internally use git

Steps to Reproduce (for bugs)

Create a new function using go language

faas-cli new --lang go --prefix s8sg mygofunc

Use any external library in handler.go such as
golang.org/x/net/context
make sure to use it somehow
Build your function

faas-cli build -f stack.yml

Context

Template should be ready to use with the least possible input/change from the user.
Go template provides an awesome to to get started with simple go coding. Although the dependency should be downloaded automatically

Your Environment

  • Docker version docker version (e.g. Docker 17.0.05 ):
Client:
 Version:	18.03.0-ce
 API version:	1.37
 Go version:	go1.9.4
 Git commit:	0520e24
 Built:	Wed Mar 21 23:10:09 2018
 OS/Arch:	linux/amd64
 Experimental:	false
 Orchestrator:	swarm

Server:
 Engine:
  Version:	18.03.0-ce
  API version:	1.37 (minimum version 1.12)
  Go version:	go1.9.4
  Git commit:	0520e24
  Built:	Wed Mar 21 23:08:36 2018
  OS/Arch:	linux/amd64
  Experimental:	false
  • Are you using Docker Swarm or Kubernetes (FaaS-netes)?
    Swarm

  • Operating System and version (e.g. Linux, Windows, MacOS):
    Linux

  • Link to your project or a code example to reproduce issue:

Stop using --no-cache with apk del

Expected Behaviour

We should not be using --no-cache with apk del.

Current Behaviour

Most alpine based template Dockerfiles have --no-cache set which results in the APK index being downloaded when set (you can see this occur by setting the --verbose flag).

# apk del nginx -v --no-cache
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
...

Possible Solution

Update Dockerfiles.

Steps to Reproduce (for bugs)

  1. apk add curl --no-cache
  2. apk del curl --no-cache --verbose

Context

Observed during review of php7 template.

Your Environment

Alpine

Create official Rust template

It would be good to have official Rust template

Expected Behaviour

Having Rust's OpenFaaS template

Current Behaviour

No Rust template

Possible Solution

Steps to Reproduce (for bugs)

Context

Your Environment

  • Docker version docker version (e.g. Docker 17.0.05 ):

  • Are you using Docker Swarm or Kubernetes (FaaS-netes)?

  • Operating System and version (e.g. Linux, Windows, MacOS):

  • Link to your project or a code example to reproduce issue:

[node] Proposal: omit devDependencies from node image builds

Expected Behaviour

Image builds should only contain runtime dependencies.

Current Behaviour

npm i installs all dependencies and can create unnecessary image bloat with dev tools such as babel and typescript.

Possible Solution

add --production

Steps to Reproduce (for bugs)

  1. add a devDependency
  2. build
  3. observe the unnecessary dependency

Context

Image bloat

Your Environment

Any node project.

Can't reference local projects from C#

Expected Behaviour

I would like to be able to reference a local project from a C# function.

Current Behaviour

The project folder which is specified as the handler in the yml file is copied into the build directory. It is then built inside the container. As a result, the referenced project cannot be found.

Possible Solution

Steps to Reproduce (for bugs)

  1. Create a new function from the CSharp template.
  2. Create a new C# project in the same folder.
  3. Reference the C# project from the function project.
  4. Run a faas build.

Context

I have a project which contains model classes. One of these models will be returned by the function. For simplicity, I would like to share the model between the function and the calling application (happens to be another function).

Your Environment

  • Docker version docker version (e.g. Docker 17.0.05 ):
    Docker version 18.09.0, build 4d60db4

  • Are you using Docker Swarm or Kubernetes (FaaS-netes)?
    Docker Swarm

  • Operating System and version (e.g. Linux, Windows, MacOS):
    Windows 10, Linux Containers

  • Link to your project or a code example to reproduce issue:

Unknown flag: chown in nodejs template

COPY --chown is not work on docker 17.03.2-ce

Expected Behaviour

fass-cli build will success

Current Behaviour

It will failed at docker build.

...
Step 14 : COPY --chown=app:app function/ .
Unknown flag: chown

Possible Solution

Do not use COPY --chown in Dockerfile

Steps to Reproduce (for bugs)

  1. Using a bit older docker
  2. js-fn.yml to specify "lang: node"
  3. faas-cli build -f js-fn.yml

Context

Your Environment

  • Docker version docker version (e.g. Docker 17.0.05 ):
    Both 17.03.2-ce and 1.12.6
  • Are you using Docker Swarm or Kubernetes (FaaS-netes)?
    K8s
  • Operating System and version (e.g. Linux, Windows, MacOS):
    Linux
  • Link to your project or a code example to reproduce issue:
    JS example can reproduce this issue.

Check all usages of root in templates

Description

All templates in this repository should be using non-root users

This is the case for Go and some of the other templates, but we need to review all other templates including ARM to make sure they are covered by this work and it is fully tested.

The easiest way to do this task is to look into each Dockerfile and make sure there is a USER statement pointing to a non-root user.

Acceptance

Any changes need testing including testing with adding modules - i.e. pip for python, nuget packages for C#

mistake in README.MD

There is a mistake in the Java8 template watchdog type in README.md .

Expected Behaviour

Correct type of watchdog should be written.

Current Behaviour

Classic watchdog is written instead of of-watchdog in the java8 section.

Possible Solution

Change classic to of-watchdog in the java8 section.
#110 Is the suggested change.

Context

README.md is incorrect, I noticed it while pull requesting the java8 template.

Update node and node-armhf templates to Node 10

Node 10 will be released on the 2018-10-30 and will become the new LTS. If that happens we should update the base image to Node 10.

Expected Behaviour

Current Behaviour

Possible Solution

Steps to Reproduce (for bugs)

Context

Your Environment

  • Are you using Docker Swarm or Kubernetes (FaaS-netes)?

  • Operating System and version (e.g. Linux, Windows, MacOS):

  • Link to your project or a code example to reproduce issue:

handler.js can return a Promise

We should be able to handle when the handler.js defined by the user returns a promise in turn of a final value.

Expected Behaviour

The handler.js could return either a final value or a promise, and we should resolve it if so to get the value to return.

Current Behaviour

Now the handler.js exports a function that receives a callback to return a resulting value, with this improvement the user could return also a promise.

Update node template for when user returns nil

Expected Behaviour

Nil should act as a valid return value and just mean that we print nothing.

Current Behaviour

This causes an exception (i.e. if the user sends "nil" to the callback):

process.stdout.write(undefined)

https://github.com/openfaas/templates/blob/master/template/node/index.js#L17

Possible Solution

Add a truthy check before entering the code block.

Steps to Reproduce (for bugs)

  1. faas-cli new --lang node test
  2. Edit test/handler.js: module.exports = (context, callback) => { callback(undefined, undefined); }
  3. faas-cli up --skip-push
  4. Invoke the function. You'll see the error, when fixed you'll just see nothing come back but a 200 status.

Context

People sometimes see this and are confused about the error. (seen on Slack)

Change the c# examples to string interpolation.

I know, that these are just examples, but string interpolation is much more readable so I think this change would be a minor improvement to the example in the templates.

The change would be from

            return string.Format("Hi there - your input was: {0}\n", input);

to

            return $"Hi there - your input was: {input}\n";

Question: How do we handle Gradle builds?

With larger projects there is a need to use a build system (with some programming languages). In the case of Kotlin (as a example) Gradle is the main build system used. Gradle has a build structure convention (src/main/kotlin, src/test/kotlin etc) which is used by projects that use the build system.

Expected Behaviour

Unsure what the expected behaviour would be since the OpenFaaS template structure assumes a programming language doesn't use a build system, and that the build process is completely handled in a Docker image.

Current Behaviour

As it currently stands a template cannot use a build system, especially one that has build structure conventions that need to be followed in a project.

Context

There needs to be a general consensus (way forward) on how to handle templates where a build system is needed or required by a programming language.

Build Issues with Go Template for Raspberry Pi 3Bs

I got two problems whenever I try to build a Go function for Raspberry Pi 3Bs.

To build the project in MacOS, I did the following:

faas-cli new pet-api --lang go-armhf
faas-cli build -f pet-api.yml

However when I run the build, I get the following error:

The command '/bin/sh -c test -z ./main.go' returned a non-zero code: 1
2019/03/13 14:36:25 ERROR - Could not execute command

The offending section is:

RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./function/vendor/*"))" || { echo "Run \"gofmt -s -w\" on your Golang code"; exit 1; }

I don't know what -z does in test -z. But I assumed it's testing for the presence of file. Google showed that test -e will do the trick. So I replaced it with:

RUN test -e "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./function/vendor/*"))" || { echo "Run \"gofmt -s -w\" on your Golang code"; exit 1; }

That worked.

Now I deployed the project via

faas-cli deploy -f pet-api.yml

Then I got hit with this error upon calling the function:

fork/exec
./handler: exec format error

So it turns out the offending line is this:

RUN CGO_ENABLED=0 GOOS=linux \

I have to compile it for ARM as follows:

    go build --ldflags "-s -w" -a -installsuffix cgo -o handler . && \
    go test ./... -cover

When I run the function, I was able to get the info I need.

Also upgrading to the latest arm version works as well:

FROM arm32v7/golang:1.12.0-alpine3.9 

I am thinking of creating a PULL request.

Install curl what already exists

Expected Behaviour

The Dockerfile in the csharp template contains only required steps.

Current Behaviour

The Dockerfile install curl to download the watchdog. After that curl will be uninstalled. There is no need for this steps. The program curl is already part on the image microsoft/dotnet:2.1-runtime.

Console output of my test

root@vmd24929:~# docker run -it --rm microsoft/dotnet:2.1-runtime /bin/bash
root@40ce644ee8a3:/# apt-get install curl ca-certificates
Reading package lists... Done
Building dependency tree
Reading state information... Done
curl is already the newest version (7.52.1-5+deb9u7).
ca-certificates is already the newest version (20161130+nmu1+deb9u1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Possible Solution

Remove the steps in the dockerfile.

Table of contents listing templates

Let's create a table of contents listing the template in this repo

Name Language Version Linux base Watchdog Link
python3 Python 3.6 Alpine Linux 3.8 Classic

[PHP] Optimise building cache

Expected Behaviour

When dependencies/requirements are not changed, these build steps should be cached.
Pros:

  • build time is reduced
  • reduce Github rate-limit issues (when not providing a Github token)
    Cons:
  • composer.json and php-extensions.sh must exist for this template, the user cannot delete them when they are not used

Current Behaviour

Any modification in function directory uncaches the build step starting from copy of function source codes.

Template pulled but new project generates empty folder

I'm working on creating a custom template for scala (in a personal repository). When I pull the template, everything is fine. When I try to build with the template I get an empty directory.

Template in question: https://github.com/AnEmortalKid/scala-template-faas

Here's the structure of my repo:

template/
  scala/
    src/main/scala/Main.scala
    Dockerfile
    template.yml
    build.bst
    project

When I pull the template, I see the structure copied into my local template folder:

scala $ pwd
/MY_USER/template/scala
MY_USER scala $ ls
Dockerfile	build.sbt	project		src		template.yml

Expected Behaviour

When I run faas-cli new my-func --lang scala I should get:

my-func.yml
my-func/
  src/main/scala/Main.scala
  Dockerfile
  build.sbt
  project

Current Behaviour

I only get:

my-func.yml
my-func/

Possible Solution

Maybe a pointer to some doc on what I'm doing wrong! I've looked at https://github.com/itscaro/openfaas-template-php/tree/master/template and seem to have the same structure.

Steps to Reproduce (for bugs)

Template in question: https://github.com/AnEmortalKid/scala-template-faas

  1. faas-cli template pul https://github.com/AnEmortalKid/scala-template-faas
  2. faas-cli new my-func --lang scala
  3. Note that my-func is empty
  4. Note that template/scala/ has stuff within it.

Context

Your Environment

  • Docker version docker version (e.g. Docker 17.0.05 ):
docker -v
Docker version 18.06.0-ce, build 0ffa825
faas-cli version
  ___                   _____           ____
 / _ \ _ __   ___ _ __ |  ___|_ _  __ _/ ___|
| | | | '_ \ / _ \ '_ \| |_ / _` |/ _` \___ \
| |_| | |_) |  __/ | | |  _| (_| | (_| |___) |
 \___/| .__/ \___|_| |_|_|  \__,_|\__,_|____/
      |_|

CLI:
 commit:  8bd16510bc6476edbe6ab593786feefbe2fb8f6f
 version: 0.6.16

Gateway
 uri:     http://127.0.0.1:8080
 version: 0.8.9
 sha:     8f0d2d1fd6c5e3c9d2e0a73d6d256c4e232b3737
 commit:  Expose scale-function endpoint


Provider
 name:          faas-swarm
 orchestration: swarm
 version:       0.4.0 
 sha:           cd4ff365c29d6c6a49e0a75dfa98899e09c98318

Bump watchdog for GC optimisation

PR 1001 in the faas repo fixed a GC optimisation in the watchdog, but currently images are with older watchdog binary

Expected Behaviour

Pull watchdog binary with latest release (0.9.14)

Current Behaviour

Most of the templates are still with 0.9.6 release of the watchdog with the unoptimised GC

Possible Solution

In the templates which are using the classic watchdog change the Dockerfile to pull latest watchdog binary(0.9.14) here is example PR which updates the watchdog.

Steps to Reproduce (for bugs)

N.A. People use watchdog binary with memory leak unless they manually update their dockerfiles.

Context

The binary which is used now (0.9.6) for the Dockerfiles needs updating to the latest.

Move from .NET Core 2.0 to 2.1

We should update to the latest minor version of .NET Core 2.0

This is a simple change in the Dockerfile.

Work was suggested via #33, but after 6 weeks of inactivity we can assume the community needs to finish the work.

Alex

Add support for ARMv6 devices and build fwatchdog as part of template

Add support for ARM 32bit v6 devices like Raspberry Pi Zero. Also including building of fwatchdog as part of template.

Expected Behaviour

Add template for ARMv6 devices e.g. python3-armv6
Additional, build fwatchdog as part of template build process

Current Behaviour

No template available for ARMv6.

Possible Solution

Working example:
https://github.com/ZeoX06/templates/blob/arm32v6_support/template/python3-armv6/Dockerfile
I'm not ready with reading the guide to make a pull request ;)

Steps to Reproduce (for bugs)

python3-armhf template not running on ARMv6 devices

Context

Like to use template directly and make it easy for other people to run openfaas on Raspberry Pi Zero devices.

Your Environment

  • Docker version docker version (e.g. Docker 17.0.05 ):
    18.06.1-ce

  • Are you using Docker Swarm or Kubernetes (FaaS-netes)?
    Docker Swarm

  • Operating System and version (e.g. Linux, Windows, MacOS):
    Linux

Wrong flag set for group in non-root users

This line in the Node template is incorrect according to the man/help page for busybox:

RUN addgroup -S app && adduser -S -g app app

-g must be G

/ # adduser
BusyBox v1.27.2 (2017-12-12 10:41:50 GMT) multi-call binary.

Usage: adduser [OPTIONS] USER [GROUP]

Create new user, or add USER to GROUP

        -h DIR          Home directory
        -g GECOS        GECOS field
        -s SHELL        Login shell
        -G GRP          Group
        -S              Create a system user
        -D              Don't assign a password
        -H              Don't create home directory
        -u UID          User id
        -k SKEL         Skeleton directory (/etc/skel)

Impact is unknown but should be fixed as soon as possible.

Expected Behaviour

app should belong to app group

Current Behaviour

app doesn't belong to the group

Possible Solution

Fix flag in all/any templates including ARM.

This will need testing too.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.