2019-08-05 00:00:00 +0530
I bought a Raspberry Pi 3B+ some time ago to build a Home automation system, But came around Balena (https://www.balena.io/) It provides a infrastruture to develop, deploy and manage connected IoT (Internet of things) devices at scale! It is built for deploying containers, mostly focused on Containerization
Containerization is a lightweight alternative to full machine virtualization that involves encapsulating an application in a container with its own operating environment. This provides many of the benefits of loading an application onto a virtual machine, as the application can be run on any suitable physical machine without any worries about dependencies.
I will go ahead and explain the building blocks of the application.
The NodeJs project that i have used does a simple authentication with login/logout and creates users in a MONGODB database.
- A Node.js project which has to be deployed on the BalenaCloud.
- The Dockerfile
- The docker-compose.yaml
Two containers are created here
- NodeJS Container
- MongoDB database Container
What happens inside a Dockerfile ?
- We explicitly sepcify that we will be using the NODE image from “balenalib/raspberrypi3-node”
- In the Dockerfile we define the working directory for our application which will be used to store our NodeJs authentication module.
- The script then copies our code to the working directory.
- To build the node.js app we run “npm run install” or if you are using yarn “yarn install”
- We them export the port 80 for our node.js app, this will be the internal port for the docker used to communicate with other docker images.
- The script executes a command CMD [ “npm”, “start” ] to start the server.
Whats inside the docker-compose.yaml ?
- We define the version of our compose as 2, you can read more about it here https://docs.docker.com/compose/compose-file/compose-versioning/
- We then define two services here a) Web - We specify that this app depends on mongodb b) Mongo - We use mongodb image from “nonoroazoro/rpi-mongo” which is a custom built image for the raspberry pi architecture. As soon as we fire the script the mongodb image gets downloaded and starts on the port 27017.
Now this is a very simple example of what we can accomplish with Balena-Cloud for IoT. We do have a lot of ways of deploying apps like this usind different OS’s. We do have Ubuntu CORE! which gives an added advantage and more control in terms of the OS! plus the security for the IoT world.
Balena cloud supports a variety of devices and the link can be found here. https://www.balena.io/docs/reference/hardware/devices/
I have hosted the sample app that i created on GitHub. https://github.com/Anmol92verma/BalenaCloudRpi3Sample
Balena also provides a list of example here which can be deployed on your IoT devices. https://www.balena.io/docs/learn/getting-started/raspberrypi3/nodejs/#example-projects