Raspberry Pi Deployment Options
Here we analyze different options for automated deployments on the Raspberry Pi platform.
What we want is a workflow in which we develop locally on a computer and then update RPi instances over the air.
Using git
Raspberry Pi: Server
Create a directory where our app will be deployed:
mkdir -p ~/APPS/rpi_app
We create an empty git repository:
mkdir -p ~/rpi_app.git && cd ~/rpi_app.git
git init --bare
Create a post-receive hook so we can run after code is pushed:
nano ~/rpi_app.git/hooks/post-receive
After you are done with the script, make sure it is executable:
chmod +x ~/rpi_app.git/hooks/post-receive
You can use something like this:
#!/bin/sh
DEPLOYDIR=~/APPS/rpi_app
GIT_WORK_TREE="$DEPLOYDIR" git checkout -f
cd "$DEPLOYDIR"
pm2 stop rpi_app
npm install --production
pm2 start rpi_app
Development Machine
Now, we need to set up our development environment. Add your remote pi:
git remote add pi-remote pi@192.168.1.90:testing_app.git
To publish:
git push pi-remote
Downside is that you need to push to each remote device you have. If you have 10 pi you have to create 10 remotes.
With recent versions of git
you can add multiple remotes and push to all of them:
git remote set-url origin --push --add user1@repo1
git remote set-url origin --push --add user2@repo2
However, it seems that sometimes hooks fail to execute on a push.
You could create an alias:
[alias]
pushall = "!f(){ for i in `git remote`; do git push $i; done; };f"
Using Docker
resin.io
https://resin.io