- Published on
Making deploying functions even easier with faas-cli up using OpenFaaS
- Authors
- Name
- Ruan Bekker
- @ruanbekker
I recently discovered that the faas-cli
allows you to append your function's yaml to an existing file when generating a new function. And that faas-cli up
does the build, push and deploy for you.
The way I always did it:
Usually, I will go through this flow: create, build, push, deploy, when creating 2 functions that will be in the same stack:
$ faas-cli new --lang python3 fn-old-foo \
--prefix=ruanbekker \
--gateway https://openfaas.domain.com
then:
$ faas-cli build -f fn-old-foo.yml && \
faas-cli push -f fn-old-foo.yml && \
faas-cli deploy -f fn-old-foo.yml
And for my other function:
$ faas-cli new --lang python3 fn-old-bar \
--prefix=ruanbekker \
--gateway https://openfaas.domain.com
then:
$ faas-cli build -f fn-old-bar.yml && \
faas-cli push -f fn-old-bar.yml && \
faas-cli deploy -f fn-old-bar.yml
And then you are ready to invoke those functions.
The new discovered way
So recently I discovered that you can append the yaml definition of your function to an existing yaml file, and use faas-cli up
to build, push and deploy your functions:
Generating the first function:
$ faas-cli new --lang python3 fn-foo \
--prefix=ruanbekker \
--gateway https://openfaas.domain.com
Stack file written: fn-foo.yml
Now that we have fn-foo.yml
in our current work directory, we will append the second function the that file:
$ faas-cli new --lang python3 fn-bar \
--prefix=ruanbekker \
--gateway https://openfaas.domain.com \
--append fn-foo.yml
Stack file updated: fn-foo.yml
Now, when using faas-cli up
it expects by default that the filename is stack.yml
which we can change with -f
but to keep this as easy as possible, we will change the filename to stack.yml
:
$ mv fn-foo.yml stack.yml
At the moment, our stack.yml
will look like this:
provider:
name: openfaas
gateway: https://openfaas.domain.com
functions:
fn-foo:
lang: python3
handler: ./fn-foo
image: ruanbekker/fn-foo:latest
fn-bar:
lang: python3
handler: ./fn-bar
image: ruanbekker/fn-bar:latest
Deploying our functions is as easy as:
$ faas-cli up
...
Deploying: fn-foo.
Deployed. 202 Accepted.
URL: https://openfaas.domain.com/function/fn-foo
Deploying: fn-bar.
Deployed. 202 Accepted.
URL: https://openfaas.domain.com/function/fn-bar
Simply amazing. OpenFaaS done a great job in making it as simple and easy as possible to get your functions from zero to deployed in seconds.
Thank You
Thanks for reading, if you like my content, feel free to check out my website, and subscribe to my newsletter or follow me at @ruanbekker on Twitter.
- Linktree: https://go.ruan.dev/links
- Patreon: https://go.ruan.dev/patreon