Skip to content

Instantly share code, notes, and snippets.

@ktkaushik
Created May 3, 2012 09:15
Show Gist options
  • Select an option

  • Save ktkaushik/2584577 to your computer and use it in GitHub Desktop.

Select an option

Save ktkaushik/2584577 to your computer and use it in GitHub Desktop.
Capistrano steps
# Installation
gem install capistrano
# Setting up capistrano
# Go to your application directory in the terminal and run capify .
capify .
cap deploy:setup
# This is the first command you would want to run.
# What this is going to do is that, it will setup all of the configurations in place for you.
# Next up :
cap deploy:check
# This command would check all the configurations and generate any errors on the configurations
# point of view. You can then fix these issues regarding your VM before taking the final step.
cap deploy
# Finally, this would deploy.
# What happens when you cap deploy ?
cap deploy
# assume in your deploy.rb, you have
set :deploy_to, location
if folder is available at "deploy_to" location/shared/cached_copy
cd location/shared/cached_copy && perform a git fetch -q
# What does git fetch "-q" do ? Well, in simple terms, it would perform the fetch operation
# silently. It would basically silence / block / not perform any other git operations on that repo
# until this operation is completed.
&& git fetch --tags -q && git reset -q --hard
# git reset will reset your branch to the last commit and remove all the uncommitted changes you
# have performed in that particular branch quietly with "-q".
&& git clean -q -d -f -x
# git clean would remove all the untracked files from your respective branch.
# -d : remove directories as well.
# -f : force remove
# -x : Don't use the standard .gitgnore
else
&& git clone -q the repo && cd into the new clone && git checkout -b deploy "Some_code_in_hex"
end
# copying the cached version to Users/kaushik/dev/quadmint/releases/Some_code_in_hex_here
cp -RPp "path/to/cached_copy" "path/to/releases/Some_code_in_hex" && (echo "Some_another_code_in_hex" > /releases/Some_code_in_hex/REVISION)
# -R ::
# Copy the folder and subtree (recursive).
# If source_file designates a directory, cp copies the directory and
# the entire subtree connected at that point. If the source_file
# ends in a /, the contents of the directory are copied rather than
# the directory itself. This option also causes symbolic links to be
# copied, rather than indirected through, and for cp to create special
# files rather than copying them as normal files. Created
# directories have the same mode as the corresponding source directory,
# unmodified by the process' umask.
# -P ::
# No symbolic links are followed
# -p ::
# Cause cp to preserve the following attributes of each source file
# in the copy: modification time, access time, file flags, file mode,
# user ID, and group ID, as allowed by permissions.
# This callback would be called upon after this ::
deploy:finalize_update
rm -rf "releases/Some_code_in_hex/log" "releases/Some_code_in_hex/public/system" "releases/Some_code_in_hex/tmp/pids"
&& mkdir -p "/releases/Some_code_in_hex/public" "/releases/Some_code_in_hex/tmp" "/shared/log"
&& ln -s "/shared/log" "/releases/Some_code_in_hex/log" "/shared/system" "releases/Some_code_in_hex/public/system" "shared/pids" "releases/Some_code_in_hex/tmp/pids"
# ln creates a link and -s creates a symbloic link.
find "releases/Some_code_in_hex/public/images" "releases/Some_code_in_hex/public/stylesheets" "releases/Some_code_in_hex/public/javascripts"
# find the assets.
rm -f "/current/" && ln -s "releases/Some_code_in_hex/" "/current"
# make the latest code as the current code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment