bjo0 / VaporberryPi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Introduction

This is a demo for getting Vapor running on a Raspberry Pi using swift 4.1.1 from the swift-arm port.

Getting Started

Develop on desktop, run on RaspberryPi

Steps to do on your Raspberry Pi

  1. Setup your Raspberry Pi with Raspbian Stretch
  2. Enable ssh
  3. Install swift 4.1.1 from the swift-arm port
  4. 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
  5. 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)
  6. Clone your bare git repo to create a working git repo, e.g. git clone ssh://pi@localhost/git/VaporberryPi.git ~/VaporberryPi

Steps to do on your desktop computer

  1. Clone VaporberryPi from the bare repo on your Raspberry Pi, e.g. git clone ssh://pi@raspberrypi.local/git/VaporberryPi.git
  2. Change current directory to your VaporberryPi clone, e.g. cd VaporberryPi
  3. Use ssh to connect to your Raspberry Pi to confirm the connection, e.g. ssh pi@raspberrypi.local -- hostname
  4. 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
  5. Open a web browser and go to http://raspberrypi.local:8080
    • Confirm output: "It works!"

Next Steps

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.

Appendix

post-receive hook example

This post-receive hook:

  1. changes the active directory to the working git repo,
  2. fetches new changes from the bare repo and resets its state to match,
  3. 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

Vapor

API Template

Documentation Team Chat MIT License Continuous Integration Swift 4.1

About


Languages

Language:Swift 64.1%Language:Shell 19.6%Language:Dockerfile 16.4%