Swim, Frameworks, and Containers: Putting It All Together

by Brad Johnson, on May 24, 2019 11:52:56 AM

I’ve written previously about Scott Clarke’s Greenhouse demo app because it’s a good example of how to build integrations between external frameworks and Swim. While Swim functions perfectly well on its own (for an app built using only Swim’s own UI and server libraries, you can check out traffic.swim.ai), sometimes it makes sense to utilize a framework to speed development or simplify the learning curve. Popular frameworks like AngularJS, NodeJS, ReactJS and others have many pre-built connectors, vibrant developer ecosystems, and abundant developer resources available for reference. Swim makes it easy to take advantage of these frameworks, enabling developers to integrate one or more UI and server frameworks together into a shared data fabric.


Look at this absolute unit.

Using Swim with UI and Server Frameworks

In the Greenhouse demo app, Scott used NodeJs to provide a standard interface to a web application. Scott describes that “Node is used to serve the various status pages used by the web app and as a data bridge from the sensors into Swim. Unlike a traditional web application where all the pages are hosted in a central place, Swim web applications can be hosted from each device. This ensures the UI is showing the real time data possible without the latency of being routed through various databases and/or cloud services.” In this way, it’s possible to leverage Swim’s efficient state management and consistency model, while still getting the benefit of the NodeJS ecosystem. The same is true for integrating Swim and any number of available open source libraries.

Using Swim with Docker and Containers

You can also use Swim to integrate with external platforms to offload the management of deployment, leverage a third-party device management console, or integrate with a proprietary system. Scott utilized Docker containers to simplify deployment of his Greenhouse demo. He includes a set of instructions for deploying his Greenhouse application using Docker in his README on GitHub. All the code required to deploy and run this application is located in this repository, including the Docker files. You will need to be running in a Unix like environment to be able to run this demo as well as Docker. Scott uses both Debian and Ubuntu, but you are not limited to just those distributions. He advises that “for Windows, you can setup an compatible environment inside a VM, or in either the Windows Subsystem for Linux or Cygwin. It is important to note If you are running Windows 10 Home you may have problems getting Docker to run and it may be easier to just run Docker on your Pi.”

Scott includes instructions for building Docker images:

To build Docker images:

Screen Shot 2019-05-24 at 11.42.29 AM

As well as for running Docker images:

All command line parameters are required with the exception of --privileged which is only required for SenseHat so that python can communicate with the the SenseHat hardware. You can debug an image by adding --entrypoint=/bin/bash. This will run the image and drop you into the bash shell of the running image. From there you can run npm, gradle, or python directly. Just remember that changes made inside an image will  be saved between runs.

Screen Shot 2019-05-24 at 11.42.38 AM

You can find Scott's complete instructions over on GitHub.

Learn More

Swim is an Open Source platform for building distributed real-time applications. For technical resources, you can find out more about Swim here.

Topics:Stateful ApplicationsSWIM Inc.SWIM AIdevopsdistributed computingserverlessweb applicationsswimOSnodejs