<?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>Jonathan Spooner is a Web Developer in the San Diego Area. &#187; ec2onrails</title>
	<atom:link href="http://www.jonathanspooner.com/tag/ec2onrails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jonathanspooner.com</link>
	<description>Flex Developer, Air Developer, and ActionScript Programmer</description>
	<lastBuildDate>Thu, 31 Mar 2011 16:02:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Deploying a Rails app to Amazon EC2 with Capistrano</title>
		<link>http://www.jonathanspooner.com/web-development/deploying-a-rails-app-to-amazon-ec2-with-capistrano/</link>
		<comments>http://www.jonathanspooner.com/web-development/deploying-a-rails-app-to-amazon-ec2-with-capistrano/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 18:30:38 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[ec2onrails]]></category>

		<guid isPermaLink="false">http://www.jonathanspooner.com/?p=557</guid>
		<description><![CDATA[@esilverberg originally posted this article that I've been referring to for the past year and now wanted to contribute some updates of my own.
Get the code
Arr!  There are some problems with checking out code from github with SVN.  I'll fix this soon but if your reading today modify deploy.rb to deploy from git.
We're [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://twitter.com/esilverberg">@esilverberg</a> originally posted <a href="http://www-cs-students.stanford.edu/~silver/ec2.html">this article</a> that I've been referring to for the past year and now wanted to contribute some updates of my own.</p>
<h2>Get the code</h2>
<p>Arr!  There are some problems with checking out code from github with SVN.  I'll fix this soon but if your reading today modify deploy.rb to deploy from git.</p>
<p>We're going to deploy my <a href="http://github.com/jspooner/authlogic_cucumber_rspec_example">stub site</a> from github and we'll check it out with SubVersion</p>
<pre class="bash">&nbsp;
svn checkout  http://svn.github.com/jspooner/authlogic_cucumber_rspec_example.git basic
<span style="color: #7a0874; font-weight: bold;">cd</span> basic
&nbsp;</pre>
<p>You probably want to get the project running locally.  Hopefully you have the mysql driver installed or you can edit the database.yml file to use sqlite.</p>
<pre class="bash">&nbsp;
rake db:create
rake db:migrate
rake db:seed
script/server
&nbsp;</pre>
<h2>EC2 setup</h2>
<ol>
<li>Read the <a href="http://docs.amazonwebservices.com/AmazonEC2/gsg/2006-06-26/">getting started guide here</a> at amazon.</li>
<li>Install the developer tools.  I have them located at
<pre>ec2-ami-tools-1.3-45758</pre>
</li>
<li>Make sure you have downloaded the cert- and pk- .pem files. I have them in ~/.ec2/</li>
</ol>
<h3>Setup environment variables</h3>
<p>Probably want to put these in your .bashrc or .bash_profile with the 'export' command in front.</p>
<pre class="bash">&nbsp;
     <span style="color: #007800;">EC2_CERT=</span>/home/USER/.ec2/cert-EZC7LAIYSKPC546UKT7E3PI.pem
     <span style="color: #007800;">EC2_HOME=</span>/home/USER/ec2-api-tools<span style="color: #000000;">-1.3</span><span style="color: #000000;">-30349</span>
     <span style="color: #007800;">EC2_PRIVATE_KEY=</span>/home/USER/.ec2/pk-EZC7LAIYSKPC546UKT7EUEOOI.pem
     <span style="color: #007800;">PATH=</span><span style="color: #007800;">$PATH</span>:<span style="color: #007800;">$EC2_HOME</span>/bin
&nbsp;</pre>
<h3>Verify dev tools</h3>
<p>Run this to make sure it works:
<pre class="bash">ec2-describe-images ami-5394733a</pre>
<h3>Start up an instance</h3>
<ol>
<li>Click "Launch Instance" https://console.aws.amazon.com/ec2/home<br />
<a href="http://www.jonathanspooner.com/blog/wp-content/uploads/2010/04/Screen-shot-2010-04-29-at-10.54.01-AM.png"><img src="http://www.jonathanspooner.com/blog/wp-content/uploads/2010/04/Screen-shot-2010-04-29-at-10.54.01-AM.png" alt="" title="Screen shot 2010-04-29 at 10.54.01 AM" width="420" height="164" class="alignnone size-full wp-image-582" /></a>
</li>
<li>Click "Community AMI's" and select one of the AMI's listed when you ran cap ec2onrails:ami_ids.  I'm using ami-5394733a
<p><a href="http://www.jonathanspooner.com/blog/wp-content/uploads/2010/04/Screen-shot-2010-04-29-at-11.21.46-AM.png"><img src="http://www.jonathanspooner.com/blog/wp-content/uploads/2010/04/Screen-shot-2010-04-29-at-11.21.46-AM-150x150.png" alt="" title="Screen shot 2010-04-29 at 11.21.46 AM" width="150" height="150" class="alignnone size-thumbnail wp-image-589" /></a></p>
</li>
<li>Select an instance size and continue.<br />
<a href="http://www.jonathanspooner.com/blog/wp-content/uploads/2010/04/Screen-shot-2010-04-29-at-11.22.38-AM.png"><img src="http://www.jonathanspooner.com/blog/wp-content/uploads/2010/04/Screen-shot-2010-04-29-at-11.22.38-AM-150x150.png" alt="" title="Screen shot 2010-04-29 at 11.22.38 AM" width="150" height="150" class="alignnone size-thumbnail wp-image-592" /></a>
</li>
<li>Advanced Instance Options.  Click Continue.<br />
<a href="http://www.jonathanspooner.com/blog/wp-content/uploads/2010/04/Screen-shot-2010-04-29-at-11.25.30-AM.png"><img src="http://www.jonathanspooner.com/blog/wp-content/uploads/2010/04/Screen-shot-2010-04-29-at-11.25.30-AM-150x150.png" alt="" title="Screen shot 2010-04-29 at 11.25.30 AM" width="150" height="150" class="alignnone size-thumbnail wp-image-593" /></a></li>
<li>Create a new Key Pair named testkey and click download.  Move this file to ~/.ssh/testkey.pem and chmod the key to 600.
<pre class="bash">&nbsp;
   <span style="color: #c20cb9; font-weight: bold;">mv</span> testkey.pem ~/.<span style="color: #c20cb9; font-weight: bold;">ssh</span>/testkey.pem
   <span style="color: #7a0874; font-weight: bold;">cd</span> ~/.<span style="color: #c20cb9; font-weight: bold;">ssh</span>/
   <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">600</span> testkey.pem
   <span style="color: #c20cb9; font-weight: bold;">ls</span> -al
&nbsp;</pre>
<p>You should see the file permissions set to -rw-------<br />
This key is used to SSH into your instance and is used set on line 13 of deploy.rb.</p>
<pre class="ruby">ssh_options[:keys] = ["#{ENV['HOME']}/.ssh/testkey.pem"]</pre>
</li>
<li>Create a new Security Group and rules for HTTP HTTPS & SSH.<br />
<a href="http://www.jonathanspooner.com/blog/wp-content/uploads/2010/04/Screen-shot-2010-04-29-at-11.31.20-AM.png"><img src="http://www.jonathanspooner.com/blog/wp-content/uploads/2010/04/Screen-shot-2010-04-29-at-11.31.20-AM-150x150.png" alt="" title="Screen shot 2010-04-29 at 11.31.20 AM" width="150" height="150" class="alignnone size-thumbnail wp-image-594" /></a>
</li>
<li>Verify your settings and Launch the Instance<br />
<a href="http://www.jonathanspooner.com/blog/wp-content/uploads/2010/04/Screen-shot-2010-04-29-at-11.32.19-AM.png"><img src="http://www.jonathanspooner.com/blog/wp-content/uploads/2010/04/Screen-shot-2010-04-29-at-11.32.19-AM-150x150.png" alt="" title="Screen shot 2010-04-29 at 11.32.19 AM" width="150" height="150" class="alignnone size-thumbnail wp-image-595" /></a></li>
<li>After you instance has launched find the Public DNS that looks something like this ec2-xxx-xxx-xx-xxx.compute-1.amazonaws.com and add that to you deploy.rb file on lines 18-21</li>
</ol>
<h3> Update tools on the image </h3>
<p>ssh into the machine and run the following</p>
<pre class="bash">
ssh -i ~/.ssh/testkey.pem root@ec2-xxx-xxx-xx-xxx.compute-1.amazonaws.com
sudo apt-get update
sudo apt-get -y install build-essential
sudo apt-get -y install emacs22
sudo gem update --system
</pre>
<p>The <a href="http://www-cs-students.stanford.edu/~silver/ec2.html">original post</a> had you installing imagemagick with apt-get but that wan't pulling the latest version; which the rmagick gem requires.  So here we will pull down the latest version and install from source.</p>
<pre class="bash">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span>://<span style="color: #c20cb9; font-weight: bold;">ftp</span>.imagemagick.org/pub/ImageMagick/ImageMagick.<span style="color: #c20cb9; font-weight: bold;">tar</span>.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> -zxvf ImageMagick.<span style="color: #c20cb9; font-weight: bold;">tar</span>.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> ImageMagick<span style="color: #000000;">-6.6</span><span style="color: #000000;">.1</span><span style="color: #000000;">-5</span>/
./configure
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span>
gem <span style="color: #c20cb9; font-weight: bold;">install</span> rmagick
ldconfig /usr/<span style="color: #7a0874; font-weight: bold;">local</span>/lib
&nbsp;</pre>
<h3>Set up capistrano and <a href="http://ec2onrails.rubyforge.org/">ec2onrails</a></h3>
<p><a href="http://www.capify.org/index.php/Capistrano">Capistrano</a> is a tool for automating tasks on one or more remote servers.  We are going to use it to push our site up to EC2 with the help of the <a href="http://ec2onrails.rubyforge.org/">ec2onrails</a> gem.</p>
<pre class="bash">
capify .
gem install ec2onrails
</pre>
<p>Open Capfile and require ec2onrails.</p>
<pre class="bash">require 'ec2onrails/recipes'</pre>
<p>Open deploy.rb and replace with this.</p>
<pre class="ruby">&nbsp;
<span style="color:#008000; font-style:italic;"># This is a sample Capistrano config file for EC2 on Rails.</span>
<span style="color:#008000; font-style:italic;"># It should be edited and customized.</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:application</span>, <span style="color:#996600;">&quot;basic&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:user</span>, <span style="color:#996600;">&quot;root&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:use_sudo</span>, <span style="color:#0000FF; font-weight:bold;">true</span>
set <span style="color:#ff3333; font-weight:bold;">:repository</span>, <span style="color:#996600;">&quot;http://svn.github.com/jspooner/authlogic_cucumber_rspec_example.git &quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># NOTE: for some reason Capistrano requires you to have both the public and</span>
<span style="color:#008000; font-style:italic;"># the private key in the same folder, the public key should have the</span>
<span style="color:#008000; font-style:italic;"># extension &quot;.pub&quot;.</span>
ssh_options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:keys</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;#{ENV['HOME']}/.ssh/testkey.pem&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Your EC2 instances. Use the ec2-xxx....amazonaws.com hostname, not</span>
<span style="color:#008000; font-style:italic;"># any other name (in case you have your own DNS alias) or it won't</span>
<span style="color:#008000; font-style:italic;"># be able to resolve to the internal IP address.</span>
role <span style="color:#ff3333; font-weight:bold;">:web</span>,      <span style="color:#996600;">&quot;ec2-xx-xx-xx-xx.compute-1.amazonaws.com&quot;</span>
role <span style="color:#ff3333; font-weight:bold;">:app</span>,      <span style="color:#996600;">&quot;ec2-xx-xx-xx-xx.compute-1.amazonaws.com&quot;</span>
role <span style="color:#ff3333; font-weight:bold;">:db</span>,       <span style="color:#996600;">&quot;ec2-xx-xx-xx-xx.compute-1.amazonaws.com&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:primary</span> =&gt; <span style="color:#0000FF; font-weight:bold;">true</span>
role <span style="color:#ff3333; font-weight:bold;">:memcache</span>, <span style="color:#996600;">&quot;ec2-xx-xx-xx-xx.compute-1.amazonaws.com&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Whatever you set here will be taken set as the default RAILS_ENV value</span>
<span style="color:#008000; font-style:italic;"># on the server. Your app and your hourly/daily/weekly/monthly scripts</span>
<span style="color:#008000; font-style:italic;"># will run with RAILS_ENV set to this value.</span>
set <span style="color:#ff3333; font-weight:bold;">:rails_env</span>, <span style="color:#996600;">&quot;production&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># EC2 on Rails config.</span>
<span style="color:#008000; font-style:italic;"># NOTE: Some of these should be omitted if not needed.</span>
set <span style="color:#ff3333; font-weight:bold;">:ec2onrails_config</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>
  <span style="color:#008000; font-style:italic;"># S3 bucket and &quot;subdir&quot; used by the ec2onrails:db:restore task</span>
  <span style="color:#008000; font-style:italic;"># :restore_from_bucket =&gt; &quot;your-bucket&quot;,</span>
  <span style="color:#008000; font-style:italic;"># :restore_from_bucket_subdir =&gt; &quot;database&quot;,</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># S3 bucket and &quot;subdir&quot; used by the ec2onrails:db:archive task</span>
  <span style="color:#008000; font-style:italic;"># This does not affect the automatic backup of your MySQL db to S3, it's</span>
  <span style="color:#008000; font-style:italic;"># just for manually archiving a db snapshot to a different bucket if</span>
  <span style="color:#008000; font-style:italic;"># desired.</span>
  <span style="color:#008000; font-style:italic;"># :archive_to_bucket =&gt; &quot;your-other-bucket&quot;,</span>
  <span style="color:#008000; font-style:italic;"># :archive_to_bucket_subdir =&gt; &quot;db-archive/#{Time.new.strftime('%Y-%m-%d--%H-%M-%S')}&quot;,</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Set a root password for MySQL. Run &quot;cap ec2onrails:db:set_root_password&quot;</span>
  <span style="color:#008000; font-style:italic;"># to enable this. This is optional, and after doing this the</span>
  <span style="color:#008000; font-style:italic;"># ec2onrails:db:drop task won't work, but be aware that MySQL accepts</span>
  <span style="color:#008000; font-style:italic;"># connections on the public network interface (you should block the MySQL</span>
  <span style="color:#008000; font-style:italic;"># port with the firewall anyway).</span>
  <span style="color:#008000; font-style:italic;"># If you don't care about setting the mysql root password then remove this.</span>
  <span style="color:#ff3333; font-weight:bold;">:mysql_root_password</span> =&gt; <span style="color:#996600;">&quot;blamblam12343&quot;</span>,
&nbsp;
  <span style="color:#008000; font-style:italic;"># Any extra Ubuntu packages to install if desired</span>
  <span style="color:#008000; font-style:italic;"># If you don't want to install extra packages then remove this.</span>
  <span style="color:#ff3333; font-weight:bold;">:packages</span> =&gt; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;logwatch&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
&nbsp;
  <span style="color:#008000; font-style:italic;"># Any extra RubyGems to install if desired: can be &quot;gemname&quot; or if a</span>
  <span style="color:#008000; font-style:italic;"># particular version is desired &quot;gemname -v 1.0.1&quot;</span>
  <span style="color:#008000; font-style:italic;"># If you don't want to install extra rubygems then remove this</span>
  <span style="color:#ff3333; font-weight:bold;">:rubygems</span> =&gt; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;rails -v 2.3.5&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
&nbsp;
  <span style="color:#008000; font-style:italic;"># Set the server timezone. run &quot;cap -e ec2onrails:server:set_timezone&quot; for</span>
  <span style="color:#008000; font-style:italic;"># details</span>
  <span style="color:#ff3333; font-weight:bold;">:timezone</span> =&gt; <span style="color:#996600;">&quot;Canada/Eastern&quot;</span>,
&nbsp;
  <span style="color:#008000; font-style:italic;"># Files to deploy to the server (they'll be owned by root). It's intended</span>
  <span style="color:#008000; font-style:italic;"># mainly for customized config files for new packages installed via the</span>
  <span style="color:#008000; font-style:italic;"># ec2onrails:server:install_packages task. Subdirectories and files inside</span>
  <span style="color:#008000; font-style:italic;"># here will be placed in the same structure relative to the root of the</span>
  <span style="color:#008000; font-style:italic;"># server's filesystem.</span>
  <span style="color:#008000; font-style:italic;"># If you don't need to deploy customized config files to the server then</span>
  <span style="color:#008000; font-style:italic;"># remove this.</span>
  <span style="color:#008000; font-style:italic;"># :server_config_files_root =&gt; &quot;../server_config&quot;,</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># If config files are deployed, some services might need to be restarted.</span>
  <span style="color:#008000; font-style:italic;"># If you don't need to deploy customized config files to the server then</span>
  <span style="color:#008000; font-style:italic;"># remove this.</span>
  <span style="color:#ff3333; font-weight:bold;">:services_to_restart</span> =&gt; %w<span style="color:#006600; font-weight:bold;">&#40;</span>apache2 postfix sysklogd<span style="color:#006600; font-weight:bold;">&#41;</span>,
&nbsp;
  <span style="color:#008000; font-style:italic;"># Set an email address to forward admin mail messages to. If you don't</span>
  <span style="color:#008000; font-style:italic;"># want to receive mail from the server (e.g. monit alert messages) then</span>
  <span style="color:#008000; font-style:italic;"># remove this.</span>
  <span style="color:#ff3333; font-weight:bold;">:admin_mail_forward_address</span> =&gt; <span style="color:#996600;">&quot;me@gmail.com&quot;</span>,
&nbsp;
  <span style="color:#008000; font-style:italic;"># Set this if you want SSL to be enabled on the web server. The SSL cert</span>
  <span style="color:#008000; font-style:italic;"># and key files need to exist on the server, The cert file should be in</span>
  <span style="color:#008000; font-style:italic;"># /etc/ssl/certs/default.pem and the key file should be in</span>
  <span style="color:#008000; font-style:italic;"># /etc/ssl/private/default.key (see :server_config_files_root).</span>
  <span style="color:#ff3333; font-weight:bold;">:enable_ssl</span> =&gt; <span style="color:#0000FF; font-weight:bold;">false</span>
<span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;</pre>
<p>Be sure to customize those files and read the comments.</p>
<p>Now run cap -T and you should see all the <a href="http://ec2onrails.rubyforge.org/">ec2onrails</a> tasks like this.</p>
<p>Also, use the hostname “db_primary” in your database.yml file. After running “cap ec2onrails:server:set_roles” it will resolve to the instance defined in your Capistrano “db” role.</p>
<h3>Deploy the site</h3>
<pre class="bash">
cap ec2onrails:setup
cap ec2onrails:db:set_root_password
cap deploy:cold
</pre>
<p>That should be it!  Now goto http://ec2-xxx-xxx-xx-xxx.compute-1.amazonaws.com and your site should be running.</p>
<hr/>
<h2>Extended Set Up</h2>
<p>This was a very basic set up and you will want to customize your installation. </p>
<h3>Cron services</h3>
<p>EC2onrails lets you do hourly and daily cron tasks, but not more frequent<br />
than that. I installed craken and have this in my deploy.rb to compensate:</p>
<pre class="ruby">&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:craken</span> <span style="color:#9966CC; font-weight:bold;">do</span>
	desc <span style="color:#996600;">&quot;Install raketab&quot;</span>
	task <span style="color:#ff3333; font-weight:bold;">:install</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> =&gt; <span style="color:#ff3333; font-weight:bold;">:cron</span> <span style="color:#9966CC; font-weight:bold;">do</span>
		set <span style="color:#ff3333; font-weight:bold;">:rails_env</span>, <span style="color:#996600;">&quot;production&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span>
		exists?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:rails_env</span><span style="color:#006600; font-weight:bold;">&#41;</span>
		set <span style="color:#ff3333; font-weight:bold;">:env_args</span>, <span style="color:#006600; font-weight:bold;">&#40;</span>exists?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:env_args</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? env_args :<span style="color:#996600;">&quot;app_name=#{application} deploy_path=#{current_path}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
			run <span style="color:#996600;">&quot;cd #{current_path} &amp;&amp; rake #{env_args} RAILS_ENV=#{rails_env} craken:install&quot;</span>
			<span style="color:#9966CC; font-weight:bold;">end</span>
			task <span style="color:#ff3333; font-weight:bold;">:uninstall</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> =&gt; <span style="color:#ff3333; font-weight:bold;">:cron</span> <span style="color:#9966CC; font-weight:bold;">do</span>
				set <span style="color:#ff3333; font-weight:bold;">:rails_env</span>, <span style="color:#996600;">&quot;production&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> exists?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:rails_env</span><span style="color:#006600; font-weight:bold;">&#41;</span>
				set <span style="color:#ff3333; font-weight:bold;">:env_args</span>, <span style="color:#006600; font-weight:bold;">&#40;</span>exists?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:env_args</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? env_args :<span style="color:#996600;">&quot;app_name=#{application} deploy_path=#{current_path}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
				run <span style="color:#996600;">&quot;cd #{current_path} &amp;&amp; rake #{env_args} RAILS_ENV=#{rails_env} craken:uninstall; true&quot;</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
before <span style="color:#996600;">&quot;deploy:symlink&quot;</span>, <span style="color:#996600;">&quot;craken:uninstall&quot;</span>
after <span style="color:#996600;">&quot;deploy:symlink&quot;</span>, <span style="color:#996600;">&quot;craken:install&quot;</span>
&nbsp;</pre>
<p>You can see more about the <a href="http://capitate.rubyforge.org/recipes/deploy.html">capistrano events here</a>. The recipe was taken <a href="http://github.com/latimes/craken/blob/5aa07b47cca7eab925fca714a160eedc6164bc20/recipes/craken.rb">from here</a>.</p>
<h2>Gotchas</h2>
<ul>
<li>Don't forget to open up port 443 on Amazon's management console if<br />
  you need ssl support</li>
<li><a href="http://groups.google.com/group/ec2-on-rails-discuss/browse_thread/thread/79b60bf683b2365b">Follow these instructions</a> to configure your SSL certs</li>
<li>Setting up <a href="http://codeintensity.blogspot.com/2009/03/deploying-per-server-crontabs-with.html">cron is described here</a></li>
<li>If you include submodules you can't do the git shallow copy</li>
</ul>
<h2>Useful links</h2>
<ul>
<li><a href="http://ec2onrails.rubyforge.org/">EC2 on Rails</a></li>
<li><a href="http://github.com/guides/deploying-with-capistrano">Getting<br />
 it working with github</a> (has some useful stuff about capistrano)</li>
<li><a<br />
  href="http://kumaria.blogspot.com/2008/12/rails-deployment-capistrano-github.html">Random<br />
  guy talking about what he did</a></li>
<li><a href="https://console.aws.amazon.com/ec2/home">The amazon ec2<br />
  console</a></li>
<li><a<br />
  href="http://www.zabada.com/tutorials/deploying-a-rails-application-to-production-on-amazon-ec2.php">Another<br />
  guy deploys ec2 on rails</a></li>
<li><a href="http://thinkrefresh.com/posts/9-starling-workling-capistrano-tasks">Starling and workling capistrano tasks</a></li>
</ul>
<h2>Advanced - Setting up a db server</h2>
<ul>
<li>Setup a cool mysql server backed by EBS here: <a<br />
href="http://developer.amazonwebservices.com/connect/entry.jspa?categoryID=100&externalID=1663">http://developer.amazonwebservices.com/connect/entry.jspa?categoryID=100&externalID=1663</a></li>
<li>This server only has a root user, but capistrano needs an admin user<br />
that is capable of sudoing...d'oh! You have to do the<br />
following:</li>
</ul>
<pre class="bash">
adduser admin
</pre>
<p>Now, add your public keypair via these instructions here:<br />
<a href="http://blogs.techrepublic.com.com/opensource/?p=86">blogs.techrepublic.com.com</a></p>
<p>I think you have to manually copy the keypair; who knows where it is on<br />
the system??</p>
<p>Now, add the admin user to the /etc/sudoers file so it is what capistrano<br />
is expecting. </p>
<pre class="bash">
# The 'admin' user can run sudo without a password<br/>
admin   ALL=(ALL) NOPASSWD: ALL
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanspooner.com/web-development/deploying-a-rails-app-to-amazon-ec2-with-capistrano/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

