Look a squirrel! Logo

Creating a launch button for Resin.io 🚀

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.

I can't work this magic box

Literally push to deploy ☢ 🏈

button is armed

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.

Parts list

You'll also need a Resin.io account and USB Overdrive installed.

Putting it together

wiring the power
please ignore my awful soldering

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.

adding ground wires

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…

final connection

Finally the blue wire connects the negative pin on the button to pin 0 on the Digispark.

Digispark code

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.

The 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.

find it in your system settings

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"

notification

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.

all of the buttons
control box goals

More from Look a squirrel!

Are Sketchnotes copyright infringement?

I recently read an interesting article by Jamie Knight about conference talks and copyright with regards to Sketchnotes. For anyone who is not familiar with the term, Sketchnotes are a...

See Article

Morseboard - Morse Code via your keyboard backlight

Because it's there – George Mallory As a developer sometimes it can be difficult to remember just because you can do something, does not always mean you should do something. With...

See Article