<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Zownir Enterprises &#187; Capistrano</title>
	<atom:link href="http://zownir.net/tag/capistrano/feed" rel="self" type="application/rss+xml" />
	<link>http://zownir.net</link>
	<description></description>
	<lastBuildDate>Mon, 10 May 2010 09:02:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Rails and Git</title>
		<link>http://zownir.net/2008/03/16/rails-and-git</link>
		<comments>http://zownir.net/2008/03/16/rails-and-git#comments</comments>
		<pubDate>Mon, 17 Mar 2008 02:00:00 +0000</pubDate>
		<dc:creator>Ronnie Zownir</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Mongrel]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[My notes from Scott Chacon&#8217;s screencast. You should check it out for yourself. It is definitely well worth your time. Instantiate a git repository with a newly minted rails app. rails railsapp &#38;&#38; cd railsapp git init-db touch .gitignore Add the following lines to .gitignore: config/database.yml tmp/* log/* Add all the files to the repository [...]]]></description>
			<content:encoded><![CDATA[<p>My notes from <a href="http://jointheconversation.org/railsgit">Scott Chacon&#8217;s screencast</a>. You should check it out for yourself. It is definitely well worth your time.</p>
<h3>Instantiate a git repository with a newly minted rails app.</h3>
<pre><code>rails railsapp &amp;&amp; cd railsapp
git init-db
touch .gitignore
</code></pre>
<p>Add the following lines to <code>.gitignore</code>:</p>
<pre><code>config/database.yml
tmp/*
log/*
</code></pre>
<p>Add all the files to the repository and commit all.</p>
<pre><code>git add .
git status # To check the status of the working copy.
git commit -a -m "Initial commit"
git log # To see the log for the repository.
</code></pre>
<h3>Create a remote git repository from the one just created.</h3>
<pre><code>cd ..
git clone --bare railsapp/.git railsapp.git
scp -r railsapp.git username@remote-machine:/home/username/git-repos
cd railsapp
git remote add gitserver username@remote-machine:/home/username/git-repos/railsapp.git
</code></pre>
<p>Replace <code>gitserver</code> with a name you want to reference the remote machine by. Make sure that the path to the <code>git</code> binaries is defined in <code>~/.bashrc</code> and not <code>~/.bash_profile</code> because remote commands load the former and not the latter. Information about the remote is added in the <code>git</code> config.</p>
<pre><code>git push gitserver # Push the code in local repository to gitserver
</code></pre>
<p>On the remote machine, in railsapp.git:</p>
<pre><code>export GIT_DIR=.
git log
</code></pre>
<h3>Branching and merging in git.</h3>
<pre><code>git branch -a # Show all git branches (including the remote machine).
git branch # Show all local git branches.
git checkout -b experimental # Create and switch to new branch "experimental".
git checkout master # Switch back to master branch.
git checkout experimental # Switch back to experimental branch.
</code></pre>
<p>To merge experimental into master:</p>
<pre><code>git checkout master # Switch to the master branch as the working copy.
git pull . experimental # Does a fetch and then a merge; you could just merge.
git add filenameinconflict # Fix files in conflict and then do a git add.
git commit -a # After merging do a commit.
</code></pre>
<p>After merging the experimental branch into master, we&#8217;re finished with it so we can delete its identifier. The branch&#8217;s change history will still be there but the branch name is gone. To do so:</p>
<pre><code>git branch -d experimental
git branch # See that the branch name is deleted.
gitk --all&amp; # Visualize the change history using a TK GUI.
</code></pre>
<h3>Database</h3>
<h4>database.yml</h4>
<pre><code>development:
  adapter: sqlite3
  database: db/development.sqlite3

test:
  adapter: sqlite3
  database: db/test.sqlite3

production:
  adapter: mysql
  encoding: utf8
  host: localhost
  database: production_db_name
  username: mysql_username
  password: mysql_password
</code></pre>
<h3>Mongrel Cluster</h3>
<h4>mongrel_cluster.yml</h4>
<pre><code>---
user: user
group: user
environment: production
address: 127.0.0.1
port: 3000
servers: 2
cwd: /home/user/webapps/railsapp/current
log_file: log/mongrel.log
pid_file: tmp/pids/mongrel.pid
</code></pre>
<h3>Capistrano</h3>
<p>In railsapp, execute:</p>
<pre><code>capify .
</code></pre>
<h4>Capfile</h4>
<pre><code>load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy'
load 'config/mongrel' # mongrel overrides
</code></pre>
<h4>deploy.rb</h4>
<pre><code>set :application, "railsapp"
set :repository,  "user@webxx.webfaction.com:/home/user/git-repos/railsapp.git"
set :domain, "webxx.webfaction.com"
set :deploy_to, "/home/user/webapps/#{application}"
set :mongrel_conf, "#{current_path}/config/mongrel_cluster.yml"
set :scm, :git
set :deploy_via, :remote_cache
ssh_options[:paranoid] = false
set :user, "user"
set :runner, "user"
set :use_sudo, false
role :app, domain
role :web, domain
role :db,  domain, :primary =&gt; true

# If the production web server doesn't have access to your git server,
# add the following two lines.
set :deploy_via, :copy # instead of :remote_cache
set :git_shallow_clone, 1 # optional, but makes things faster

# moves over server config files after deploying the code
task :update_config, :roles =&gt; [:app] do
  run "cp -Rf #{shared_path}/config/* #{release_path}/config/"
end
after 'deploy:update_code', :update_config
</code></pre>
<h4>mongrel.rb</h4>
<pre><code># mongrel-based overrides of the default tasks

namespace :deploy do
  namespace :mongrel do
    [ :stop, :start, :restart ].each do |t|
      desc "#{t.to_s.capitalize} the mongrel appserver"
      task t, :roles =&gt; :app do
        #invoke_command checks the use_sudo variable to determine how to run the mongrel_rails command
        invoke_command "mongrel_rails cluster::#{t.to_s} -C #{mongrel_conf}", :via =&gt; run_method
      end
    end
  end

  desc "Custom restart task for mongrel cluster"
  task :restart, :roles =&gt; :app, :except =&gt; { :no_release =&gt; true } do
    deploy.mongrel.restart
  end

  desc "Custom start task for mongrel cluster"
  task :start, :roles =&gt; :app do
    deploy.mongrel.start
  end

  desc "Custom stop task for mongrel cluster"
  task :stop, :roles =&gt; :app do
    deploy.mongrel.stop
  end

end
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://zownir.net/2008/03/16/rails-and-git/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
