Deploying Resin.io projects is easy,
git push and you're done. But it's lacking a certain amount of ceremony.
I'm old enough (and scarred enough) to remember when it was common to provision your servers manually, to deploy your code over sFTP, and configure them via ssh. So being able to deploy an application to a £30 pocket sized computer with a single command still feels a little bit like magic.
Literally push to deploy ☢ 🏈
The final product. Toggling the switch on the left arms the system. Pushing the button on the right will deploy my application!
It's built around a Digispark, a tiny Arduino like development board with an Attiny85 based microcontroller. It's currently plugged into my Macbook via USB and the Macbook thinks it's a USB keyboard. This bit's important later.
- toggle switch, I used an illuminated toggle switch but you could go full missile control
- push to make button
- small project box or something to put all the parts in
- USB extension cord
Putting it together
The two red wires are going from the 5v pin on the Digispark to the power pin on the toggle switch, and from the ACC pin on the switch to the positive pin on the button.
The black wire is going from the ground pin on the switch to the ground pin on the Digispark.
Be careful if your Digispark suddenly gets very hot and smells like burning then you've accidentally bridged 5v and ground. Not that I've ever done that or anything…
Finally the blue wire connects the negative pin on the button to pin 0 on the Digispark.
So we're using the DigiKeyboard library to help us emulate a USB keyboard. In the main loop we check to see if the button is pressed and if it is then we send our keystroke, which in this case is going to be equivalent to the F3 key being pressed. To be honest the actual key we send doesn't matter.
delay tries to prevent us from triggering the deployment multiple times if our button press is a little long.
When is a keyboard not a keyboard?
So we've essentially built a single button keyboard, it might not seem that useful, but that's what USB Overdrive is for. Download and install the USB Overdrive preference pane and we can configure our new keyboard button.
We're going to execute a little bit of AppleScript which will display a notification and then force push our Resin.io project.
display notification "Deploying to Resin.io" sound name "Purr.aiff" do shell script "git -C /path/to/app push -f resin master"
Taking it further
If you have multiple Resin.io projects you could add more buttons to control each separately. Or you could have your button run a script to check for projects with un-pushed changes and deploy all of them with a single press.
If you install the Resin CLI you could have the button reboot (or even delete) devices for you.