<?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>pastbedti.me &#187; deploy</title>
	<atom:link href="http://www.pastbedti.me/tag/deploy/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pastbedti.me</link>
	<description>About ruby, rails, postgresql and stuff....</description>
	<lastBuildDate>Fri, 02 Apr 2010 20:12:14 +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 Sinatra app with Apache and Phusion Passenger a.k.a. mod_rack</title>
		<link>http://www.pastbedti.me/2009/11/deploying-a-sinatra-app-with-apache-and-phusion-passenger-a-k-a-mod_rack/</link>
		<comments>http://www.pastbedti.me/2009/11/deploying-a-sinatra-app-with-apache-and-phusion-passenger-a-k-a-mod_rack/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 22:01:30 +0000</pubDate>
		<dc:creator>Mathias Stjernström</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Sinatra]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[deploy]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[webroot]]></category>

		<guid isPermaLink="false">http://www.pastbedti.me/?p=610</guid>
		<description><![CDATA[My Sinatra + Apache + Passenger setup did not just run  
Deploying a simple Sinatra rack application under Apache and Phusion Passenger turned out not work out of the box for me. 
I already had a virtual host so I decided to deploy with passengers sub URI (sub URI documentation).
To make this work you&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<h3>My Sinatra + Apache + Passenger setup did not just run <img src='http://www.pastbedti.me/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </h3>
<p>Deploying a simple Sinatra rack application under Apache and Phusion Passenger turned out not work out of the box for me. </p>
<p>I already had a virtual host so I decided to deploy with passengers sub URI (<a href="http://www.modrails.com/documentation/Users%20guide.html#deploying_rack_to_sub_uri" target="_blank">sub URI documentation</a>).</p>
<p>To make this work you&#8217;ll need Apache installed with Phusion Passenger setup (<a href="http://www.modrails.com/install.html" target="_blank">Passenger installation</a>)</p>
<p>
<h3>This is what I started with</h3>
<p>This is my folders for the already existing website.</p>
<p>[cc lang="bash"]<br />
# Existing homedir<br />
/home/my_web/<br />
# Current webroot<br />
/home/my_web/htdocs<br />
[/cc]</p>
<p>
<h3>Creating folders and files for Sinatra</h3>
<p>The first thing you want to do is to create folders and files for Sinatra.</p>
<p>[cc lang=bash]<br />
mkdir /home/my_web/sinatra<br />
[/cc]</p>
<p>[cc lang=bash]<br />
cd /home/my_web/sinatra<br />
mkdir tmp<br />
mkdir logs<br />
mkdir public<br />
touch app.rb<br />
touch config.ru<br />
[/cc]</p>
<p>
<h3>Create symlink</h3>
<p>Create a symbolic link from our current webroot to the new Sinatra app so that apache/passenger can find it.</p>
<p>[cc lang="bash"]<br />
ln -s /home/my_web/sinatra/public /home/my_web/htdocs/app<br />
[/cc]</p>
<p>
<h3>Creating the application</h3>
<p>We also need a Sinatra application for this to work so lets fill those files.</p>
<p>
<h4>File: config.ru</h4>
<p>[cc lang="ruby"]<br />
require &#8216;app&#8217;</p>
<p>set :environment, ENV['RACK_ENV'].to_sym<br />
set :app_file,     &#8216;app.rb&#8217;<br />
disable :run</p>
<p>log = File.new(&#8220;logs/sinatra.log&#8221;, &#8220;a&#8221;)<br />
STDOUT.reopen(log)<br />
STDERR.reopen(log)</p>
<p>run Sinatra::Application<br />
[/cc]</p>
<p>
<h4>File: app.rb</h4>
<p>[cc lang="ruby"]<br />
require &#8216;rubygems&#8217;<br />
require &#8217;sinatra&#8217;</p>
<p>before do<br />
  # Strip the last / from the path<br />
  request.env['PATH_INFO'].gsub!(/\/$/, &#8221;)<br />
end</p>
<p>get &#8221; do<br />
   &#8220;Hello world&#8221;<br />
end<br />
[/cc]</p>
<p>
<h3>Apache configuration</h3>
<p>Now we need to setup apache so that it can find our Sinatra app and load it.</p>
<p>The only thing you need to do is add the following line to your existing VirtualHost block:<br />
[cc lang="apache"]<br />
RackBaseURI /app<br />
[/cc]<br />
This line will tell passenger to look into our existing webroot for a symlink thats named app and which points to our rack app.  (<a href="http://www.modrails.com/documentation/Users%20guide.html#RackBaseURI" target="_blank">RackBaseURI  documentation</a>)</p>
<p>
<h3>Virtual host entry</h3>
<p>[cc lang="apache"]<br />
<VirtualHost *:80><br />
  ServerName www.example.com<br />
  ServerAlias example.com<br />
  DocumentRoot /home/my_web/htdocs/<br />
  RackBaseURI /app</p>
<p>  <Directory "/home/my_web/htdocs/"><br />
    Order allow,deny<br />
    Allow from all<br />
    AllowOverride All<br />
  </Directory><br />
</VirtualHost><br />
[/cc]</p>
<p>The best part is that you are allowed to specify this option multiple times. So you can easily setup multiple apps under the same virtual host.</p>
<p>Cheers! </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pastbedti.me/2009/11/deploying-a-sinatra-app-with-apache-and-phusion-passenger-a-k-a-mod_rack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handling a staging environment with capistrano / rails</title>
		<link>http://www.pastbedti.me/2009/01/handling-a-staging-environment-with-capistrano-rails/</link>
		<comments>http://www.pastbedti.me/2009/01/handling-a-staging-environment-with-capistrano-rails/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 20:49:06 +0000</pubDate>
		<dc:creator>Mathias Stjernström</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[deploy]]></category>
		<category><![CDATA[staging]]></category>

		<guid isPermaLink="false">http://www.pastbedti.me/?p=342</guid>
		<description><![CDATA[Just before christmas I worked with one of our customers new server cluster or cloud if you may.
This cluster has production nodes and staging nodes and this post is about how to get capistrano to play nice with both production and the staging environment.

I have googled for a solution but all solutions I found where [...]]]></description>
			<content:encoded><![CDATA[<p>Just before christmas I worked with one of our customers new server cluster or cloud if you may.<br />
This cluster has production nodes and staging nodes and this post is about how to get capistrano to play nice with both production and the staging environment.<br />
<span id="more-342"></span></p>
<p>I have googled for a solution but all solutions I found where pretty ugly so i decided to create my own.  When writing this line I did a test googling just to give an example of a bad example and my first result where the <a href="http://weblog.jamisbuck.org/">buckblogs</a> blog. A post about <a href="http://weblog.jamisbuck.org/2007/7/23/capistrano-multistage">a plugin called multistage</a> I do not how I could miss that <img src='http://www.pastbedti.me/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>But as my solution is so simple I will continue this post and show you anyway. </p>
<p>As usual I have written to much bullshit and I guess that you just want is some code so here you go.</p>
<p>[cc lang="ruby"]<br />
desc &#8220;Run tasks in production enviroment.&#8221;<br />
task :production do<br />
  # Production nodes<br />
  role :app, &#8220;192.168.1.30&#8243;<br />
  role :app, &#8220;192.168.2.30&#8243;<br />
  role :db,  &#8220;192.168.1.30&#8243;, :primary => true<br />
end </p>
<p>desc &#8220;Run tasks in staging enviroment.&#8221;<br />
task :staging do<br />
  # Staging nodes<br />
  role :web, &#8220;192.168.1.60&#8243;<br />
  role :app, &#8220;192.168.2.60&#8243;<br />
  role :db,  &#8220;192.168.1.60&#8243;, :primary=>true<br />
end<br />
[/cc]</p>
<p>This is all there is to it. Splitting your role definitions into different tasks.<br />
Now you may wonder how you use this when deploying or whatever you do.</p>
<p>Just add those tasks as params to <strong>cap</strong>.</p>
<p>[cc lang="bash"]<br />
cap staging deploy:check<br />
cap staging deploy<br />
# or<br />
cap production deploy:check<br />
cap production deploy<br />
[/cc]</p>
<p></p>
<h3>And here is a little bonus</h3>
<p>Just to spice this up a bit I added another useful function. A little warning if you are about to deploy to your production environment. When running a big/important site you do not want to deploy into the wrong environment <img src='http://www.pastbedti.me/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>This is how the final code looks. </p>
<p>[cc lang="ruby"]<br />
desc &#8220;Run tasks in production enviroment.&#8221;<br />
task :production do<br />
  # Prompt to make really sure we want to deploy into prouction<br />
  puts &#8220;\n\e[0;31m   ######################################################################"<br />
  puts "   #\n   #       Are you REALLY sure you want to deploy to production?"<br />
  puts "   #\n   #               Enter y/N + enter to continue\n   #"<br />
  puts "   ######################################################################\e[0m\n"<br />
  proceed = STDIN.gets[0..0] rescue nil<br />
  exit unless proceed == &#8216;y&#8217; || proceed == &#8216;Y&#8217; </p>
<p>  # Production nodes<br />
  role :app, &#8220;192.168.1.30&#8243;<br />
  role :app, &#8220;192.168.2.30&#8243;<br />
  role :db,  &#8220;192.168.1.30&#8243;, :primary => true<br />
end </p>
<p>desc &#8220;Run tasks in staging enviroment.&#8221;<br />
task :staging do<br />
  # Staging nodes<br />
  role :web, &#8220;192.168.1.60&#8243;<br />
  role :app, &#8220;192.168.2.60&#8243;<br />
  role :db,  &#8220;192.168.1.60&#8243;, :primary=>true<br />
end<br />
[/cc]</p>
<p>
When this code is used you will get something like the image below.<br />
<br />
<img src="http://www.pastbedti.me/wp-content/uploads/2009/01/deploying_to_production.png" alt="Warning when deploying to production" title="Warning when deploying to production" width="562" height="276" class="alignnone size-full wp-image-360" /></p>
<p>And thats all there is to it. The only thing that I think is missing is a warning/notice if you do not specify either production/staging. Like it is now you will get an error when capistrano cannot find any valid servers.</p>
<p>Happy deploying! </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pastbedti.me/2009/01/handling-a-staging-environment-with-capistrano-rails/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
