Starting a project on Resin

 
 

Balena.io Docker and Gitflow Continuous Deployment for Raspberry Pi and other Edge devices
https://www.balena.io/static/ecosystem-c8f031071c57ecb4606a46b9136551b8.png

https://www.balena.io/blog/resin-io-changes-name-to-balena-releases-open-source-edition/

 

Resin.io changed name to Balena but its principles stays the same, and its concepts to develop on linux edge devices such as Raspberry Pis just like we push  software in continuous deployment in the cloud (fully automated with Git).


With Balena, you can update your code and push it to all your devices, directly from git. This was very difficult before due to the different hardware environment of many Iot devices (lots of different processors - ARM - Intel ....that needed cross compilation of code). 

Now you can manage fleets of devices with different architecture and manage cross compilation on the fly on the cloud, simply by pushing your code on Github.

 

https://docs.resin.io/raspberrypi3/python/getting-started/#using-the-web-terminal

1) First step to start working on a RESIN project

- Clone the project on your computer

- Add the resin git remote endpoint by running the command git remote add shown in the top-right corner of your application page

git remote add resin user_toto@git.resin.io:user_toto/my_app.git

when we push new changes to this remote repository it will get compiled and built on our servers and deployed to every device in the application fleet.


$ git push resin master

Just as we will do to update our repository on github, 
we will do git addgit commitgit push to deploy our code to the devices connected on RESIN.


2) A python Resin project using python has 3 files

Dockerfile.template
The main docker file that will provision and install the Container with all the applications that needs to be installed.
(the .template is used for Resin engine to parse variables inside the dockerfile and adapt to the device:
for exemple %%RESIN_MACHINE_NAME%% place holder gets stripped and replaced with the resin device name, so that the same repository is used for various devices that can have different hardware)

requirements.txt
The list of all Python libraries dependancies that needs to be installed for the project to run perfectly

src/main.py
The main entry point to our application code: once the container is properly setup, this script will be exectuted



3) Access devices and develop faster

Using Resin.io pannel, we can open a teminal by clicking on a connected device.

From the terminal: install resin cli

$ npm install --global --production resin-cli
$ resin login


Each time we want to sync scripts files on our machines without going through the whole container deploy script:

$ resin sync --source . --destination /usr/src/app


It should prompt you to select a device, then it will sync all the files in the root of your directory to /usr/src/app on your selected device and finally it will restart the container. 
Notes:
It is not possible(~easy) to install dependencies using resin sync. So if you need to do an apt-get or add something to either your Dockerfilepackage.json or requirements.txt, then you will need to go through the standard git push resin master build pipeline.
If you know the device UUID you can just run: resin sync
Provided you are already logged in on the CLI and you have a device online, you can use resin ssh  to access the container. Here is an example:

Commentaires