Skip to content

MartinHeinz/openfaas-templates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenFaaS Templates

Build Status

This repository is used both for development of OpenFaaS templates and well as a OpenFaaS Template Store.

Blog Posts - More Information About This Repo

You can find more information about this project/repository and how to use it in following blog posts:

Related Projects/Work

OpenFaaS functions created using templates in this repository can be found in following repository - https://github.com/MartinHeinz/openfaas-functions.

Usage

Before deploying functions, the Docker image needs to first be push to remote registry repository, this repository is specified using PREFIX variable in Taskfile.yml. You need to change its value to your Docker Hub username.

  • Verify:

    You can verify that all templates work by running:

    task verify

    This will build all templates in template directory. Ideally test should be included in Docker build, so that test don't need to be ran separately.

  • Build:

    You can build the Docker image of the template using:

    task build FUNC=golang-mod
  • Run:

    You can run template by building and running function created from it:

    task run FUNC=golang-mod

    The function is ran in Docker container on local accessible on port 8081.

  • Debug:

    You can debug template by building and running function created from it and attaching to its watchdog process logs:

    task debug FUNC=golang-mod

    When the function is running you can hit it with cURL:

    curl -vvv --header "Content-Type: application/json" \
              --request POST \
              --data '{"key":"value"}' \
              127.0.0.1:8081

    You might also want to change timeouts of the function when debugging (template.yml):

    functions:
        func_name:
          ...
          environment:
              read_timeout: 20
              write_timeout: 20
  • Clean:

    To remove artifacts created during build you can run:

    task clean

Using Local Docker Images

Images need to be pushed to remote registry, because OpenFaaS doesn't recognize local repositories. That's why, you need to specify prefix, which is a username + repository in remote registry.

If you don't want to push images, then you can use helm and pass it openfaasImagePullPolicy and faasnetesd.imagePullPolicy parameters to use local docker images:

helm upgrade openfaas chart/openfaas --install \
  --set "faasnetesd.imagePullPolicy=IfNotPresent" \
  --set "openfaasImagePullPolicy=IfNotPresent" \
  --namespace openfaas  \
  --set functionNamespace=openfaas-fn \
  --set operator.create=true

Create New Template

How you create new templates depends on language you use, therefore please refer to guide at https://github.com/openfaas/faas-cli/blob/master/guide/TEMPLATE.md

For the Golang based templates please use Golang module system.

You can use ./template/golang-mod as a base or example.

Before building image, you first need to download all dependencies with go mod tidy.

Troubleshooting Functions

Apart from task debug you can also use following commands for troubleshooting:

  • View functions and their logs:

    $ kubectl get deploy -n openfaas-fn
    NAME             READY     UP-TO-DATE   AVAILABLE    AGE
    <FUNCTION_NAME>   0/1       1            0           11m
    nodeinfo          1/1       1            1           7h3m
    
    kubectl logs -n openfaas-fn deploy/<FUNCTION_ANME>
  • See if function failed to start:

    kubectl describe -n openfaas-fn deploy/<FUNCTION_NAME>

Resources

Releases

No releases published

Packages

No packages published