Andrew Marconi

UX/Creative Technology Leadership

Git-Logo-2Color

12 June, 2014
by Andrew Marconi
0 comments

Deploying a git Repository with rsync and Tagging

Organizing the git Repository

Generally, I organize my digital projects according to this basic file structure:

File/Directory Description
01_Docs/ Documentation related to the project, if I’m not using the wiki services provided by a service such as GitHub or BitBucket.
02_Website/ The “rendered” site. This is the directory structure that gets deployed to my web host.
03_WebSource/ Any un-compiled source files (such as un-minified Javascript or CSS/LESS). The “rendered” files get pushed into the directory above.
99_Utility/ Any utility scripts.
README.md The requisite README file explaining the project.

Any additional components would be organized within the numbered directory scheme (for example, if there was a related desktop or mobile app, it would fall somewhere between the 01_Docs/ folder and 99_Utility/. All this is to say that it gives me a single directory that will be used to deploy from.

Deploying to Production

My go-to Bash script for deploying to production is (surprisingly enough) called deploy.sh, and it lives in the  99_Utility/ directory:

#!/bin/bash
DIR="$( dirname "${BASH_SOURCE[0]}" )" && pwd )/../02_Website/"
cd "$DIR"
TAGVERSION=$(date +Release-%Y.%m.%d-%Hh%Mm%Ss)
echo ""
echo "--> Tagging as $TAGVERSION and pushing to master repo..."
git tag $TAGVERSION
git push origin $TAGVERSION
echo ""
echo "--> Deploying to remote server using rsync..."
rsync -avzhe ssh --progress \
  --exclude cache/ --exclude templates_c/ \
  --delete . username@remotehost:directory

Let me step through each line of the script to explain what it does.

First, the cd command looks for where the script is located in my file system. This helps me avoid hard-coding a directory name, let’s me run it from any directory, and makes it portable to different environments (so if on one computer, the git repository is located in /opt/projects/projectname, but it’s under ~/projects/projectname on another computer, I don’t need to worry about it running correctly.

Next, I create a unique, human-readable tag name. Most projects involve version numbers in the tags. For me, tagging by release date/time works just fine… and let’s me automate it’s creation (removing the most error-prone variable from the equation… my own brain).

Why am I using tags this way? If something goes wrong, I can always see what the last deployment revision was, and easily undo the mistakes I’ve made… and it’s done automatically, so I can’t forget to do it. To grab a previous deployment, I simply run this command locally:

git fetch && git checkout tagname

After that, the two git commands create the tag based on the current codebase, and then pushes it to the remote master repository.

And now the fun part… rsync. This command tells the shell to synchronize my local files in the 02_Website/ folder to the remote host (obvs replace username, remotehost and the full directory path).

  • It will give you visual feedback as it works (–progress).
  • This sample project uses the Smarty PHP template engine, so there are two directories that exist for caching and pre-compiling of the templates, but I don’t want to sync them. The –exclude parameters handle that. You can have multiple –exclude parameters for multiple files/directories, or if there are a bunch of things you’d like to exclude use the –exclude-from parameter instead. See “Exclude multiple files and directories with rsync” for an excellent explanation of how to accomplish this. There are also special permissions on these two folders on my production host, so I don’t want to overwrite them, and foul things up.
  • The –delete parameter ensures that any files that are no longer of the site are removed from the remote server.

As an aside, I include the directories, but not the contents of my cache/ and templates_c/ folders. Since git won’t track an empty folder, the solution is to add a .gitignore file inside these directories with following contents:

*
!.gitignore

This forces git to record the directory, but not the files. This is a little trick I learned from a posting on StackOverflow.

That’s It.

And that’s all there is to it. It may not be the precise “proper” workflow, or the most efficient way, but it works for my needs and helps to lessen user error in the deployment process.

  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • PDF
  • RSS
  • Slashdot
  • Tumblr
webapps

10 September, 2010
by Andrew Marconi
2 Comments

Getting Started with iOS Web Applications: Block Best Practices

Being relatively new to building Web applications for iPhone, iPad and other Webkit/iOS browsers, I’ve been spending more and more time searching through the Apple Developer Safari Reference Library.

It’s a very complete resource, but so far, I’ve found it to be mildly frustrating for the beginner. For instance, constructing a basic <head> block requires referencing about 3-5 different pages in the Apple documentation (that don’t link together in a meaningful way), as well as a variety of third-party developers’ sites.
Continue Reading →

  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • PDF
  • RSS
  • Slashdot
  • Tumblr
paper-inbox

20 March, 2010
by Andrew Marconi
0 comments

Getting More Done, Mac Edition

Lately, I’ve started implementing David Allen’s GTD framework for “Getting Things Done.”

I’ve never been a huge fan of life coaches, “creative visualization to get what you want in life,” and all the touchy-feely “my parents didn’t give me ice cream once when I was five, so now I can’t have a serious relationship” communities led by “life gurus.” Mostly, I think they’re frauds that prey on the weak and vulnerable.
Continue Reading →

  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • PDF
  • RSS
  • Slashdot
  • Tumblr
AppleTV-XBMC-Boxee

3 December, 2009
by Andrew Marconi
3 Comments

Getting Boxee and XBMC Back after the Apple TV 3.0.1 Update

The Apple TV has a lot of potential. Unfortunately, it has some “features” that limit its usefulness out of the box. Thankfully, some really smart people have stepped in to leverage  third-party components, extending its capabilities that bring it one step closer to being a fantastic HTPC.
Continue Reading →

  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • PDF
  • RSS
  • Slashdot
  • Tumblr
adnetwork-optout

4 June, 2009
by Andrew Marconi
0 comments

Opt-Out of “Interest Based Ads” from Google and Other Ad Networks

While I don’t consider myself to be paranoid about being tracked around the Web, I still value my privacy. I also don’t like companies making money off of me (unless I’m getting a cut, of course) — and behaviorally-targeted ads have a higher value to advertisers, so DoubleClick (Google’s ad serving platform) and the other networks can charge more money.

Continue Reading →

  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • PDF
  • RSS
  • Slashdot
  • Tumblr
jquery

29 May, 2009
by Andrew Marconi
0 comments

Troubleshooting jQuery in WordPress Themes

Here’s another “oh yeah, I always forget about that” geek item.

I spent a few hours today going nuts trying to figure out why the jQuery Cycle plug-in wasn’t working in a new theme I’m working on. The code ran great outside of WordPress, but the minute I placed it inside the theme, it broke.

Then I realized: when using jQuery in WordPress you always have to remember to explicitly call it by name rather than use the handy-dandy $(“#identifier”) short-cut that every example and demo online uses. The long-winded reasoning (as I discovered thanks to Techxplorer’s blog entry) is that the bundled version of jQuery built into WordPress since version 2.2 is initialized with jQuery.noConflict. The upside is that this keeps the jQuery library from crashing into other bundled libraries (like Prototype). The bad news is that it breaks support for the $ shortcut.
Continue Reading →

  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • PDF
  • RSS
  • Slashdot
  • Tumblr
wordpress-theme-development-checklist-300x197

14 May, 2009
by Andrew Marconi
0 comments

WordPress Theme Check List/Cheat Sheet

Stefan Vervoort over at WPToy.com has published a great cheat sheet for developing WordPress themes. It’s available in PDF format, so as he suggests, if you build themes print it out and put it on your wall. When I’m building a WordPress theme, I always forget something along the line (when I go into “programmer mode” I get a little lazy sometimes, alright?) — this makes sure I cover off on all the elements.
Continue Reading →

  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • PDF
  • RSS
  • Slashdot
  • Tumblr