Git Product home page Git Product logo

multiarch-templates's Introduction

multiarch-templates

OpenFaaS multi-arch templates

Notes:

This relies on Docker's new buildx container builder and buildkit. A flag is required to enable buildx: export DOCKER_CLI_EXPERIMENTAL=enabled, then commands can be invoked as per below

The basic workflow of the usual faas-cli up command invokes: docker build, docker push and the deploy code against the OpenFaaS gateway. These commands can also be run one-by-one.

When it comes to using buildx with faas-cli, there's currently no direct support, however you can still use a feature of faas-cli called shrinkwrap to help. The command faas-cli build --shrinkwrap will create a new folder with a valid Docker build context - first laying down the template of choice, followed by the function's code.

If you're looking for a HTTP-based template see: OpenFaaS Golang HTTP templates

Suggestions on how to support buildx and a series of platforms in faas-cli would be welcomed. Join us on Slack in the #contributors channel

Golang

You can also use these instructions with golang-http and golang-middleware after this PR was merged.

faas-cli template pull https://github.com/openfaas-incubator/golang-http-template

Create a new function

export DOCKER_CLI_EXPERIMENTAL=enabled
export OPENFAAS_PREFIX="alexellis2"
export FN="multiarch-fn"

faas-cli template pull https://github.com/alexellis/multiarch-templates
faas-cli new --lang go-multiarch $FN

Build and push

faas-cli build --shrinkwrap -f $FN.yml

docker buildx create --use --name=multiarch --node=multiarch
docker buildx build \
	--platform linux/amd64,linux/arm/v7,linux/arm64 \
	--output "type=image,push=true" \
	--tag $OPENFAAS_PREFIX/$FN:latest build/$FN/

Just build

faas-cli build --shrinkwrap -f $FN.yml

docker buildx create --use --name=multiarch --node=multiarch
docker buildx build \
--output "type=docker,push=false" \
--tag $OPENFAAS_PREFIX/$FN:latest build/$FN/

Deploy your function

The build above will work on amd64, RPi (armv7) and ARM64.

faas-cli deploy --image $OPENFAAS_PREFIX/$FN:latest \
  --name $FN

curl http://127.0.0.1:8080/function/multiarch-fn -d "hi"
Hello, Go. You said: hi

Node.js 12

As per above, but change the template name:

Create a new function

faas-cli new --lang node12-multiarch $FN

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.