This is a demo for getting Vapor running on a Raspberry Pi using swift 4.1.1 from the swift-arm port.
- Setup your Raspberry Pi with Raspbian Stretch
- Enable ssh
- Set up passwordless ssh access to avoid entering password
- Install swift 4.1.1 from the swift-arm port
- Clone a bare git repo, e.g.
sudo mkdir /git && sudo git clone --bare ssh://pi@raspberrypi.local/git/VaporberryPi.git /git/VaporberryPi.git && sudo chown -R pi:pi /git
- Add a post-receive hook script to your bare git repo that runs when you push new code to it (see post-receive hook example in Appendix)
- Clone your bare git repo to create a working git repo, e.g.
git clone ssh://pi@localhost/git/VaporberryPi.git ~/VaporberryPi
- Clone VaporberryPi from the bare repo on your Raspberry Pi, e.g.
git clone ssh://pi@raspberrypi.local/git/VaporberryPi.git
- Change current directory to your VaporberryPi clone, e.g.
cd VaporberryPi
- Use ssh to connect to your Raspberry Pi to confirm the connection, e.g.
ssh pi@raspberrypi.local -- hostname
- Push to your bare repo:
git push origin
- Confirm in the
git push origin
output that the project builds and runs successfully on the Raspberry Pi
- Confirm in the
- Open a web browser and go to http://raspberrypi.local:8080
- Confirm output: "It works!"
John Woolsey trailblazed this topic with Controlling A Raspberry Pi From A Web Browser With Vapor 3. Check it out for a tutorial on next steps, like how to integrate an LED into the program.
This post-receive hook:
- changes the active directory to the working git repo,
- fetches new changes from the bare repo and resets its state to match,
- executes the Procfile script and logs its output to a file in /tmp.
$ chmod +x /git/VaporberryPi.git/hooks/post-receive
$ ls -ld /git/VaporberryPi.git/hooks/post-receive
-rwxr-xr-x 1 pi pi 254 Mar 10 14:11 /git/VaporberryPi.git/hooks/post-receive
$ cat /git/VaporberryPi.git/hooks/post-receive
#!/bin/bash -e
code_dir=~/VaporberryPi
cd "$code_dir"
git --git-dir "$code_dir/.git" --work-tree "$code_dir" fetch --all origin master
git --git-dir "$code_dir/.git" --work-tree "$code_dir" reset --hard origin/master
git --git-dir "$code_dir/.git" --work-tree "$code_dir" clean --force
log=/tmp/"$(basename "$code_dir")"-post-receive.log
./Procfile | tee "$log"
exit