27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

402 CHAPTER 14 Deployment<br />

executing locally: "git ls-remote [git_path] HEAD"<br />

* executing "git clone -q [git_path] [release_path] &&<br />

cd [release_path] &&<br />

git checkout -q -b deploy [SHA1 hash] &&<br />

(echo [SHA1 hash] > [release_path]/REVISION)"<br />

servers: ["your-server"]<br />

This task first runs git ls-remote, a lesser-known Git command, locally (not on the<br />

server), which will get the current SHA for HEAD, the latest commit to the master<br />

branch, unless you set a branch in Capistrano’s configuration.<br />

The next thing Capistrano does is put the current revision in a file called<br />

REVISION. If you like, you can alter the layout of your application to read the value<br />

from this file and put it in your application’s layout as a HTML comment so that when<br />

you do a deploy to the server, you can check this hash to see if it is the latest code.<br />

The next couple of lines output from cap deploy are from the beginning of the<br />

deploy:finalize_update task:<br />

* executing "chmod -R g+w [release_path]"<br />

servers: ["localhost"]<br />

[localhost] executing command<br />

command finished<br />

With this chmod command, Capistrano ensures that your new release’s directory is<br />

group writable (g+w), allowing the user/group to make any modifications to this<br />

directory they like, barring all others.<br />

Finally, the deploy:finalize_update then removes the log, public/system, and<br />

tmp/pids directories and symbolically links the shared/log, shared/system, and<br />

shared/pids directories (in your application’s deployed path) to these paths respectively.<br />

It does that in this little series of commands:<br />

* executing "rm -rf [release_path]/log<br />

[release_path]/public/system<br />

[release_path]/tmp/pids &&<br />

mkdir -p [release_path]/public &&<br />

mkdir -p [release_path]/tmp &&<br />

ln -s [shared_path]/log [release_path]/log &&<br />

ln -s [shared_path]/system [release_path]/public/system &&<br />

ln -s [shared_path]/pids [release_path]/tmp/pids<br />

servers: ["your-server"]<br />

[your-server] executing command<br />

command finished<br />

Next, Capistrano will use the find command to touch every file in the public/images,<br />

public/stylesheets, and public/javascripts to update their last modified time. This is so<br />

that when a user visits your site they get the latest image, stylesheet, or JavaScript file<br />

rather than a cached file. It does this with this part of the output:<br />

* executing "find [release_path]/public/images<br />

[release_path]/public/stylesheets<br />

[release_path]/public/javascripts<br />

-exec touch -t [timestamp] {} ';'; true"

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!