<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Finnian Anderson</title>
    <description>The latest articles on DEV Community by Finnian Anderson (@developius).</description>
    <link>https://dev.to/developius</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2421%2F6bbf224f-1dad-42c2-a913-a5318bb5e711.jpeg</url>
      <title>DEV Community: Finnian Anderson</title>
      <link>https://dev.to/developius</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/developius"/>
    <language>en</language>
    <item>
      <title>Colourising Video with Serverless Machine Learning</title>
      <dc:creator>Finnian Anderson</dc:creator>
      <pubDate>Fri, 10 Nov 2017 08:10:19 +0000</pubDate>
      <link>https://dev.to/developius/colourising-video-with-serverless-machine-learning-c8a</link>
      <guid>https://dev.to/developius/colourising-video-with-serverless-machine-learning-c8a</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was originally published on &lt;a href="https://finnian.io/blog/colourising-video-with-openfaas-serverless-functions/" rel="noopener noreferrer"&gt;my blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Earlier this year I saw a post on &lt;a href="http://mashable.com/2017/04/30/second-world-war-in-color/#rkolNHL3TmqM" rel="noopener noreferrer"&gt;Mashable&lt;/a&gt; which had some amazing photos from World War Two. They really bring the era to life so I was thinking about how we could automate the process of colourising photos and save a ton of ðŸ’° - it can cost up to Â£3k/minute to colourise video professionally.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://europe-2017.dockercon.com/" rel="noopener noreferrer"&gt;DockerCon EU&lt;/a&gt; was coming up and I really wanted to attend. My idea sounded like the perfect solution to my problem! Enlisting the help of my friend &lt;a href="https://twitter.com/olicallaghan_" rel="noopener noreferrer"&gt;Oli Callaghan&lt;/a&gt;, we started writing code. We tried a couple of different approaches, notably writing our own machine learning framework from scratch in C++ and training a tensorflow network. When it came down to it, these solutions were always limited by one thing: time. DockerCon was in a few weeks time and our networks were taking far too long to train (we're talking weeks).&lt;/p&gt;

&lt;p&gt;So, we were forced to go with another approach. We decided to build on &lt;a href="http://richzhang.github.io/colorization/" rel="noopener noreferrer"&gt;the work by Richard Zhang et al&lt;/a&gt; and use their prebuilt model to colourise our photos. We were able to successfully deploy their Caffe model at scale with the open source serverless framework &lt;a href="https://www.openfaas.com/" rel="noopener noreferrer"&gt;OpenFaaS&lt;/a&gt;. Using OpenFaaS allowed us to concentrate on the integration of the colourisation, instead of the underlying infrastructure.&lt;/p&gt;

&lt;p&gt;Having got the colourisation working in a serverless function, we decided to extend it so that our audience at DockerCon could get involved.&lt;/p&gt;

&lt;p&gt;Exploiting the flexibility of OpenFaaS, we wrote some extra serverless functions to allow people to tweet black and white images to &lt;a href="https://twitter.com/colorisebot" rel="noopener noreferrer"&gt;@colorisebot&lt;/a&gt; and for it to reply back with the colourised image.&lt;/p&gt;

&lt;p&gt;This is what our function stack looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffinnian.io%2Fblog%2Fcontent%2Fimages%2F2017%2F10%2FScreen-Shot-2017-10-19-at-01.57.29.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffinnian.io%2Fblog%2Fcontent%2Fimages%2F2017%2F10%2FScreen-Shot-2017-10-19-at-01.57.29.png" alt="Function stack"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Some pretty awesome tried out our bot at the DockerCon afterparty, including the one and only &lt;a href="https://twitter.com/ChloeCondon" rel="noopener noreferrer"&gt;Chloe Condon&lt;/a&gt; and &lt;a href="https://twitter.com/jonasrosland" rel="noopener noreferrer"&gt;Jonas Rosland&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-920741455253164032-672" src="https://platform.twitter.com/embed/Tweet.html?id=920741455253164032"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-920741455253164032-672');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=920741455253164032&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;Okay, so we can colourise photos. However, our main goal was always to colourise videos. How did this go? Pretty well!&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/K4QVi-BSjGw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Here's how it works. We simply split the video up into frames and then drop them into the OpenFaaS function stack, gather up the colourised frames and stitch them back together with ffmpeg.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffinnian.io%2Fblog%2Fcontent%2Fimages%2F2017%2F10%2FScreen-Shot-2017-10-19-at-20.51.03.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffinnian.io%2Fblog%2Fcontent%2Fimages%2F2017%2F10%2FScreen-Shot-2017-10-19-at-20.51.03.png" alt="Colourising video"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Community
&lt;/h1&gt;

&lt;p&gt;The OpenFaaS community has been very supportive of us, helping test, develop and inspire Oli and I to keep improving the project. Although the original idea was ours, the development and deployment has been a group effort.&lt;/p&gt;

&lt;p&gt;In particular, we'd like to say a massive thank you to OpenFaaS's project lead, &lt;a href="https://twitter.com/alexellisuk" rel="noopener noreferrer"&gt;Alex Ellis&lt;/a&gt; for his continued help and support. He's been a great mentor, giving us invaluable advice on various different aspects varying from presentation guidance to OpenFaaS setup and configuration. He's even written a &lt;a href="https://github.com/faas-and-furious/autocolour" rel="noopener noreferrer"&gt;neat function which normalises the images&lt;/a&gt; to help with the sepia effect which has given great results.&lt;/p&gt;

&lt;p&gt;Alex has just launched the idea of "Pods" in the OpenFaaS community. This is an idea to help manage the work on the project and decentralise leadership. Alex writes:&lt;/p&gt;

&lt;p&gt;Pods are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;7 +/- 2 people&lt;/li&gt;
&lt;li&gt;Mixed ability&lt;/li&gt;
&lt;li&gt;Gravitate to areas of the project that interest them the most&lt;/li&gt;
&lt;li&gt;Get special mentions in GitHub issues, PRs and release notes&lt;/li&gt;
&lt;li&gt;Work collaboratively or independently&lt;/li&gt;
&lt;li&gt;Are represented by a Pod Advocate who is willing to commit to give time to the Pod and the project&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'm really excited about this idea and look forward to joining a pod!&lt;br&gt;
The OpenFaaS community is very inclusive and friendly, if you're interested in getting involved just ping an email to &lt;a href="mailto:alex@openfaas.com"&gt;alex@openfaas.com&lt;/a&gt; and he'll get you added to the Slack group.&lt;/p&gt;

&lt;h1&gt;
  
  
  Sum up
&lt;/h1&gt;

&lt;p&gt;Feel free to have a play with &lt;a href="https://twitter.com/colorisebot" rel="noopener noreferrer"&gt;@colorisebot&lt;/a&gt; on twitter and let us know what you think!&lt;/p&gt;

&lt;p&gt;The code is all open source (checkout the original post &lt;a href="https://finnian.io/blog/colourising-video-with-openfaas-serverless-functions/" rel="noopener noreferrer"&gt;here&lt;/a&gt;) so take a look and have a hack.&lt;/p&gt;

&lt;p&gt;I've got a cool little grafana dashboard linked up to the OpenFaaS Prometheus metrics so I can see what's going on in real time. Incidentally, this weekend has been a very busy period for the bot, racking up over 1130 colourised images on Twitter! I've put together a collection of the best here: &lt;a href="https://storify.com/developius/best-of-colorisebot" rel="noopener noreferrer"&gt;https://storify.com/developius/best-of-colorisebot&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fqjif667n1yssxovcogab.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fqjif667n1yssxovcogab.png" alt="Can @colorisebot be called "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Next steps
&lt;/h1&gt;

&lt;p&gt;In the future we'd like to run the conversions on GPUs so that we can leverage the power of graphics processors to run our network even faster. We think we can decrease execution time by a factor of 100 (5s -&amp;gt; 50ms) by using a GPU.&lt;/p&gt;

&lt;p&gt;We'd also like to try running our network on a recurrent network, which learns from the frames that came before the current one. This should help with the video conversion which appears to flicker because some of the frames are slightly incorrect.&lt;/p&gt;

&lt;p&gt;Our slides are available &lt;a href="https://www.slideshare.net/Docker/repainting-the-past-with-distributed-machine-learning-and-docker" rel="noopener noreferrer"&gt;here&lt;/a&gt; and you can watch &lt;a href="https://dockercon.docker.com/watch/1sEyvPTJuVUADbbLYJLpi8" rel="noopener noreferrer"&gt;our DockerCon talk here&lt;/a&gt;. Oli has also &lt;a href="http://olicallaghan.com/post/repainting-the-past-with-machine-learning-and-openfaas" rel="noopener noreferrer"&gt;written a post&lt;/a&gt; about the ins and outs (pun intended) of machine learning and also goes over how we adapted our program for video.&lt;/p&gt;

</description>
      <category>openfaas</category>
      <category>serverless</category>
      <category>machinelearning</category>
      <category>docker</category>
    </item>
    <item>
      <title>OpenFaaS - deploying serverless functions to Docker Swarm via a CLI</title>
      <dc:creator>Finnian Anderson</dc:creator>
      <pubDate>Thu, 18 May 2017 21:52:02 +0000</pubDate>
      <link>https://dev.to/developius/functions-as-a-service---deploying-functions-to-docker-swarm-via-a-cli</link>
      <guid>https://dev.to/developius/functions-as-a-service---deploying-functions-to-docker-swarm-via-a-cli</guid>
      <description>&lt;h1&gt;
  
  
  OpenFaaS
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://openfaas.com" rel="noopener noreferrer"&gt;Functions as a Service&lt;/a&gt; or OpenFaaS (lead by &lt;a href="https://twitter.com/alexellisuk" rel="noopener noreferrer"&gt;Alex Ellis&lt;/a&gt;) is a really neat way of implementing serverless functions with Docker. You can build out functions in any programming language and then deploy them to your existing Docker Swarm.&lt;/p&gt;

&lt;p&gt;In this post we'll look at a CLI for making this process even easier.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj931i7mg6khc8b01tx27.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj931i7mg6khc8b01tx27.png" width="800" height="1015"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://asciinema.org/a/141284" rel="noopener noreferrer"&gt;Demo&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenFaaS highlights
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The only serverless framework for both Docker Swarm and Kubernetes&lt;/li&gt;
&lt;li&gt;Easy to use - deploy in 60 seconds, UI and CLI built-in&lt;/li&gt;
&lt;li&gt;Supports code or binaries in any language on Windows or Linux&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Getting up and running
&lt;/h1&gt;

&lt;p&gt;To run functions with OpenFaaS, you'll first need to deploy an OpenFaaS cluster to a Docker Swarm. This is really simple, just follow the steps over on the &lt;a href="https://github.com/openfaas/faas/blob/master/guide/deployment_swarm.md" rel="noopener noreferrer"&gt;deployment guide&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  How it works
&lt;/h1&gt;

&lt;p&gt;The diagram below gives an overview of how the OpenFaaS function packages, the Docker image, and the &lt;code&gt;faas-cli deploy&lt;/code&gt; command fit together.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_g7x-UpA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://finnian.io/blog/content/images/2017/05/Screen-Shot-2017-05-02-at-15.12.45.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_g7x-UpA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://finnian.io/blog/content/images/2017/05/Screen-Shot-2017-05-02-at-15.12.45.png" alt="The OpenFaaS CLI makes it easy to deploy your functions!" width="729" height="212"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To deploy a function onto an OpenFaaS stack, you firstly must write the function itself. This is really easy and you can do it in any language which runs inside Docker (i.e. all of them). At the current time, the OpenFaaS CLI supports Python and Node, so for this example we'll use Python.&lt;/p&gt;

&lt;p&gt;My very simple fib function is written in Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;st&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;st&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code is saved in &lt;code&gt;sample/fib/handler.py&lt;/code&gt;. It's important to create a &lt;code&gt;requirements.txt&lt;/code&gt; file in the same directory (even if your Python code has no requirements from pip) because otherwise &lt;code&gt;pip install&lt;/code&gt; will throw an error.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building the function package
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zeeB13z0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://finnian.io/blog/content/images/2017/05/FaaS-function-diagrams.001.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zeeB13z0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://finnian.io/blog/content/images/2017/05/FaaS-function-diagrams.001.jpeg" alt="OpenFaaS deploy overview" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The way FaaS runs the function is by running this inside Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;function&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;handler&lt;/span&gt;
&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stdin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you build a function with the OpenFaaS CLI, what it's doing is packaging up your function (&lt;code&gt;handler.py&lt;/code&gt;) and building out the parts for Docker to run the container.&lt;/p&gt;

&lt;p&gt;The last step is to write the &lt;code&gt;stack.yml&lt;/code&gt; file which FaaS will use to build and deploy the function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;provider&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;faas&lt;/span&gt;
  &lt;span class="na"&gt;gateway&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;http://localhost:8080&lt;/span&gt; &lt;span class="c1"&gt;# your faas stack url&lt;/span&gt;

&lt;span class="na"&gt;functions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;fib&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;lang&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;python&lt;/span&gt;
    &lt;span class="na"&gt;handler&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./sample/fib&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;developius/func_python-fib&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To build the package, simply run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ faas-cli  build -f ./stack.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is an example package for our &lt;code&gt;func_python-fib&lt;/code&gt; function, located inside &lt;code&gt;faas-cli&lt;/code&gt;'s &lt;code&gt;build&lt;/code&gt; directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;tree build/fib/
build/fib/
â”œâ”€â”€ Dockerfile
â”œâ”€â”€ &lt;span class="k"&gt;function
&lt;/span&gt;â”‚Â Â  â”œâ”€â”€ handler.py         &amp;lt;&lt;span class="nt"&gt;--&lt;/span&gt; called by index.py
â”‚Â Â  â””â”€â”€ requirements.txt
â”œâ”€â”€ index.py               &amp;lt;&lt;span class="nt"&gt;--&lt;/span&gt; Docker runs this
â””â”€â”€ requirements.txt

1 directory, 5 files
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The package includes everything to allow Docker to run our function - &lt;code&gt;Dockerfile&lt;/code&gt;, &lt;code&gt;index.py&lt;/code&gt; and &lt;code&gt;handler.py&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploying the function
&lt;/h2&gt;

&lt;p&gt;Now that our function is built, we need to deploy it. Before we do this however, we must push our function to the hub so that all the nodes in the swarm can access it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker push developius/func_python-fib
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now for the deploy! This can be done with one command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;faas-cli deploy &lt;span class="nt"&gt;-f&lt;/span&gt; ./stack.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you run this command, the function will be deployed to the remote Docker Swarm. How cool is that?&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing
&lt;/h2&gt;

&lt;p&gt;The final thing to do is to test your function deployed successfully. You can do this via the OpenFaaS UI or via &lt;code&gt;curl&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--otagmXjm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://finnian.io/blog/content/images/2017/05/Screen-Shot-2017-05-01-at-21.23.26.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--otagmXjm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://finnian.io/blog/content/images/2017/05/Screen-Shot-2017-05-01-at-21.23.26.png" alt="Testing via the FaaS UI" width="800" height="572"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or, via curl:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ curl -d "10" http://localhost:8080/function/fib
0, 1, 1, 2, 3, 5, 8, 13, 21, 34
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  High Availability via autoscaling
&lt;/h2&gt;

&lt;p&gt;FaaS supports Docker Swarm's replication feature, which allows auto scaling of functions directly inside Docker. OpenFaaS makes use of this internally to make sure enough function replicas are available to deal with requests. It works by exporting metrics for &lt;a href="https://prometheus.io/" rel="noopener noreferrer"&gt;Prometheus&lt;/a&gt;, which then generates alerts when thresholds are reached. The FaaS gateway will then scale up the functions when it receives these alerts.&lt;/p&gt;

&lt;p&gt;This can be seen perfectly in the screenshot of my Grafana dashboard below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fky1v70irvo1qogil1ni3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fky1v70irvo1qogil1ni3.png" alt="Autoscaling within OpenFaaS" width="800" height="313"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Recap
&lt;/h2&gt;

&lt;p&gt;In this post we've seen how to package and deploy a function using the FaaS framework. We've looked at how to write a function, how to build it into a function package and deploy it to a remote Docker Swarm. Pretty neat stuff.&lt;/p&gt;

&lt;p&gt;I've built a &lt;a href="https://github.com/alexellis/faas/blob/master/community.md" rel="noopener noreferrer"&gt;number of other functions&lt;/a&gt; and hope to expand this to include more soon. I wrote a function to shorten URLs, using &lt;a href="https://finnian.io/blog/a-url-shortener-written-in-ten-minutes/" rel="noopener noreferrer"&gt;a service I built&lt;/a&gt;, which received a PR from &lt;a href="https://twitter.com/rgee0" rel="noopener noreferrer"&gt;Richard Gee&lt;/a&gt; to merge in an armhf Dockerfile for use on Raspberry Pies. This was a big milestone for me as I've never accepted a PR for one of my projects before!&lt;/p&gt;

&lt;p&gt;You can find out more about the projects I've been doing with Docker on my blog at &lt;a href="https://finnian.io/blog" rel="noopener noreferrer"&gt;finnian.io/blog&lt;/a&gt; - including &lt;a href="https://finnian.io/blog/dockercon-2017-highlights-and-experiences/" rel="noopener noreferrer"&gt;my DockerCon 2017 writeup&lt;/a&gt;! Feel free to get in touch on Twitter &lt;a href="https://twitter.com/developius" rel="noopener noreferrer"&gt;@developius&lt;/a&gt; and I'd love to hear your thoughts below.&lt;/p&gt;

&lt;p&gt;Props to &lt;a href="https://twitter.com/alexellisuk" rel="noopener noreferrer"&gt;Alex Ellis&lt;/a&gt; for creating such an awesome tool, I look forward to participating in the development of FaaS in the future. It's worth noting that FaaS is currently considered experimental but you can expect more language templates amongst some other neat features. First... learn Go. ðŸ™ˆ&lt;/p&gt;

</description>
      <category>docker</category>
      <category>faas</category>
      <category>serverless</category>
      <category>openfaas</category>
    </item>
  </channel>
</rss>
