6094 comments
2357 subscribers
6250 on Twitter
Subscribe! Feed reader E-mail

Deploying to servers

I’m heading to the Philippines tomorrow, and to make life easer for the two other Windows-based PHP developers on my team, I updated the web-based deployment script I mentioned in
Development kaizen: deployment and testing. I added the ability to push a specified revision to the production server. It took me less time than I thought it would (I love it when things Just Work!), so I decided to spend time documenting it just in case I ever need to do it again (almost certainly) or just in case it breaks while I’m away (hope not).

Behind the scenes, there are a number of moving parts:

  • Key-based authentication. Because I need to copy files and run commands on the production and QA servers non-interactively, I needed to set up key-based authentication using SSH. I’m somewhat nervous about using a passphrase-less key, but I couldn’t see a way to work around this.
  • Rsync. I use rsync over ssh to transfer files to the remote system. It’s good at efficiently transferring changed files. I couldn’t use –delete to get rid of old files, though, as our source tree does not include the complete system.
  • A shell script with the suid bit. The shell script is responsible for exporting the requested revision to a temporary directory, rsyncing it over to the selected host, and running a few commands on the server in order to reset file permissions and clear the cache. The suid bit is there so that it takes my identity and uses the key that I set up. I resorted to suid because I couldn’t figure out how to make sure that Apache had its own key. I tried associating it with the user that Apache ran as, but I kept running into “no tty”-type errors. The suid workaround solved the problem quickly.
  • A PHP script that displays a form and the last 20 revisions. The form includes a drop-down box of the revisions displayed, a button for deploying to QA, and a button for deploying to the server. When submitted, the script does some error-checking, then uses system to call the relevant shell script. The script determines the list of revisions by using shell_exec to store the output of svn log … -limit 20 in a string, then using preg_match_all to match all instances of /r([0-9]+)/. Seems to work.
Short URL: http://sachachua.com/blog/p/5057
  • http://randell.ph/ randell

    OT: *points Sacha @ Facebook*

On This Day...

  • 2012: Learning more about Android development — From Tuesday: I spent most of the long weekend learning about Android development by working on the MobileOrg for Android [...]
  • 2011: Drupal: Overriding Drupal autocompletion to pass more parameters — Drupal autocompletion is easy – just add #autocomplete_path to a Form API element, set it to something that returns a [...]
  • 2010: Monthly review: July 2010 — Last month, I said: What will July be like? I want to polish my community toolkit and share it with more [...]
  • 2009: Improv: Catch 23′s Next Act, people-watching — Hat-tip to Taylor for telling me about Catch 23‘s improv event at the Comedy Bar last night. It was a [...]
  • 2009: The sweetness of life — W- and I made apricot syrup. It’s amazing. I’m tempted to go and make pancakes right now. I’m sure they’re fine for [...]
  • 2008: Drupal 5: Migrating a production database to a QA server — Building on the configuration management strategy I described last time, I wrote some scripts to make it easier for other [...]
  • 2007: I survived my defense! — zomg, I’m actually done with the defense. I need to make a few minor revisions, but the bulk of my work [...]
  • 2006: Raided the library — Having discovered the joys of the online book request system, I raided the library for 22 books on various topics including [...]
  • 2006: Time bubble — For some reason or another, my initial “Wow, this has been quite an eventful year” reflection included my stay in Japan. [...]
  • 2005: My Web 2.0 – Yahoo’s social search — Yahoo’s social search engine, My Web 2.0, certainly looks promising. It automatically picks up your Yahoo Messenger contacts and prioritizes their (and [...]
  • 2004: del.icio.us: sachac — http://del.icio.us/sachac: My del.icio.us page. New URLs will be posted there instead of on this blog, because blogging to del.icio.us is slightly more [...]
  • 2004: Myrkraverk’s box — -----BEGIN PGP MESSAGE----- Version: GnuPG v1.2.4 (GNU/Linux) hQEOAzQ6c9jHW5SMEAP/S9ch+peMGLyEn7Cmu0PdVIu3QW7XP75BJDypzQRzhOOh OwONxwtnH3yzkOfrwNxzQVPb5fyfWQgOjtlLZdPeDAxV8uBvj3ysmUwFH0SVSaKX O/wR0mr801hW1kbLR073+J8+Xvz5ioLb+3B1Kt1knaZ1U51XGxTieCaEQ3rpx94E AImExgp+j8Neuv40itenuroVSmM3uFAx1yCvlbc1pDAJOJp//X7AFRPsxwXxFidW rDHojDShCqGzy9CCQ10QfLdc1AswQIf1EP4V+BfYWp4Cg1byoBvjw0+2VEmuW196 rUh+8FyDUaigarCB64/M1fW6E2+0vNZ8SvG8bB77Z6MQ0mEBcuESqr1lrTDACIzs pGGuixg3TRzVflhH0Cf9jwid8je28gOqDUiGAhg/MGFQnroSpGfBVy/tqE227eRP mh6qnBpq9fBr0TcHPAhqjhghlmj7jP0WWl7i+LFZpAvhRRHc =c0jl -----END PGP MESSAGE-----
  • 2004: AOTS confirmed — Incidentally, I really _am_ going on the industry training trip to Japan. I’ll be leaving on August 25.

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging

Free sample!