<?xml version='1.0' encoding='utf-8' ?>
<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1/'>
  <channel>
    <title>Wolfmans Howlings: Capistrano deploy from local repository</title>
    <link>http://blog.wolfman.com/articles/2006/5/26/capistrano-local-deploy-recipe</link>
    <description>A programmers Blog about Ruby, Rails and a few other issue</description>
    <language>en-us</language>
    <ttl>40</ttl>
    <item>
      <title>Capistrano deploy from local repository</title>
      <description>
        &lt;p&gt;&lt;em&gt;UPDATE&lt;/em&gt; 2006-12-06 I have replaced this with a full blown SCM module that works much better, see &lt;a href=&quot;http://blog.wolfman.com/articles/2006/12/06/a-capistrano-scm-module-for-local-svn-access&quot;&gt;this posting&lt;/a&gt;&lt;/p&gt;
        
        &lt;p&gt;It seems that many people are in the same position as I was, they want
        to deploy to a remote server farm that does not have access to the
        SCCM (subversion,CVS,perforce etc), which is usually behind a corporate firewall.&lt;/p&gt;
        
        &lt;p&gt;The following recipe overcomes this by checking out the source code
        from the local repository (using svn in this case) and goes into your
        deploy.rb.&lt;/p&gt;
        
        &lt;p&gt;What it does is checkout the latest copy of the application from your
        local subversion repository, tars it up, and copies the tar file to
        the remote server, then detars it and does the normal deploy tasks
        from then on.&lt;/p&gt;
        
        &lt;pre&gt;&lt;code&gt;desc &amp;lt;&amp;lt;DESC
        Update all servers with the latest release of the source code.
        This is a modified version that copies a local copy to the remote site
        DESC
        
        task :update_code, :roles =&amp;gt; [:app, :db, :web] do
            on_rollback { delete release_path, :recursive =&amp;gt; true }
        
            #puts &quot;doing my update_code&quot;
            temp_dest= &quot;tmp_code&quot;
        
            #puts &quot;...get a local copy of the code into #{temp_dest} from local svn&quot;
            # but this could also just be your local development folder
            system(&quot;svn export -q #{configuration.repository} #{temp_dest}&quot;)
        
            #puts &quot;...tar the folder&quot;
            # you could exclude files here that you don't want on your production server
            system(&quot;tar -C #{temp_dest} -c -z -f code_update.tar.gz .&quot;)
        
            #puts &quot;...Sending tar file to remote server&quot;
            put(File.read(&quot;code_update.tar.gz&quot;), &quot;code_update.tar.gz&quot;)
        
            #puts &quot;...detar code on server&quot;
            run &amp;lt;&amp;lt;-CMD
                mkdir -p #{release_path} &amp;amp;&amp;amp;
                tar -C #{release_path} -x -z -f code_update.tar.gz &amp;amp;&amp;amp;
                rm -rf code_update.tar.gz &amp;amp;&amp;amp;
                rm -rf #{release_path}/log #{release_path}/public/system &amp;amp;&amp;amp;
                ln -nfs #{shared_path}/log #{release_path}/log &amp;amp;&amp;amp;
                ln -nfs #{shared_path}/system #{release_path}/public/system
            CMD
        
            #puts &quot;...cleanup&quot;
            system(&quot;rm -rf #{temp_dest} code_update.tar.gz&quot;)
        end
        &lt;/code&gt;&lt;/pre&gt;
        
        &lt;p&gt;This recipe does what many people need todo which is replace the database.yml with the production version, and also repalces the .htaccess with the production version (YMMV)&lt;/p&gt;
        
        &lt;pre&gt;&lt;code&gt;desc &quot;fix up database and .htaccess&quot;
        task :after_update_code do
          run &quot;cp #{release_path}/config/database.yml.templ #{release_path}/config/database.yml&quot;
          run &quot;cp #{release_path}/public/dot.htaccess.deploy #{release_path}/public/.htaccess&quot;
        end
        &lt;/code&gt;&lt;/pre&gt;
      </description>
      <author>Jim Morris</author>
      <pubDate>Fri, 26 May 2006 17:08:00 -0700</pubDate>
      <link>http://blog.wolfman.com/articles/2006/5/26/capistrano-local-deploy-recipe</link>
      <guid isPermaLink='false'>urn:uuid:a34dca64fd0c31ef826145563d45bd57</guid>
    </item>
  </channel>
</rss>
