Old and new - ASCII art and serverless

In this post, we will build a FaaS function for creating Ascii banners without writing a single line of code. Why? Well because Ascii banners are nice!

Wait! We said no code!

For that, we will use, Figlet:

FIGlet is a program for making large letters out of ordinary text

Using Figlet, and FaaS, we will create a Function (fka. Lambda), to be able to create banners such as this one:

faas-figlet-output

Do a test run on PWD or on a Swarm

If you want to see how this would behave, go ahead, and Try in PWD

Once the stack is ready, just call:

curl http://localhost:8080/function/func_figlet -d 'Hello, FaaS, world'  

and see the magic!

You can also try this out on your laptop if you have Docker installed already
by deploying the docker-compose file:

docker swarm init  
docker stack deploy -c docker-compose.yml func  

If this is the first time you are reading about this subject, maybe you should start with this post first or the post by Docker Captain Alex Ellis.

Prepare the image

We can base our image on a latest alpine, add to it figlet, and add FaaS watchdog and specify figlet as the process to execute:

FROM alpine:3.5

RUN apk update && apk upgrade  
RUN apk add figlet

ADD https://github.com/alexellis/faas/releases/download/0.5.6-alpha/fwatchdog /usr/bin  
RUN chmod +x /usr/bin/fwatchdog

ENV fprocess="figlet"  
CMD ["fwatchdog"]  

You can find all the code and scripts accompanying this post here: https://github.com/jmkhael/faas-figlet

Build, deploy and test

First, let's build the image above:

docker build -t jmkhael/faas-figlet .  

Now, we are ready to deploy our function.
For that we will be using the faas-cli.

I'll also give an alternative way to deploy from the shell - you can find the scripts in the github repo

Deploy with faas-cli

This experimental CLI can be used to and deploy functions to FaaS or to build Node.js or Python functions from a templates meaning you just write a handler file (handler.py/handler.js).

You define individual functions or a set of of them within a YAML file. This makes the CLI easier to use and means you can use this file to deploy to your FaaS instance.

In laymen's term, faas-cli can help you scaffold a function. Supported languages are python and node.js. It can deploy your function from a yml file.

We will only use faas-cli to deploy our function in this example. for a more in depth introduction to faas-cli, check Alex's post here

First make sure to install faas-cli if you don't have it yet, like so:

curl -sSL cli.get-faas.com | sudo sh  

As stated, faas-cli supports a YAML file where you can define metadata describing your functions.

Below you can find the yml file for this example:

provider:  
  name: faas
  gateway: http://localhost:8080
  network: "func_functions" # this is optional and defaults to func_functions

functions:  
  func_figlet:
    image: jmkhael/faas-figlet
    fprocess: figlet

Now we can use faas-cli to deploy our function:

faas-cli -action=deploy -f faas-figlet.yml  

if everything went fine, you should see that faas-cli deployed your service and gave you a url where that function resides:

Deploying: func_figlet.  
No existing service to remove  
200 OK  
URL: http://localhost:8080/function/func_figlet  

Let's try to hit that url with some data:

curl http://localhost:8080/function/func_figlet -d 'Hello, FaaS, world'  

faas-figlet-output

This is one of the simplest FaaS function you can build without coding!

Next

I am contemplating a build of a GPGPU function on a Swarm of Raspberry Pis maybe using https://github.com/mn416/QPULib or https://github.com/nineties/py-videocore:

The Pi contains 12 QPUs in total, each running at 250MHz. That's a max throughput of 750M vector instructions per second (250M cycles divided by 4 cycles-per-instruction times 12 QPUs). Or: 12B operations per second (750M instructions times 16 vector elements). QPU instructions can in some cases deliver two results at a time, so the Pi's QPUs are often advertised at 24 GFLOPS.

Acknowledgements

Thanks to @Alex Ellis for feedback on the post.

Comments

comments powered by Disqus