<?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>Abisso Dev. &#187; webapp</title>
	<atom:link href="http://abisso.org/tag/webapp/feed/" rel="self" type="application/rss+xml" />
	<link>http://abisso.org</link>
	<description>il sapere umano appartiene al mondo</description>
	<lastBuildDate>Sun, 02 May 2010 14:08:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>heroku.com il deploy di applicazioni rack-based è un gioco</title>
		<link>http://abisso.org/2009/05/herokucom-il-deploy-di-applicazioni-rack-based-e-un-gioco/</link>
		<comments>http://abisso.org/2009/05/herokucom-il-deploy-di-applicazioni-rack-based-e-un-gioco/#comments</comments>
		<pubDate>Mon, 18 May 2009 13:58:09 +0000</pubDate>
		<dc:creator>nolith</dc:creator>
				<category><![CDATA[Recensioni]]></category>
		<category><![CDATA[italiano]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[deploy]]></category>
		<category><![CDATA[heroku]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[rack]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sinatra]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://abisso.org/?p=97</guid>
		<description><![CDATA[Ieri sera ho scoperto un servizio interessante, si chiama Heroku ed è un hosting di applicazioni basate su rack come ad esempio Ruby on Rails o Sinatra. Fino a qui nulla di nuovo, ma il loro sistema si basa sulla semplicità della procedura di deploy che come ben sa chi ci ha provato, non è [...]]]></description>
			<content:encoded><![CDATA[<p>Ieri sera ho scoperto un servizio interessante, si chiama <a href="http://heroku.com">Heroku</a> ed è un <strong>hosting di applicazioni basate su <a href="http://rack.rubyforge.org/">rack</a></strong> come ad esempio <strong><a href="http://rubyonrails.org">Ruby on Rails</a></strong> o <strong><a href="http://www.sinatrarb.com">Sinatra</a></strong>.</p>
<p>Fino a qui nulla di nuovo, ma il loro sistema si basa sulla <strong>semplicità della procedura di deploy</strong> che come ben sa chi ci ha provato, non è proprio al livello di una applicazione php.</p>
<p>Per provare un po&#8217; questo sistema ho deciso di creare una mini applicazione con sinatra che esegue l&#8217;hash MD5 di alcune stringhe.<br />
Vediamo come funziona.<br />
<span id="more-97"></span></p>
<h2>Prerequisiti</h2>
<p>È necessario installare la gemma <tt>heroku</tt>; per l&#8217;applicazione dell&#8217;esempio serviranno anche le gemme <tt>sinatra</tt> e <tt>thin</tt>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">	$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> heroku
	$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> sintra 
	$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> thin</pre></div></div>

<p>Per il deploy serve <tt>git</tt>. <a href="http://git-scm.com/" rel="nofollow" target="_blank">Scaricabile da qui</a>.</p>
<p>Fatto questo è necessario registrare un account su <a href="http://heroku.com">Heroku</a>.</p>
<h2>L&#8217;applicazione</h2>
<p>Creiamo il file <tt>hasher.rb</tt> dentro la cartella <tt>hasher</tt>.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">	<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
	<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'sinatra'</span>
	<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'digest/md5'</span>
&nbsp;
	get <span style="color:#996600;">'/'</span> <span style="color:#9966CC; font-weight:bold;">do</span>
	  erb <span style="color:#ff3333; font-weight:bold;">:home</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
	post <span style="color:#996600;">'/md5'</span> <span style="color:#9966CC; font-weight:bold;">do</span>
	  <span style="color:#9966CC; font-weight:bold;">unless</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:str</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?
	    <span style="color:#996600;">&quot;&lt;code&gt;MD5(#{params[:str]}) -&gt; #{Digest::MD5.hexdigest(params[:str])}&lt;/code&gt;&quot;</span>
	  <span style="color:#9966CC; font-weight:bold;">else</span>
	    redirect <span style="color:#996600;">'/'</span>
	  <span style="color:#9966CC; font-weight:bold;">end</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
	<span style="color:#008000; font-style:italic;"># Accettiamo solo richieste in POST</span>
	get <span style="color:#996600;">'/md5'</span> <span style="color:#9966CC; font-weight:bold;">do</span>
	  redirect <span style="color:#996600;">'/'</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
	use_in_file_templates!
&nbsp;
	__END__
&nbsp;
	@@ home
&nbsp;
	<span style="color:#006600; font-weight:bold;">&lt;</span>p<span style="color:#006600; font-weight:bold;">&gt;</span>
	Questa è una semplice webapp <span style="color:#006600; font-weight:bold;">&#40;</span>esagerato!<span style="color:#006600; font-weight:bold;">&#41;</span> per spiegare come funziona 
	<span style="color:#006600; font-weight:bold;">&lt;</span>a href=<span style="color:#996600;">&quot;http://heroku.com&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span>Heroku<span style="color:#006600; font-weight:bold;">&lt;/</span>a<span style="color:#006600; font-weight:bold;">&gt;</span>.<span style="color:#006600; font-weight:bold;">&lt;</span>br<span style="color:#006600; font-weight:bold;">/&gt;</span>
	Puoi trovare l<span style="color:#996600;">'articolo relativo nel mio 
	&lt;a href=&quot;http://bit.ly/nkw0V&quot; rel=&quot;me&quot;&gt;blog&lt;/a&gt;.
	&lt;/p&gt;
&nbsp;
	&lt;form action=&quot;/md5&quot; method=&quot;post&quot; accept-charset=&quot;utf-8&quot;&gt;
	  &lt;input type=&quot;text&quot; name=&quot;str&quot; value=&quot;Write here...&quot; id=&quot;str&quot; /&gt;
	  &lt;input type=&quot;submit&quot; /&gt;
	&lt;/form&gt;</span></pre></div></div>

<p>Per il deploy con <tt>rack</tt> è necessario creare anche il file <tt>config.ru</tt></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#rack config file</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'hasher'</span>
run <span style="color:#6666ff; font-weight:bold;">Sinatra::Application</span></pre></div></div>

<h2>Il deploy</h2>
<p>Ora giunge il momento di mandare online la nostra applicazione</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#creaiamo il repository git nella cartella corrente</span>
$ git init
Initialized empty Git repository <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>nolith<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>Projects<span style="color: #000000; font-weight: bold;">/</span>hasher<span style="color: #000000; font-weight: bold;">/</span>.git<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#aggiungiamo tutti i file nella cartella al controllo di versione</span>
$ git add .
&nbsp;
<span style="color: #666666; font-style: italic;">#eseguiamo il commit dei file</span>
$ git commit <span style="color: #660033;">-m</span> <span style="color: #ff0000;">'Import iniziale: hash md5'</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>master <span style="color: #7a0874; font-weight: bold;">&#40;</span>root-commit<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: created 21b62e4: <span style="color: #ff0000;">&quot;Import iniziale: hash md5&quot;</span>
 <span style="color: #000000;">2</span> files changed, <span style="color: #000000;">41</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 create mode <span style="color: #000000;">100644</span> config.ru
 create mode <span style="color: #000000;">100644</span> hasher.rb
&nbsp;
<span style="color: #666666; font-style: italic;">#creiamo una nuova applicazione su heroku</span>
<span style="color: #666666; font-style: italic;"># sarà possibile rinominarla in seguito</span>
$ heroku create
Enter your Heroku credentials.
Email: utente<span style="color: #000000; font-weight: bold;">@</span>server.it
Password:
Uploading <span style="color: #c20cb9; font-weight: bold;">ssh</span> public key
Created http:<span style="color: #000000; font-weight: bold;">//</span>growing-summer-43.heroku.com<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">|</span> git<span style="color: #000000; font-weight: bold;">@</span>heroku.com:growing-summer-43.git
Git remote heroku added
&nbsp;
<span style="color: #666666; font-style: italic;">#eseguiamo l'upload dell'applicazione</span>
$ git push heroku master
Warning: Permanently added the RSA host key <span style="color: #000000; font-weight: bold;">for</span> IP address <span style="color: #ff0000;">'75.101.145.87'</span> to the list of known hosts.
Counting objects: <span style="color: #000000;">4</span>, done.
Compressing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">4</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
Writing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">4</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">784</span> bytes, done.
Total <span style="color: #000000;">4</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, reused <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
-----<span style="color: #000000; font-weight: bold;">&gt;</span> Heroku receiving push
-----<span style="color: #000000; font-weight: bold;">&gt;</span> Rack app detected
       Compiled slug <span style="color: #c20cb9; font-weight: bold;">size</span> is 004K
-----<span style="color: #000000; font-weight: bold;">&gt;</span> Launching..... <span style="color: #000000; font-weight: bold;">done</span>
       App deployed to Heroku
&nbsp;
To git<span style="color: #000000; font-weight: bold;">@</span>heroku.com:growing-summer-43.git
 <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>new branch<span style="color: #7a0874; font-weight: bold;">&#93;</span>      master -<span style="color: #000000; font-weight: bold;">&gt;</span> master
&nbsp;
<span style="color: #666666; font-style: italic;">#Proviamo la nostra applicazione</span>
<span style="color: #007800;">$heroku</span> open</pre></div></div>

<h3>Alcune note</h3>
<p>La prima volta che si utilizza un comando di heroku vengono richieste le credenziali di accesso e viene fatto l&#8217;upload di una chiave pubblica ssh (<a href="http://linubuntu.blogspot.com/2007/02/ssh-autenticazione-tramite-chiave.html">Come creare una coppia di chiavi per ssh</a>).</p>
<p><strong>Finito! Siamo online!</strong></p>
<h2>Conclusioni</h2>
<p>Quanto mostrato si può fare anche per una applicazione Rails, in questo caso non servirà il file <tt>config.ru</tt>.<br />
Attualmente il deploy di una applicazione basata su rack non è dei più semplici, anche se devo dire che <a href="http://modrails.org">mod_rails</a> ha notevolmente migliorato le cose.<br />
Dobbiamo però considerare anche il fattore economico, per piccole applicazioni di test heroku è gratuito, per applicazoni che necessitano di risorse consistenti direi che la scelta di basarsi su <a href="http://aws.amazon.com">AWS</a> è un vantaggio non da poco, i benefici offerti dalla struttura di Amazon sono impossibili da ottenere ad un costo contenuto per uno sviluppatore indipendete o una PMI.</p>
]]></content:encoded>
			<wfw:commentRss>http://abisso.org/2009/05/herokucom-il-deploy-di-applicazioni-rack-based-e-un-gioco/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
