A good programmer is a lazy programmer...

/ Edit this post / code

They say "A good programmer is a lazy programmer..." - That may be true, however I would like to turn the negative into a positive and change the phrase to "A good programmer is an efficient programmer..."

I love patterns. I see them all the time. Throughout music, throughout code, throughout life in general. They're litterally everywhere and I am constantly on the lookout for them. Today I found myself repeating the same task/pattern over and over again and I was curious to see how much time it was actually taking up throughout my day.

Problem:

So the task at hand was to deploy 17 repositories to heroku at the same time and verify that they are deployed and running by simply viewing them in a browser. Pretty simple, right? Yes, simple is NOT the issue at hand, time is. Time is everything when it comes to getting work done, so be sure to use it wisely, as I'm pretty sure you will not get any of it back...

Solution:

Write a simple Shell script that will do the following:

Navigate to 17 local repositories

$ cd ~/path/of/my/local/repositories

Deploy each property to heroku / github / some cloud based git service (in my case, heroku)

$ git push heroku master

Then confirm the site is running and deployed by opening it physically in Google Chrome like so

$ open -a Google\ Chrome http://nameofmyawesomedomain.com

And finally, (optionally) print out some console confirmation that the script completed

$ echo "Deploy complete"

My Script

(Most likley this will not help you, but have a look anyway...)

#!/bin/bash
 
echo "Deploying admityouhaveaproblem..."
cd ~/Heroku/admityouhaveaproblem.github.io && git push heroku master
open -a Google\ Chrome http://admityouhaveaproblem.com
echo "Deploy complete"
 
echo "Deploying ColorMyMusic..."
cd ~/Heroku/ColorMyMusic.github.io && git push heroku master
open -a Google\ Chrome http://colormymusic.com
echo "Deploy complete"
 
echo "Deploying beforeidiei..."
cd ~/Heroku/beforeidiei.github.io && git push heroku master
open -a Google\ Chrome http://beforeidiei.com
echo "Deploy complete"
 
echo "Deploying convoclothing..."
cd ~/Heroku/convoclothing.github.io && git push heroku master
open -a Google\ Chrome http://convoclothing.com
echo "Deploy complete"
 
echo "Deploying getanintern..."
cd ~/Heroku/getanintern.github.io && git push heroku master
open -a Google\ Chrome http://getanintern.com
echo "Deploy complete"
 
echo "Deploying getgearly..."
cd ~/Heroku/getgearly.github.io && git push heroku master
open -a Google\ Chrome http://getgearly.com
echo "Deploy complete"
 
echo "Deploying hissio..."
cd ~/Heroku/hissio.github.io && git push heroku master
open -a Google\ Chrome http://hiss.io
echo "Deploy complete"
 
echo "Deploying jogbuy..."
cd ~/Heroku/jogbuy.github.io && git push heroku master
open -a Google\ Chrome http://jogbuy.com
echo "Deploy complete"
 
echo "Deploying kissvote..."
cd ~/Heroku/kissvote.github.io && git push heroku master
open -a Google\ Chrome http://kissvote.com
echo "Deploy complete"
 
echo "Deploying kywrd..."
cd ~/Heroku/kywrd && git push production master
open -a Google\ Chrome http://kywrd.com
echo "Deploy complete"
 
echo "Deploying latched..."
cd ~/Heroku/latched.github.io && git push heroku master
open -a Google\ Chrome http://getlatched.com
echo "Deploy complete"
 
echo "Deploying madstory..."
cd ~/Heroku/madstory.github.io && git push heroku master
open -a Google\ Chrome http://madstory.com
echo "Deploy complete"
 
echo "Deploying meetsme..."
cd ~/Heroku/meetsme.github.io && git push heroku master
open -a Google\ Chrome http://meetsme.com
echo "Deploy complete"
 
echo "Deploying neighborhoodly..."
cd ~/Heroku/neighborhoodly.github.io && git push heroku master
open -a Google\ Chrome http://neighborhood.ly
echo "Deploy complete"
 
echo "Deploying picksomeone..."
cd ~/Heroku/picksomeone.github.io && git push heroku master
open -a Google\ Chrome http://picksomeone.com
echo "Deploy complete"
 
echo "Deploying rehearseio..."
cd ~/Heroku/rehearseio.github.io && git push heroku master
open -a Google\ Chrome http://rehearse.io
echo "Deploy complete"
 
echo "Deploying youmeyoume..."
cd ~/Heroku/youmeyoume.github.io && git push heroku master
open -a Google\ Chrome http://youmeyoume.com
echo "Deploy complete"

Save the above as deploy_script.sh and then set the permissions to be executable:

$ chmod +x ./deploy_script.sh

Next run the script:

$ ./deploy_script.sh

Conclusion

Now, before writing this simple Shell script, this process was taking up about an hour of my time each and every day (I'm doing the 365 Days of Open Source Contributions). Clearly this was not something that I enjoyed, nor was it even remotely sustainable.

By writing a script, I can now deploy code in less than 30 seconds.

Video Proof

Save yourself some time and write shell scripts locally, or possibly consider using Alfred Mac App.

Happy coding!

Eric David Smith

Father / Software Engineer / Musician / Recording Engineer / Navy Veteran / Runner / Javascript / Crypto / Human ETH: 0xa9FFaD2A2cA147F784f4C82Ee6475afb6765A974

Read More