<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Tales from the classpath - Jeppe Nejsum Madsen</title>
	<atom:link href="http://jeppenejsum.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jeppenejsum.wordpress.com</link>
	<description>Useless tidbits from the world of internet software</description>
	<lastBuildDate>Sun, 16 Oct 2011 19:09:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jeppenejsum.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Tales from the classpath - Jeppe Nejsum Madsen</title>
		<link>http://jeppenejsum.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jeppenejsum.wordpress.com/osd.xml" title="Tales from the classpath - Jeppe Nejsum Madsen" />
	<atom:link rel='hub' href='http://jeppenejsum.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Building a social site using Scala, Lift &amp; MongoDB</title>
		<link>http://jeppenejsum.wordpress.com/2011/09/27/building-a-social-site-using-scala-lift-mongodb/</link>
		<comments>http://jeppenejsum.wordpress.com/2011/09/27/building-a-social-site-using-scala-lift-mongodb/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 21:29:55 +0000</pubDate>
		<dc:creator>Jeppe</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://jeppenejsum.wordpress.com/?p=279</guid>
		<description><![CDATA[So, it has been quite a while since the last update on this blog. Time to do something about it and build a real-time social application using lots of new and shiny technology! Motivation I have a 12-year old daughter. Like many others she spend a lot of time online, Skype &#38; Facebook of course, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=279&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So, it has been quite a while since the last update on this blog. Time to do something about it and build a real-time social application using lots of new and shiny technology!</p>
<h2><span id="more-279"></span>Motivation</h2>
<p>I have a 12-year old daughter. Like many others she spend a lot of time online, Skype &amp; Facebook of course, but mostly a horse site called <a href="http://net-hesten.dk/">net-hesten.dk</a> (warning: in danish!) I think she has probably written thousands of messages on their forum <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  One of the main things you can do there is to create your own farm where you can buy/sell horses etc. As part of making your farm, you create a profile for your farm. And here all kinds of creativity starts.</p>
<p>Over the summer she has taught herself HTML, CSS, some Javascript, Gimp etc. just to be able to create a &#8220;cool&#8221; profile page. Nothing beats motivation for learning new stuff! Now the time has come where she wants to create her own site (the precise mammal is not known yet and probably not important). She is inspired by other girls that have learned PHP, MySQL etc. in order to build things. And while the results are not always impressive when viewed with the eyes of a professional, the dedication is.</p>
<p>So I decided to help her getting some of the basic components up and running and figured I could kill two birds with one stone:</p>
<ol>
<li>Try out some new technology &amp; services that I&#8217;ve been wanting to play with for a while</li>
<li>Get some quality time with my daughter (How often do you hear &#8220;I&#8217;ve got a cool dad&#8221;, when you proclaim you can build a web application  :-)</li>
</ol>
<h2>Ground rules</h2>
<p>This is a side project, so low cost &amp; high return on time invested is important. So I&#8217;ll try to see how little code I can get away with writing. It&#8217;ll also function as a test-bed for the highly (too?) popular MVP concept from the lean startup camp: Only focus on the minimal amount of functionality needed.</p>
<p>I&#8217;ll not be doing the layout &amp; design, but will leave that to my daughter (which probably has better abilities for this anyway)</p>
<p>The idea is to blog about some of the code components that (hopefully!) will be created during this project and put some, if not all, the code on github.</p>
<h2>The components</h2>
<ul>
<li>The Scala language</li>
<li>Scala IDE for Eclipse</li>
<li>LIft web framework</li>
<li>MongoDB</li>
<li>Akka</li>
<li>&#8230;and probably more</li>
</ul>
<div>At <a href="http://www.fleetzone.dk">my company</a> we&#8217;ve been using Scala &amp; Lift for more than two years to build a B2B SaaS platform. I&#8217;ve come across quite a few use cases where Akka &amp; MongoDB might be useful, but haven&#8217;t had time to explore this fully. This should give me an opportunity to try it out.</div>
<h2>The Services</h2>
<p>Low cost is important and I don&#8217;t expect a lot of traffic here, so many of the online service providers have free plans that can be useful:</p>
<ul>
<li>CloudBees for hosting JVM applications. As opposed to e.g. Google AppEngine you can actually use the full JVM functionality (e.g. create threads for Lift&#8217;s comet support)</li>
<li>MongoHQ for hosted mongodb</li>
<li>SendGrid for sending out emails</li>
</ul>
<div>I haven&#8217;t used any of the above services so don&#8217;t know how this will turn out (though at my company we do use CloudBees&#8217; Jenkins infrastructure for automated builds), this is part of the experiment.</div>
<div>
<p>In the world of LAMP there seems to be an abundance of free hosting services, but the few I&#8217;ve tried left a lot to be desired. The above services all seem fairly complete and do provide solutions for scaling up if needed  (and an idea of how they are going to make money)</p>
</div>
<br />Filed under: <a href='http://jeppenejsum.wordpress.com/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeppenejsum.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeppenejsum.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jeppenejsum.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jeppenejsum.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jeppenejsum.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jeppenejsum.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jeppenejsum.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jeppenejsum.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jeppenejsum.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jeppenejsum.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jeppenejsum.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jeppenejsum.wordpress.com/279/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jeppenejsum.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jeppenejsum.wordpress.com/279/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=279&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeppenejsum.wordpress.com/2011/09/27/building-a-social-site-using-scala-lift-mongodb/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/acdc9f9dea04591decfd7992de3a6de9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jeppe</media:title>
		</media:content>
	</item>
		<item>
		<title>Rapid Lift application development with Eclipse and JRebel</title>
		<link>http://jeppenejsum.wordpress.com/2010/09/17/rapid-lift-application-development-with-eclipse-and-jrebel/</link>
		<comments>http://jeppenejsum.wordpress.com/2010/09/17/rapid-lift-application-development-with-eclipse-and-jrebel/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 22:46:02 +0000</pubDate>
		<dc:creator>Jeppe</dc:creator>
				<category><![CDATA[lift]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://jeppenejsum.wordpress.com/?p=169</guid>
		<description><![CDATA[In this article I&#8217;ll describe the setup I use to do develop Lift applications. While more heavy-weight than if an interpreted language is used, I find this setup provides fairly decent turnaround times. So, it took a little longer than expected to write this article which continues where the previous stopped. But all good things [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=169&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this article I&#8217;ll describe the setup I use to do develop Lift applications. While more heavy-weight than if an interpreted language is used, I find this setup provides fairly decent turnaround times.</p>
<p><span id="more-169"></span></p>
<p>So, it took a little longer than expected to write this article which continues where the <a href="/2010/04/16/lift-quick-start-look-ma-no-maven/">previous</a> stopped. But all good things come to he who waits <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  The software used in the previous article all had major updates in the meantime:</p>
<ul>
<li>Scala 2.8 (2.8.1 is just around the corner)</li>
<li>Eclipse 3.6</li>
<li>Scale IDE for Eclipse (though a nightly build is currently needed for Eclipse 3.6)</li>
<li>Gradle 0.9 RC1</li>
<li>Lift 2.1 RC2</li>
</ul>
<h1>Installing the software</h1>
<p>I&#8217;m writing this on OS X 10.6.4, using the default Java installation:</p>
<pre>java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02-279-10M3065)
Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01-279, mixed mode)</pre>
<h2>Eclipse</h2>
<p>I&#8217;m using the latest Eclipse 3.6 (Helios), which can be found <a href="http://www.eclipse.org/downloads/packages/eclipse-classic-360/heliosr">here</a>. Install it and launch with a new workspace.<a href="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-16-at-23-17-03.png"><img class="aligncenter size-full wp-image-260" title="Empty workspace" src="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-16-at-23-17-03.png?w=570&#038;h=351" alt="" width="570" height="351" /></a></p>
<h2 style="font-size:1.5em;">JRebel</h2>
<p>JRebel allows you to make code changes and have the changes reflected in your running app without restarting. This is very handy for a rapid development cycle. It&#8217;s not perfect and doesn&#8217;t work with all changes, but most of the time it picks up the changes ok. Note that you can get a free license if you only work with Scala files!</p>
<p>Follow step 1-3 in the instructions <a href="http://www.zeroturnaround.com/jrebel/eclipse-jrebel-tutorial/">here</a> to download and install JRebel as well as the JRebel Eclipse plugin.</p>
<h2><strong>Scala IDE for Eclipse</strong></h2>
<p>Next, install the Scala IDE for Eclipse from this update site: <em>http://download.scala-ide.org/nightly-update-helios-2.8.0.final/</em></p>
<p>Use this guide as a starting point: https://www.assembla.com/wiki/show/scala-ide/Requirements_and_Installation</p>
<p>Try creating a small sample Scala project to verify your installation:</p>
<ol>
<li>Select the Scala perspective (click on &#8216;+&#8217; the first time and select &#8220;Other..&#8221;)</li>
<p><a href="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-16-at-23-46-20.png"><img class="aligncenter size-full wp-image-261" title="Screen shot 2010-09-16 at 23.46.20" src="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-16-at-23-46-20.png?w=211&#038;h=92" alt="" width="211" height="92" /></a></p>
<li>Right-click in Package Explorer and select New-&gt;Scala Project</li>
<li>Enter helloworld as Project name</li>
<li>Expand the project, right-click on the src folder and select New-&gt;Scala Application</li>
<li>Enter &#8220;HelloWorld&#8221; as Object name</li>
<li>Add println(&#8220;Hello, World&#8221;)</li>
<li>Right-click in the editor and select Run As-&gt;Scala Application</li>
</ol>
<p><a href="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-17-at-00-00-20.png"><img class="aligncenter size-full wp-image-263" title="Screen shot 2010-09-17 at 00.00.20" src="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-17-at-00-00-20.png?w=570&#038;h=270" alt="" width="570" height="270" /></a></p>
<p>Note, that since this is a nightly build, there may be times when the plugin is not in a good shape. Seek help on the scala-ide mailing list <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h1>Creating the Lift Eclipse project</h1>
<h1><span style="font-weight:normal;font-size:13px;">Since we&#8217;re using Gradle to manage the dependencies to external JARs (see <a href="/2010/04/16/lift-quick-start-look-ma-no-maven/">previous article</a> for details), we need to tell Eclipse where in the file system those jars can be found. You need to find this directory on your system. It&#8217;s usally in <em>~/.gradle/cache</em> which for me maps to <em>/Users/Jeppe/.gradle/cache</em>.</span></h1>
<p>So we create a classpath variable, GRADLE_CACHE  that points to this directory. Open Eclipse preferences:</p>
<p><a href="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-17-at-00-13-48.png"><img class="aligncenter size-full wp-image-268" title="Screen shot 2010-09-17 at 00.13.48" src="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-17-at-00-13-48.png?w=570&#038;h=375" alt="" width="570" height="375" /></a></p>
<p>Next, create the actual Eclipse files (.classpath and .project) by running</p>
<pre>$ ./gradlew eclipse
:eclipseClasspath
:eclipseProject
:eclipseWtp
:eclipse
BUILD SUCCESSFUL

Total time: 11.27 secs</pre>
<p>Finally, import the project into Eclipse:</p>
<ol>
<li>Right-click in Package Explorer and select &#8220;Import&#8230;&#8221;</li>
<li>Select General-&gt;Existing projects into Workspace</li>
<li>Select the location of your build.gradle file as root</li>
</ol>
<p>The created Lift application contains a main object that runs an embedded Jetty container which is very useful for development. It&#8217;s located in <em>src/test/scala/RunWepApp.scala.</em> Right-click this file and select Run As-&gt;Scala Application. Now Jetty starts up and you can navigate to http://localhost:8080 to see the application.</p>
<p><a href="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-17-at-00-23-57.png"><img class="aligncenter size-full wp-image-269" title="Screen shot 2010-09-17 at 00.23.57" src="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-17-at-00-23-57.png?w=570&#038;h=345" alt="" width="570" height="345" /></a></p>
<p>The final step is to enable JRebel for the Run configuration just created. Select &#8220;Run Configurations&#8221; and find RunWebApp$, select the JRebel tab and enable the JRebel agent.</p>
<p><a href="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-17-at-00-27-37.png"><img class="aligncenter size-full wp-image-271" title="Screen shot 2010-09-17 at 00.27.37" src="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-17-at-00-27-37.png?w=570&#038;h=287" alt="" width="570" height="287" /></a>Restart the application. JRebel should print something to the console.</p>
<h1>JRebel in action</h1>
<p>Now try to change something. Go to <em>src/main/scala/example/snippet/HelloWorld.scala. </em></p>
<ol>
<li>Change the output of the <em>howdy</em> snippet by e.g. replacing &#8220;d.toString()&#8221; with some text.</li>
<li>Save the file in order to compile it.</li>
<li>Refresh the page in the browser.</li>
<li>Watch the new content be displayed in the browser!</li>
<li>Watch the console output that says JRebel has reloaded the class</li>
</ol>
<p>As mentioned earlier, not everything can be reloaded by JRebel and not everything in Lift can be changed during runtime.</p>
<p>If JRebel cannot reload the changes, you usually get a runtime error (ClassNotFound, ClassCastException etc) and you&#8217;ll have to restart. If JRebel does pickup your changes and nothing happens, chances are that Lift cannot dynamically pick up the changes. Examples of the latter are:</p>
<ul>
<li>Things that happen in Boot. Your application is not re-booted to pickup the changes. This unfortunately includes SiteMap changes.</li>
<li>Addition/removal of mapper fields. The fields of a mapped object are determined at startup and cannot change at runtime.</li>
</ul>
<p>So, this completes the post. Enjoy! And please provide feedback if you have any ideas to improve the development cycle!</p>
<p><em> </em></p>
<br />Filed under: <a href='http://jeppenejsum.wordpress.com/category/scala/lift-scala/'>lift</a>, <a href='http://jeppenejsum.wordpress.com/category/scala/'>scala</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeppenejsum.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeppenejsum.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jeppenejsum.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jeppenejsum.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jeppenejsum.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jeppenejsum.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jeppenejsum.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jeppenejsum.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jeppenejsum.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jeppenejsum.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jeppenejsum.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jeppenejsum.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jeppenejsum.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jeppenejsum.wordpress.com/169/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=169&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeppenejsum.wordpress.com/2010/09/17/rapid-lift-application-development-with-eclipse-and-jrebel/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/acdc9f9dea04591decfd7992de3a6de9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jeppe</media:title>
		</media:content>

		<media:content url="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-16-at-23-17-03.png" medium="image">
			<media:title type="html">Empty workspace</media:title>
		</media:content>

		<media:content url="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-16-at-23-46-20.png" medium="image">
			<media:title type="html">Screen shot 2010-09-16 at 23.46.20</media:title>
		</media:content>

		<media:content url="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-17-at-00-00-20.png" medium="image">
			<media:title type="html">Screen shot 2010-09-17 at 00.00.20</media:title>
		</media:content>

		<media:content url="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-17-at-00-13-48.png" medium="image">
			<media:title type="html">Screen shot 2010-09-17 at 00.13.48</media:title>
		</media:content>

		<media:content url="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-17-at-00-23-57.png" medium="image">
			<media:title type="html">Screen shot 2010-09-17 at 00.23.57</media:title>
		</media:content>

		<media:content url="http://jeppenejsum.files.wordpress.com/2010/09/screen-shot-2010-09-17-at-00-27-37.png" medium="image">
			<media:title type="html">Screen shot 2010-09-17 at 00.27.37</media:title>
		</media:content>
	</item>
		<item>
		<title>Lift quick start: Look Ma! No Maven</title>
		<link>http://jeppenejsum.wordpress.com/2010/04/16/lift-quick-start-look-ma-no-maven/</link>
		<comments>http://jeppenejsum.wordpress.com/2010/04/16/lift-quick-start-look-ma-no-maven/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 14:25:54 +0000</pubDate>
		<dc:creator>Jeppe</dc:creator>
				<category><![CDATA[lift]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[gradle]]></category>

		<guid isPermaLink="false">http://jeppenejsum.wordpress.com/?p=230</guid>
		<description><![CDATA[For the last year or so, I&#8217;ve been using the Lift web framework to develop our B2B SaaS application (my experiences can be found here). I&#8217;ve enjoyed this very much, especially the community, so when David Pollak asked me to be become a committer I couldn&#8217;t say no One area where Lift is lacking is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=230&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For the last year or so, I&#8217;ve been using the <a href="http://liftweb.net">Lift</a> web framework to develop our B2B SaaS application (my experiences can be found <a href="/2010/01/18/scala-and-lift-status-after-six-months/">here</a>). I&#8217;ve enjoyed this very much, especially the community, so when David Pollak asked me to be become a committer I couldn&#8217;t say no <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>One area where Lift is lacking is in documentation, so I&#8217;ll try to write a few posts here that can help people getting started using Lift. I&#8217;ll be writing about the workflow we use, since</p>
<ol>
<li>It works for us</li>
<li>It is not using Maven, a source of some &#8230;.. frustration for many</li>
</ol>
<p><span id="more-230"></span></p>
<h1>Introduction</h1>
<p>There are many tutorials available that shows how to create a new Lift project, building and running using Maven. If you like maven and think that it&#8217;s fine, you should probably follow one of those, since this is the most common setup and you&#8217;re likely to find help on the mailing list. We&#8217;ve decided to use <a href="http://www.gradle.org/">Gradle</a>.</p>
<h3>Why not SBT?</h3>
<p>The <a href="http://code.google.com/p/simple-build-tool/">Simple Build Tool</a> is a cool build tool aimed primarily at Scala projects. It has nifty support for continuous compilation and testing. I haven&#8217;t used SBT, but hear it&#8217;s quite good (Lift may eventually move to SBT).</p>
<p>But I think many of the features that are cool about SBT (ie. the continuous compilation and testing) are most useful during development if you&#8217;re just using a text editor. If you&#8217;re using an IDE (such as Eclipse) it already handles this.</p>
<p>I mostly use a build tool for automating the build/test/deployment process and as such, I think Gradle is better suited since it is scripted in Groovy and has complete support for existing Ant tasks. But I really need to try out the Emacs+SBT combo at some point to see what all the fuzz is about <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h1><strong>Prerequisites</strong></h1>
<p>Ok, lets get started. To create and run your Lift projects, you need these packages installed and working:</p>
<ul>
<li>A Java 1.5 (1.6 preferred) JRE installed</li>
<li>Git (not strictly necessary as you can download the files as zip/tar package from Github)</li>
</ul>
<p>That&#8217;s it. No need for Maven, Gradle, Scala or anything else since we&#8217;re using a the nice <em><a href="http://www.gradle.org/0.9-preview-1/docs/userguide/gradle_wrapper.html">Wrapper</a></em> feature of Gradle that automatically downloads and installs the correct version of Gradle.</p>
<h3>A minor note about versions</h3>
<p>In these posts I&#8217;ll use the versions of various software that I know work. Both Scala, Lift and Gradle are about to release new versions which will improve many things, but I&#8217;m only using the Gradle pre-release. I&#8217;ll update the posts when the new Scala &amp; Lift versions are more stable.</p>
<h1>Creating a Lift project</h1>
<p>Creating a project is as simple as cloning a project from Git:</p>
<pre>$ git clone git@github.com:jeppenejsum/liftstart.git</pre>
<p>This will fetch all the files from github. The project just created is a basic Lift application with database support (using H2) and simple user registration. The files follow a standard directory scheme.</p>
<p><a href="http://jeppenejsum.files.wordpress.com/2010/04/screen-shot-2010-04-16-at-15-48-21.png"><img class="aligncenter size-full wp-image-246" title="Screen shot 2010-04-16 at 15.48.21" src="http://jeppenejsum.files.wordpress.com/2010/04/screen-shot-2010-04-16-at-15-48-21.png?w=428&#038;h=632" alt="" width="428" height="632" /></a>The scala files are in <em>src/main/scala</em> and the web files (html, images etc) are in <em>src/main/webapp</em>. The file <em>src/main/scala/bootstrap/liftweb/Boot.scala</em> is where you customize most Lift settings, it is run once during startup. Check out the Lift documentation for more details.</p>
<h1>Building and running the project</h1>
<p>Gradle reads the <em>build.gradle</em> file to determine the tasks that are available in the project. The <em>build.gradle</em> in this project is fairly simple, mostly adding the scala-tools.org repository and specifying the dependencies needed to compile and test the project.</p>
<pre class="brush: java;">
// Minimal build.gradle for Lift project
apply {
    plugin 'scala'
    plugin 'war'
    plugin 'jetty'
}

scalaVersion = '2.7.7'
liftVersion = '2.0-M4'

jettyRun.contextPath = &quot;/&quot;

repositories {
    mavenCentral()
    mavenRepo name:'scala-releases', urls:'http://scala-tools.org/repo-releases/'
}

dependencies {
    scalaTools &quot;org.scala-lang:scala-compiler:$scalaVersion&quot;,
        &quot;org.scala-lang:scala-library:$scalaVersion&quot;

    compile &quot;org.scala-lang:scala-library:$scalaVersion&quot;,
    	&quot;net.liftweb:lift-webkit:$liftVersion&quot;,
    	&quot;net.liftweb:lift-mapper:$liftVersion&quot;,
    	&quot;net.liftweb:lift-json:$liftVersion&quot;,
    	&quot;net.liftweb:lift-util:$liftVersion&quot;,
    	&quot;net.liftweb:lift-common:$liftVersion&quot;,
        &quot;com.h2database:h2:1.1.117&quot;

    testCompile &quot;junit:junit:4.5&quot;,
        &quot;org.scala-tools.testing:specs:1.6.1&quot;,
        &quot;org.scala-lang:scala-compiler:$scalaVersion&quot;,
        'org.mortbay.jetty:jetty:6.1.22',
        'org.mortbay.jetty:jetty-util:6.1.22',
        'org.mortbay.jetty:jetty-management:6.1.22'

    providedCompile 'javax.servlet:servlet-api:2.5'
}

task wrapper(type: Wrapper) {
    gradleVersion = '0.9-preview-1'
}
</pre>
<p>In order to run a task you use the syntax</p>
<pre>$ ./gradlew taskName</pre>
<p>This will install gradle if it&#8217;s not already installed and then execute the specified task in the build script. So to compile the project and load it within the built-in Jetty web server, use the following command:</p>
<pre>$ ./gradlew jettyRun</pre>
<p>Running this (and ignore the warnings about multiple SLF4J bindings, this is a <a href="http://jira.codehaus.org/browse/GRADLE-897">bug</a> in the built-in jettyRun task) and  then browsing to http://localhost:8080 should show something like this:</p>
<p><a href="http://jeppenejsum.files.wordpress.com/2010/04/screen-shot-2010-04-16-at-15-39-02.png"><img class="aligncenter size-full wp-image-244" title="Screen shot 2010-04-16 at 15.39.02" src="http://jeppenejsum.files.wordpress.com/2010/04/screen-shot-2010-04-16-at-15-39-02.png?w=570&#038;h=264" alt="" width="570" height="264" /></a></p>
<p>To package the project such that it can be moved to a standalone web server, you can create a war file by executing</p>
<pre>$ ./gradlew war</pre>
<p>This will create the file <em>build/libs/liftstart.war</em> which can be copied to the apps directory of any servlet container.</p>
<h1>Next steps</h1>
<p>Ok, so you&#8217;ve created a Lift project and know how to run it using Gradle. So go crazy and start hacking!</p>
<p>But as you&#8217;ve probably noted, this is not exactly an efficient workflow since compiling everything from scratch takes quite a while. In a future post I&#8217;ll explain how to setup a fairly rapid development environment using Eclipse and JRebel.</p>
<br />Filed under: <a href='http://jeppenejsum.wordpress.com/category/scala/lift-scala/'>lift</a>, <a href='http://jeppenejsum.wordpress.com/category/scala/'>scala</a> Tagged: <a href='http://jeppenejsum.wordpress.com/tag/gradle/'>gradle</a>, <a href='http://jeppenejsum.wordpress.com/tag/lift/'>lift</a>, <a href='http://jeppenejsum.wordpress.com/tag/scala/'>scala</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeppenejsum.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeppenejsum.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jeppenejsum.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jeppenejsum.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jeppenejsum.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jeppenejsum.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jeppenejsum.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jeppenejsum.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jeppenejsum.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jeppenejsum.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jeppenejsum.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jeppenejsum.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jeppenejsum.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jeppenejsum.wordpress.com/230/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=230&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeppenejsum.wordpress.com/2010/04/16/lift-quick-start-look-ma-no-maven/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/acdc9f9dea04591decfd7992de3a6de9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jeppe</media:title>
		</media:content>

		<media:content url="http://jeppenejsum.files.wordpress.com/2010/04/screen-shot-2010-04-16-at-15-48-21.png" medium="image">
			<media:title type="html">Screen shot 2010-04-16 at 15.48.21</media:title>
		</media:content>

		<media:content url="http://jeppenejsum.files.wordpress.com/2010/04/screen-shot-2010-04-16-at-15-39-02.png" medium="image">
			<media:title type="html">Screen shot 2010-04-16 at 15.39.02</media:title>
		</media:content>
	</item>
		<item>
		<title>Scala and Lift &#8211; Status after six months</title>
		<link>http://jeppenejsum.wordpress.com/2010/01/18/scala-and-lift-status-after-six-months/</link>
		<comments>http://jeppenejsum.wordpress.com/2010/01/18/scala-and-lift-status-after-six-months/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 20:37:46 +0000</pubDate>
		<dc:creator>Jeppe</dc:creator>
				<category><![CDATA[lift]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://jeppenejsum.wordpress.com/?p=189</guid>
		<description><![CDATA[There are many choices to be made when starting a new project. In this post I&#8217;ll try to explain our technology choices and the experience we&#8217;ve had so far. Background One of the nice things about starting a new project in a startup is the freedom of choice when it comes to selecting platform and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=189&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There are many choices to be made when starting a new project. In this post I&#8217;ll try to explain our technology choices and the experience we&#8217;ve had so far.</p>
<h2>Background</h2>
<p>One of the nice things about starting a new project in a startup is the freedom of choice when it comes to selecting platform and tools. You can spend an awful lot of time mulling between the different choices, but in the end, it is usually not the choice of programming language that kills a startup.</p>
<p>First, a little background. I&#8217;ve been programming for more than 15 years in C++,VB,C#, Java,Perl &amp; PHP. The last 5-6 years it has been mostly enterprise Java. When I started at my last job (another startup) we had a product implemented in Java that we turned into a SaaS platform. The core remained in Java  and much of the web frontend was implemented in PHP. I really liked the productivity we got out of PHP as compared to the Java code. Very fast turnaround times. But somehow the language/platform doesn&#8217;t really  turn me on.<br />
<span id="more-189"></span></p>
<h2>So many tools, so little time</h2>
<p>So I knew I didn&#8217;t want to use pure Java or PHP,  in the end I ended up choosing between</p>
<ul>
<li>Ruby + Rails</li>
<li>Python + Django</li>
<li>Scala + Lift</li>
</ul>
<p>Despite the success of Rails in the past few years, it never really clicked with me. Granted I haven&#8217;t used it for more than a few weeks, but it never really felt natural.</p>
<p>Same with Django. I&#8217;ve used python on several occasions for scripting tasks, but never really for webapps.</p>
<p>So I ended up with Scala and Lift. I looked briefly at Scala in 2007, liking what I saw, but didn&#8217;t use it for anything serious. In the end, what made the difference was:</p>
<ol>
<li>Well known development and deployment platform (JVM, Build tools, IDEs, app servers etc)</li>
<li>Java interop, both for use of existing libraries but also as a fallback plan if everything failed.</li>
<li>Lift&#8217;s clean templating. We didn&#8217;t really need any of the real-time features (ie. comet support) in Lift, although the Ajax support looked nice.</li>
</ol>
<h2>Status</h2>
<p>So here we are, 6 months after development began. How has it been? In short: Not bad. We have a platform up and running, productivity is pretty good and getting better all the time.</p>
<p>When compared with Java code, our Scala/Lift code is not very verbose, but compared to Rails &amp; Django code I still feel it is (slightly) more verbose. I think this is because of the static typing that (despite type inferencing) requires quite a few type annotations. Otoh, when something type checks, it usually works <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h2>Scala</h2>
<h3>Pros</h3>
<p>Scala the language has a lot of benefits, many of which have already been described in other articles on the net. Here are some others  that I find important:</p>
<ul>
<li>Very concise, you can skip most types, parentheses, semicolons etc. Except when using parameterized types (generics). Here&#8217;s Hello World in Scala (using the Application trait is considered bad mojo for various reasons but ignore that for this example <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> )
<pre class="brush: java;">
object HelloWorld extends Application {
  println(&quot;Hello World&quot;)
}
</pre>
</li>
<li>You can start coding as you would in Java and gradually ease into the Functional Programming paradigm (if you want)</li>
<li>You can use all existing Java libraries</li>
<li>Very nice testing frameworks such as Specs, ScalaTest &amp; ScalaCheck</li>
<li>You can write very concise, readable code. E.g we have a dataset to be charted. It has a number of dataseries each having a number of values. To get the total of all values, we can just write this method</li>
<pre class="brush: java;">
  def sum = series.map(_.sum).foldLeft(0.0)(_+_)
</pre>
<p style="padding-left:15px;">which says, for each series, calculate the sum and then add all the results</p>
<li>Lazy parameters make logging code (which I think is very important, but is responsible for a lot of boilerplate) very readable. In Java you usually guard calls to logging to avoid the expensive computation of the string to be logged:</li>
<pre class="brush: java;">
if (log.isDebugEnabled() {
  log.debug(&quot;Here is the XML blob:&quot;+xml)
}
</pre>
<p style="padding-left:15px;">in Scala (or rather, Lift) you can, without loss of performance, just write</p>
<pre class="brush: java;">
  log.debug(&quot;Here is the XML blob:&quot;+xml)
</pre>
<p style="padding-left:15px;">The string to be logged will not be computed if debug log statements should not be logged.</p>
<li>Very easy to write meaningful DTOs. In Java, a lot of boiler plate is needed to make a class wih e.g. 3 properties. Often I would use an array (which will be untyped) or a tuple. Both suffer from the problem that you&#8217;ll have to know that the 2nd field is the customer id and the 3rd is the total amount. In Scala you can simply write a case-class and get named fields with typed access:
<pre class="brush: java;">
 case class MyRecord(id:Int, custNo:String, amount: Double)
</pre>
</li>
</ul>
<h3>Cons</h3>
<p>There are also a number of drawbacks to using the Scala language</p>
<ul>
<li>Tooling. We&#8217;re using the Scala 2.7.x plugin for Eclipse. While it works, there are a lot of bugs that means you&#8217;ll often have to rebuild the entire project for your changes to be seen. The 2.7.x version is basically abandoned and all work is going on in the 2.8 version which is supposedly much better. Unfortunately, we can&#8217;t switch to 2.8 until all the other tools we use are running on 2.8 (which is not in beta yet)</li>
<li>While type inference works, it&#8217;s not as powerful as in ML (and probably never will be. Scala&#8217;s type system has inheritance making it much harder to inference the correct types). It frequently requires you to add some type info. After a while you figure out where this is needed though.</li>
<li>The Scala compiler is rather slow. Fortunately, the Eclipse incremental compiler works most of the time.</li>
<li>The Scala book is very well written, but the API documentation is rather sparse. With most Java code I seldom have to use the source, but for the scala code it seems easier to start with the source.</li>
<li>The syntax can get quite ugly until you recognize the patterns. This is a problem since the documentation is rather bad. Parameterized types can can be especially bad I think. This is an example from the scala-user mailing list:</li>
<pre class="brush: java;">
implicit def TraversableBind[M[X] &lt;: Traversable[X]] = new Bind[M] {
  def bind[A, B](r: M[A], f: A =&gt; M[B])(implicit w: CanBuild[B, M[B]]): M[B] = r.flatMap(f)(breakOut)
}
</pre>
</ul>
<ul>
<li>No binary compatibility between Scala versions. This means that code compiled with Scala 2.7.3 is not (in general) compatible with code compiled with 2.7.5 and needs to be recompiled. This is not a big deal for our own code, but it does make it difficult to move to another version since all the Scala libraries used needs to be released first. I think this is also what has slowed down use of the forthcoming 2.8 release: people with sizable apps are waiting for the entire tool chain to be available and since 2.8 is not yet in beta, you need to agree on a version of 2.8 for everything.</li>
</ul>
<h2>Lift</h2>
<p>Overall, I like the Lift framework and how it utilizes the Scala language. The fundamental approach to request handling seem very well thought out and makes it easy to handle both traditional web apps, Ajax, REST APIs etc. The focus on Lift seems to get things done, not so much to create the perfect web framework abstraction that has all corner cases covered. This means most code has been battle tested, but sometimes you&#8217;ll wander along an untrodden path and strange things will happen.</p>
<h3>Pros</h3>
<ul>
<li>Without a doubt, the best thing about Lift is the community. Very friendly people, fast response to most questions. Eager to get newbies up to speed.</li>
<li>The Eclipse incremental compiler, Jetty &amp; the JRebel plugin makes for fairly rapid turnaround times even if it&#8217;s not in the same league as e.g. PHP &amp; Python. But many changes can be reloaded on the fly without having to restart the server.</li>
<li>Very fast to get a real app up and running. Prebuilt archetypes for a basic app with authentication and DB access.</li>
<li>Focus on security. Much effort has been put into making Lift apps secure. E.g. you cannot repost a form since the field ids are unique</li>
<li>The Lift ORM, Mapper, is fairly simple, but does provide a very quick way to get CRUD functionality up and running.</li>
<li>Very easy to add Ajax functionality (I can&#8217;t speak on the Comet functionality)</li>
<li>Pretty good i18n support. Strings, templates etc. can be locale dependent and the locale can be computed for each request if needed.</li>
<li>The clean separation between UI and code (it is impossible to have code in templates) makes it easy for designers to modify the layout and styling with breaking anything.</li>
<li>The focus on getting things done means if there&#8217;s a real use case, new features can be added fairly quickly. Same goes for bugs in production code.</li>
</ul>
<h3>Cons</h3>
<ul>
<li>API Documentation is very scarce. Usually, I use the source to figure out how stuff is working, but sometimes you need the big picture in order to get a good understanding. There is a free book available, but I usually don&#8217;t use this on a day to day basis.</li>
<li>Form handling is very basic. There isn&#8217;t really any form specific code in Lift, so making a real, usable form (with i18n, validation, etc) takes some effort.</li>
<li>Lift apps are very stateful. This is not a problem for us, but for apps that needs to be very horizontally  scalable, this is a showstopper. The problem is not easily solved, since it requires serialization of closures.</li>
<li>The Lift ORM, Mapper, is fairly simple, which means that for more complex scenarios it is somewhat difficult to extend, loosing some of the RAD capabilities</li>
<li>The focus on getting things done means that some areas are not really consistent or complete.</li>
<li>While you can&#8217;t get code into your templates, it&#8217;s easy to get UI into your code, which is (almost) just as bad. The dynamic part of the UI is done by snippets and they of course need to emit HTML. But it is easy to put all kinds of style, class attributes as well as other things which belong in the template, into this dynamically generated code. This makes it difficult for designers to modify the layout and styling without touching the Scala code.</li>
</ul>
<br />Posted in lift, scala Tagged: lift, scala <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeppenejsum.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeppenejsum.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jeppenejsum.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jeppenejsum.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jeppenejsum.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jeppenejsum.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jeppenejsum.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jeppenejsum.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jeppenejsum.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jeppenejsum.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jeppenejsum.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jeppenejsum.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jeppenejsum.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jeppenejsum.wordpress.com/189/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=189&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeppenejsum.wordpress.com/2010/01/18/scala-and-lift-status-after-six-months/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/acdc9f9dea04591decfd7992de3a6de9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jeppe</media:title>
		</media:content>
	</item>
		<item>
		<title>Making libmp3lame work with ffmpeg on OS X</title>
		<link>http://jeppenejsum.wordpress.com/2009/10/27/making-libmp3lame-work-with-ffmpeg-on-os-x/</link>
		<comments>http://jeppenejsum.wordpress.com/2009/10/27/making-libmp3lame-work-with-ffmpeg-on-os-x/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 22:27:37 +0000</pubDate>
		<dc:creator>Jeppe</dc:creator>
				<category><![CDATA[mac]]></category>

		<guid isPermaLink="false">http://jeppenejsum.wordpress.com/?p=181</guid>
		<description><![CDATA[I wanted to convert some youtube footage to mp3 by using the Firefox addon DownloadHelper together with ffmpeg. Ok, installed ffmpeg on OS X using MacPorts: sudo port install ffmpeg +gpl +lame +x264 +xvid Tried to convert a file. Got this error: [libmp3lame @ 0x1804600]lame: output buffer too small (buffer index: 8360, free bytes: 1432) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=181&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I wanted to convert some youtube footage to mp3 by using the Firefox addon DownloadHelper together with ffmpeg. </p>
<p>Ok, installed ffmpeg on OS X using MacPorts:</p>
<pre>
sudo port install ffmpeg +gpl +lame +x264 +xvid
</pre>
<p>Tried to convert a file. Got this error:</p>
<pre>
[libmp3lame @ 0x1804600]lame: output buffer too small (buffer index: 8360, free bytes: 1432)
</pre>
<p><span id="more-181"></span><br />
Turns out this is a known bug with version 3.98.2 of libmp3lame, which, incidentally is the latest version on MacPorts.</p>
<p>I tried version 3.98 and it seems to work.<br />
<a href="http://trac.macports.org/wiki/howto/InstallingOlderPort">This</a> guide tells how to install an older version of a port. </p>
<p>To save you some trouble, these are the steps I took to make it work:</p>
<pre>
cd /tmp
curl -O http://trac.macports.org/export/38059/trunk/dports/audio/lame/Portfile
sudo port install
</pre>
<p>Voila! ffmpeg can now generate mp3s without errors.</p>
<br />Posted in mac  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeppenejsum.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeppenejsum.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jeppenejsum.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jeppenejsum.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jeppenejsum.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jeppenejsum.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jeppenejsum.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jeppenejsum.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jeppenejsum.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jeppenejsum.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jeppenejsum.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jeppenejsum.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jeppenejsum.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jeppenejsum.wordpress.com/181/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=181&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeppenejsum.wordpress.com/2009/10/27/making-libmp3lame-work-with-ffmpeg-on-os-x/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/acdc9f9dea04591decfd7992de3a6de9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jeppe</media:title>
		</media:content>
	</item>
		<item>
		<title>Using twitter to maintain an operations log</title>
		<link>http://jeppenejsum.wordpress.com/2009/10/01/using-twitter-as-operations-log/</link>
		<comments>http://jeppenejsum.wordpress.com/2009/10/01/using-twitter-as-operations-log/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 15:46:13 +0000</pubDate>
		<dc:creator>Jeppe</dc:creator>
				<category><![CDATA[automation]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://jeppenejsum.wordpress.com/?p=170</guid>
		<description><![CDATA[Whenever you&#8217;re dealing with a system that changes over time, at some point you&#8217;ll find it useful to go back and see what changes were made 3 weeks ago. And then you wish you belong to the (small?) group of people who write down every change to a log file, so you can answer this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=170&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Whenever you&#8217;re dealing with a system that changes over time, at some point you&#8217;ll find it useful to go back and see what changes were made 3 weeks ago.</p>
<p>And then you wish you belong to the (small?) group of people who write down every change to a log file, so you can answer this question.</p>
<p>I&#8217;m not in this group but have had this need often enough that I&#8217;ve tried to automate at least some of the logging.<br />
<span id="more-170"></span></p>
<h1>Twitter to the rescue</h1>
<p>Lately, I&#8217;ve started using  twitter to maintain a timestamped log of the changes we&#8217;re making to our production system. It&#8217;s very easy to create a dummy twitter account (and make it private if you don&#8217;t want to expose all your production info to the public!) for the purpose of tracking these changes.</p>
<p>Since everybody else in the company is already using twitter, it&#8217;s very easy, for those who wants this info, to follow this user and get updates whenever something interesting happens.</p>
<h2>Posting an update</h2>
<p>Twitter has a decent API to access the functionality and posting a new update can be done from the <a href="http://apiwiki.twitter.com/Things-Every-Developer-Should-Know#8AcommandlineisallyouneedtousetheTwitterAPInbsp">command line, using curl</a>. This makes it easy to post updates from all kinds of places such as build scripts, boot scripts, cron jobs etc.</p>
<p>Since we&#8217;re using Gradle to handle all our builds and automation, we can define a Groovy function called tweet, which can be used throughout the scripts:</p>
<pre class="brush: jscript;">
def tweet(msg) {
  ant.exec(executable:&quot;curl&quot;) {
    arg(line: &quot;--user twitteruser:twitterpassword&quot;)
    arg(line: &quot;--data-ascii \&quot;status=$msg\&quot;&quot;)
    arg(line: &quot;--silent&quot;)
    arg(value: &quot;http://twitter.com/statuses/update.json&quot;)
  }
}
</pre>
<p>If you&#8217;re doing any manual changes (but of course you don&#8217;t, right? Everything is scripted and put under version control <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ), you can always manually post an update for the account by using a multi-account aware twitter client.</p>
<h1>What to post</h1>
<p>So, what can you use this for? Well, you probably shouldn&#8217;t post highly sensitive stuff, even if it&#8217;s on a private twitter account. But, basically as much useful info as possible. This is when we currently do updates:</p>
<ul>
<li>Whenever a new deployment is about to start</li>
<li>When a deployment is complete (with links to new features, bug solved etc)</li>
<li>When a new EC2 instance is booting</li>
<li>Any changes made to the AWS setup</li>
<li>Etc.</li>
</ul>
<br />Posted in automation Tagged: automation, deployment, twitter <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeppenejsum.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeppenejsum.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jeppenejsum.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jeppenejsum.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jeppenejsum.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jeppenejsum.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jeppenejsum.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jeppenejsum.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jeppenejsum.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jeppenejsum.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jeppenejsum.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jeppenejsum.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jeppenejsum.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jeppenejsum.wordpress.com/170/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=170&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeppenejsum.wordpress.com/2009/10/01/using-twitter-as-operations-log/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/acdc9f9dea04591decfd7992de3a6de9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jeppe</media:title>
		</media:content>
	</item>
		<item>
		<title>Beware of Scala&#8217;s lazy Range in for/yield</title>
		<link>http://jeppenejsum.wordpress.com/2009/07/04/beware-of-scalas-lazy-range-in-foryield/</link>
		<comments>http://jeppenejsum.wordpress.com/2009/07/04/beware-of-scalas-lazy-range-in-foryield/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 15:25:41 +0000</pubDate>
		<dc:creator>Jeppe</dc:creator>
				<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://jeppenejsum.wordpress.com/?p=158</guid>
		<description><![CDATA[I&#8217;m currently using Scala for most of our development and like it a lot. Coming from a mostly Java background, it is nice with a familiar execution environment and tools. But there a few things that has bitten me, one which I just spend almost an hour trying to nail. So I&#8217;m posting it here [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=158&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently using Scala for most of our development and like it a lot. Coming from a mostly Java background, it is nice with a familiar execution environment and tools. But there a few things that has bitten me, one which I just spend almost an hour trying to nail. So I&#8217;m posting it here hoping it might save somebody in the future.</p>
<p>Scala has a nice mechanism for creating lists with a for comprehension:</p>
<pre class="brush: jscript;">
val l = for (...) yield computeResult(...)
</pre>
<p>Basically, l will become the  list of return values from  computeResult. Cool.</p>
<p>Scala also has Range class that, together with the for comprehension mimics a standard for-loop construct:</p>
<pre class="brush: jscript;">
for(i &lt;- 1 to 20) {
 ...
}
</pre>
<h2>Problem</h2>
<p>I had the following case. I needed to create some objects in a database and return the results in a list. So I created something that looked like the following:</p>
<pre class="brush: jscript;">
val databaseObjects = for(i &lt;- 1 to 20) yield {
  val o = CreateObject
  o
}
</pre>
<p>When I ran this code, nothing happened?! I checked the DB, no records to be found anywhere. I tried printing the object o inside the loop. Nothing got printed. Tried the construct in the Scala REPL. Everything worked fine. Then I tried printing databaseObjects.length after the loop. Shows that 20 objects were created. Hmmmm. Then I tried printing all elements of databaseObjects. They were created just fine. Hmmmmm.</p>
<p>I recalled  a discussion about the Range being created by the expression &#8220;1 to 20&#8243; is a lazy data structure which is not evaluated before the results are needed. Turns out this lazyness is contagious (more details can be found <a href="http://www.eishay.com/2009/06/unexpected-repeated-execution-in-scala.html">here</a>)  Ahhhh. Everything makes sense now, since nothing happened until I tried to actually fetch the objects from the list (and the REPL implicitly retrieves the objects to print out the results!)</p>
<h2>Solution</h2>
<p>The fix is easy, you need to force the lazy range:</p>
<pre class="brush: jscript;">
val databaseObjects = for(i &lt;- (1 to 20).force) yield {
</pre>
<br />Posted in scala Tagged: scala <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeppenejsum.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeppenejsum.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jeppenejsum.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jeppenejsum.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jeppenejsum.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jeppenejsum.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jeppenejsum.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jeppenejsum.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jeppenejsum.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jeppenejsum.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jeppenejsum.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jeppenejsum.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jeppenejsum.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jeppenejsum.wordpress.com/158/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=158&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeppenejsum.wordpress.com/2009/07/04/beware-of-scalas-lazy-range-in-foryield/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/acdc9f9dea04591decfd7992de3a6de9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jeppe</media:title>
		</media:content>
	</item>
		<item>
		<title>EC2 Continuous Deployment: Wrapping up</title>
		<link>http://jeppenejsum.wordpress.com/2009/05/25/ec2-continuous-deployment-wrapping-up/</link>
		<comments>http://jeppenejsum.wordpress.com/2009/05/25/ec2-continuous-deployment-wrapping-up/#comments</comments>
		<pubDate>Mon, 25 May 2009 19:13:03 +0000</pubDate>
		<dc:creator>Jeppe</dc:creator>
				<category><![CDATA[continuous deployment]]></category>
		<category><![CDATA[chef]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[gradle]]></category>
		<category><![CDATA[hudson]]></category>

		<guid isPermaLink="false">http://jeppenejsum.wordpress.com/?p=123</guid>
		<description><![CDATA[Note: This is the fifth (and last!) article in the series on continuous deployment. If you want to start with the overview, go here. Finally, we&#8217;re coming to the end of the road. The only things left in order to finish the continuous deployment cycle are these steps: Run integration tests Shutdown instance Add new [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=123&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>Note: This is the fifth (and last!) article in the series on continuous deployment. If you want to start with the overview, go </em><a href="/2009/05/03/ec2-continuous-deployment-hello-world/"><em>here</em></a><em>.</em></p>
<p>Finally, we&#8217;re coming to the end of the road. The only things left in order to finish the continuous deployment cycle are these steps:</p>
<ul>
<li>Run integration tests</li>
<li>Shutdown instance</li>
<li>Add new nightly job to Hudson that runs the integration tests</li>
</ul>
<p><span id="more-123"></span></p>
<h2>Running integration tests</h2>
<p>Normally, you would use something like Selenium to do browser-based integration tests, but configuring Selenium RC is outside the scope of these articles (though, you could provision new EC2 instances and run Selenium Grid to test the app from various browsers, even running on Windows. Hmmm, maybe there&#8217;s some material here for another article series <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> )</p>
<p>To demonstrate the principle, lets create a simple task that performs a crude test to verify that the site is at least running</p>
<pre class="brush: java;">
createTask('integrationTest', dependsOn: 'testDeploy') {
	try {
		client = new org.apache.commons.httpclient.HttpClient()
		method = new org.apache.commons.httpclient.methods.GetMethod(&quot;http://$createInstance.dnsName/&quot;)
		client.executeMethod(method)
		def s = method.responseBodyAsString
		if (s.indexOf(&quot;Welcome to the final helloworld project!&quot;) &lt; 0) {
			println s
			throw new RuntimeException(&quot;Test failed&quot;)
		}
	} finally {
		ec2.terminateInstances([createInstance.instanceId])
	}
 }
</pre>
<p>Note, that we shutdown the instance at the end.</p>
<p>Now it should be straightforward to add a new Hudson job that runs at night and executes the <code>integrationTest</code> task. This is left as an exercise to the reader!</p>
<h2>Where to go from here</h2>
<p>This concludes the article series on continuous deployment. The example webapp is very crude, and the target stack rather simple, but this series does describe a complete end-to-end example of how to automate the deployment and testing of a webapp. Expanding on each of the steps in order to match a more realistic scenario should not be insurmountable.</p>
<p>But what I&#8217;ve presented here is just the nimble beginning. I know Amazon AWS is not the cheapest hosting you can get, but it does provide you with a lot of flexibility. Here are just some of the possibilities:</p>
<ul>
<li>The single server architecture we&#8217;ve used in this example is probably too simplistic in all but the smallest setups. But it is easy to extend even your nightly builds to include a more realistic setup including a load balancer, a few web servers, a few app servers and a database server.</li>
<li>If you&#8217;re using EBS to store your data, it is very simple to get a replica of your production data by taking a snapshot of your EBS volumes and then mount them in your testing environment. Then you can also test your DB upgrade scripts.</li>
<li>Extend integration tests to do browser-based testing using different browsers. This should be possible now that EC2 supports windows instances.</li>
<li>Use Chef to deploy a new version of the application without downtime.  You can easily start new app servers with the new code and start routing (perhaps just some?) requests to the new version. When everything looks ok, you can take down the old instances. Of course this would probably require support from the application, since it needs to coexist on the same database with different code bases etc.</li>
</ul>
<h2>Source code</h2>
<p>All the code in this example is available on GitHub <a href="http://github.com/jeppenejsum/helloworld/tree/master">http://github.com/jeppenejsum/helloworld/tree/master</a></p>
<br />Posted in continuous deployment Tagged: chef, continuous integration, ec2, gradle, hudson <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeppenejsum.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeppenejsum.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jeppenejsum.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jeppenejsum.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jeppenejsum.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jeppenejsum.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jeppenejsum.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jeppenejsum.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jeppenejsum.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jeppenejsum.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jeppenejsum.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jeppenejsum.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jeppenejsum.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jeppenejsum.wordpress.com/123/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=123&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeppenejsum.wordpress.com/2009/05/25/ec2-continuous-deployment-wrapping-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/acdc9f9dea04591decfd7992de3a6de9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jeppe</media:title>
		</media:content>
	</item>
		<item>
		<title>EC2 Continuous Deployment: Cooking with Chef and a stint of Gradle</title>
		<link>http://jeppenejsum.wordpress.com/2009/05/11/ec2-continuous-deployment-cooking-with-chef-and-a-stint-of-gradle/</link>
		<comments>http://jeppenejsum.wordpress.com/2009/05/11/ec2-continuous-deployment-cooking-with-chef-and-a-stint-of-gradle/#comments</comments>
		<pubDate>Mon, 11 May 2009 07:41:52 +0000</pubDate>
		<dc:creator>Jeppe</dc:creator>
				<category><![CDATA[continuous deployment]]></category>
		<category><![CDATA[chef]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[gradle]]></category>
		<category><![CDATA[groovy]]></category>

		<guid isPermaLink="false">http://jeppenejsum.wordpress.com/?p=90</guid>
		<description><![CDATA[Note: This is the fourth article in the series on continuous deployment. If you want to start with the overview, go here. What we&#8217;ve done so far is a pretty basic Continuous Integration setup. To take this to the next level, we&#8217;ll add a new job, to be run at night, that provisions and configures [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=90&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>Note: This is the fourth article in the series on continuous deployment. If you want to start with the overview, go </em><a href="/2009/05/03/ec2-continuous-deployment-hello-world/"><em>here</em></a><em>.</em></p>
<p>What we&#8217;ve done so far is a pretty basic Continuous Integration setup. To take this to the next level, we&#8217;ll add a new job, to be run at night, that provisions and configures a new EC2 instance, deploys the application and runs the integration tests.</p>
<p>The steps that needs to be executed are</p>
<ul>
<li>Start a new EC2 instance</li>
<li>Configure the instance with all the software needed to run the application (in our case Jetty &amp; nginx)</li>
<li>Deploy the application</li>
<li>Run the integration tests</li>
<li>Shutdown the instance</li>
</ul>
<p><span id="more-90"></span></p>
<h2>Chef</h2>
<p><a href="http://wiki.opscode.com/display/chef/Home">Chef</a> is a new tool for automated infrastructure management. Like Gradle it&#8217;s a task specific DSL (for managing infrastructure) based on a scripting language (Ruby).</p>
<p>For a full Chef implementation, you would run a Chef server that knows everything about your infrastructure. It also holds your Cookbook which is a collection of recipes, where each recipe describes how to install/configure some software on a node. New nodes will run chef-client to configure the node according to the &#8220;recipes&#8221; defined on the sever.</p>
<p>But the nice thing about Chef is that it also seems to scale down to the quite simple scenario we are going to use here, which won&#8217;t be using the client/server setup but the chef-solo command. This will still execute recipes to configure the node (and those same recipes can be used in the full scale setup), but will not need a Chef server.</p>
<h2>The helloworld recipe</h2>
<p>Whenever a node is brought up it should have a specific role (i.e. db server, web server, app server etc). I think it makes sense to create a recipe for each role and then have that recipe contain all the stuff that needs to be installed and configured for this role. In our example, we only have a single role, helloworld, which will contain</p>
<ul>
<li>nginx web server</li>
<li>Jetty6 application server</li>
<li>The helloworld application</li>
</ul>
<p>This is specified in the recipe shown below. It basically includes recipes for the dependencies nginx and jetty (which in turn depends on java). After the prerequisites are installed, we download the helloworld application from S3 and put it into the Jetty webapps dir. Finally, we restart jetty6 to deploy the application.</p>
<p>Note that the source of the war file is specified as <code>source node[:war]</code>. This means the actual value is a property of the node configuration. In a full Chef setup the value will come from the Chef server, but when running chef-solo we will specify the node properties in a file called dna.json.</p>
<p>Unfortunately, until this <a href="http://tickets.opscode.com/browse/CHEF-269">bug</a> is fixed in Chef, the URL cannot contain special characters.  When using S3, this means you cannot create a signed URL for the war file but need to make the file public readable. Hopefully it will be fixed soon (the fix is simple, see ticket)</p>
<pre class="brush: ruby;">
include_recipe &quot;jetty&quot;
include_recipe &quot;nginx&quot;

remote_file &quot;helloworld_war&quot; do
        path &quot;/usr/share/jetty6/webapps/ROOT.war&quot;
        owner &quot;jetty&quot;
        mode  0640
        source node[:war]
end

service &quot;jetty6&quot; do
  action :restart
end
</pre>
<h2>The jetty recipe</h2>
<p>The previous recipe was very simple (which is a good thing <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . The jetty recipe is a little more involved and shows some of the power in Chef. It installs a few packages (using Apt ), downloads a number of deb files, installs them, configures the package defaults and enables the startup script.</p>
<pre class="brush: ruby;">
include_recipe &quot;java&quot;
# Needed by jetty extra &amp; jsp
%w{ ant libgnujaf-java libgnumail-java }.each do |pkg|
 package pkg do
 action :install
 end
end

jetty_version = &quot;6.1.16_all&quot;
jetty_debs = %w{libjetty6-java libjetty6-jsp-java libjetty6-extra-java jetty6}

jetty_debs.each do |deb|
 remote_file deb do
 path &quot;/tmp/#{deb}_#{jetty_version}.deb&quot;
 source &quot;http://dist.codehaus.org/jetty/jetty-6.1.16/debs/#{deb}_#{jetty_version}.deb&quot;
 end
end

bash &quot;install-jetty&quot; do
 code &quot;cd /tmp &amp;&amp; dpkg --install *jetty6*.deb&quot;
end

bash &quot;enable-jetty&quot; do
 code &quot;sed s/NO_START=1/NO_START=0/ -i /etc/default/jetty6&quot;
end

service &quot;jetty6&quot; do
 supports :restart =&gt; true, :reload =&gt; true
 action [ :enable, :start ]
end
</pre>
<p>Chef comes with <a href="http://github.com/opscode/cookbooks/tree/master">recipes</a> for many packages, including java and nginx, and they are a good inspiration.</p>
<h2>Bootstrapping an EC2 instance</h2>
<p>Before we can begin cooking, we need to launch an EC2 instance. Since Gradle scripts are Groovy scripts, we can perform all this directly in our build scripts by creating a few new tasks &amp; methods. By using the Java libraries <a href="http://code.google.com/p/typica/">Typica </a>and <a href="https://jets3t.dev.java.net/">Jets3t</a>, it is relatively easy to perform these tasks. I&#8217;ll not go through all the code here, just highlight a few points.</p>
<pre class="brush: java;">
createTask('testDeploy', dependsOn:['libs','createInstance']) {
  urls = uploadCookbooksToS3()
  bootstrap(urls[0], urls[1])
}

createTask('createInstance', dependsOn: 'libs') {
  def config = new LaunchConfiguration(imageId)
  config.keyName = ec2keyname
  def instances = ec2.runInstances(config)
  def instance = instances.instances.get(0)
  createInstance.instanceId = instance.instanceId
  println &quot;Started instance with id $createInstance.instanceId&quot;
}
</pre>
<p>The <code>testDeploy</code> task depends on the <code>createInstance</code> task, which is the task that actually launches the EC2 instance. I&#8217;m using a RightScale Ubuntu AMI which includes Ruby and rubygem. The instance id is stored as a property of the <code>createInstance</code> task. The <code>uploadCookboksToS3</code> method, uploads the cookbook with all the recipes to S3 and creates and uploads the following <code>dna.json</code> file</p>
<pre class="brush: jscript;">
{&quot;war&quot;: &quot;http://mys3bucket.s3.amazonaws.com/helloworld-1.war&quot;, &quot;recipes&quot;: &quot;helloworld&quot;}
</pre>
<p>This file contains the URL to the war file to be used by the helloworld recipe as well as the list of recipes that should be installed on the node. <code>uploadCookbooksToS3</code> returns URLs for the cookbook.tgz and dna.json files which are needed to download from S3. The bootstrap method first waits for the EC2 instance to fully boot and then performs the following tasks:</p>
<pre class="brush: java;">
  sshExec(&quot;gem install --no-ri --no-rdoc ohai chef --source http://gems.opscode.com --source http://gems.rubyforge.org&quot;);
  ant.scp(passphrase:&quot;&quot;, todir: &quot;root@$createInstance.dnsName:&quot;, trust: true, keyfile: ec2KeyFile) {
		fileset(dir: &quot;deployment&quot;) {
			include(name: &quot;solo.rb&quot;)
		}
	}
  sshExec(&quot;chef-solo -c solo.rb -j '$dnaURL' -l info -r '$cookbookURL'&quot;);
</pre>
<p>Basically,</p>
<ul>
<li>Install Chef using gem</li>
<li>Copy the solo.rb config file to the instance</li>
<li>Configure the node by calling chef-solo with URLs for the dna &amp; cookbook files</li>
</ul>
<p>Chef will now download the recipes and run them to configure the node.</p>
<p>What we have accomplished so far is that when you type</p>
<pre>$ gradle testDeploy</pre>
<p>You can sit back and wait for a few minutes. When all is done, you can point your browser to the public DNS of the EC2 instance and &#8230;tadaaa&#8230;..you should see something like this:</p>
<p><img class="aligncenter size-full wp-image-116" title="helloworld" src="http://jeppenejsum.files.wordpress.com/2009/05/helloworld.png?w=510&#038;h=222" alt="helloworld" width="510" height="222" /></p>
<p>This might not be a very impressive application but you can find resources on the net that enable you to write a Twitter clone in Lift in 30 minutes. You might need a little more advanced deployment architecture though <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<br />Posted in continuous deployment Tagged: chef, deployment, ec2, gradle, groovy <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeppenejsum.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeppenejsum.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jeppenejsum.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jeppenejsum.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jeppenejsum.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jeppenejsum.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jeppenejsum.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jeppenejsum.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jeppenejsum.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jeppenejsum.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jeppenejsum.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jeppenejsum.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jeppenejsum.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jeppenejsum.wordpress.com/90/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=90&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeppenejsum.wordpress.com/2009/05/11/ec2-continuous-deployment-cooking-with-chef-and-a-stint-of-gradle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/acdc9f9dea04591decfd7992de3a6de9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jeppe</media:title>
		</media:content>

		<media:content url="http://jeppenejsum.files.wordpress.com/2009/05/helloworld.png" medium="image">
			<media:title type="html">helloworld</media:title>
		</media:content>
	</item>
		<item>
		<title>EC2 Continuous Deployment: Managing the build process</title>
		<link>http://jeppenejsum.wordpress.com/2009/05/06/ec2-continuous-deployment-managing-the-build-process/</link>
		<comments>http://jeppenejsum.wordpress.com/2009/05/06/ec2-continuous-deployment-managing-the-build-process/#comments</comments>
		<pubDate>Wed, 06 May 2009 17:41:28 +0000</pubDate>
		<dc:creator>Jeppe</dc:creator>
				<category><![CDATA[continuous deployment]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[gradle]]></category>
		<category><![CDATA[hudson]]></category>

		<guid isPermaLink="false">http://jeppenejsum.wordpress.com/?p=39</guid>
		<description><![CDATA[Note: This is the third article in the series on continuous deployment. If you want to start with the overview, go here. We can now build our application manually, but need to automate the actual build process. For this I&#8217;ll be using the Hudson Extensible continuous integration engine. I&#8217;ve been using CruiseControl for many years, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=39&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>Note: This is the third article in the series on continuous deployment. If you want to start with the overview, go </em><a href="/2009/05/03/ec2-continuous-deployment-hello-world/"><em>here</em></a><em>.</em></p>
<p>We can now build our application manually, but need to automate the actual build process. For this I&#8217;ll be using the <a href="https://hudson.dev.java.net/">Hudson</a> Extensible continuous integration engine. I&#8217;ve been using CruiseControl for many years, and while it does the job, I&#8217;ve been annoyed enough that I&#8217;ll try something new.</p>
<p><span id="more-39"></span></p>
<h2>Add the source to a repository</h2>
<p>All CI systems need to get the source from a SCM so that the code that is being built is in a well defined state. So let&#8217;s  add the source of the webapp to a SCM, in this case github.com.</p>
<pre>$ git init
$ git add *
$ git remote add origin git@github.com:jeppenejsum/helloworld.git
$ git commit
$ git push origin master</pre>
<p>Now all the sample code is available here <a href="http://github.com/jeppenejsum/helloworld/tree/master">http://github.com/jeppenejsum/helloworld/tree/master</a></p>
<h2>Install Hudson</h2>
<p>While you could use Amazon EC2 to host your build server, it takes some time to configure with persistent storage, mail server etc. Since this is not the main focus of these articles, I&#8217;ll just use our existing Xen infrastructure. Provisioning a new server running Debian Lenny is simple (when xen-tools is configured correctly):</p>
<pre># xen-create-image --hostname buildserver --mac 00:16:3E:55:42:8E
# xm create /etc/xen/buildserver.cfg</pre>
<p>Now sign in to the new VM and install the necessary prerequisite software:</p>
<pre># apt-get update &amp;&amp; apt-get upgrade &amp;&amp; apt-get install sun-java6-jdk git-core<tt> daemon subversion unzip</tt>
# git config --global user.email "you@example.com"
# git config --global user.name "Your Name"</pre>
<p>There seems to be a <a href="http://weblogs.java.net/blog/kohsuke/archive/2008/06/debian_packages.html">Debian repository</a> for Hudson, but it&#8217;s very unstable so we&#8217;ll just install directly from the .deb files:</p>
<pre># cd /tmp &amp;&amp; wget http://hudson.gotdns.com/debian/binary/hudson_1.303_all.deb &amp;&amp; dpkg --install hudson_1.303_all.deb</pre>
<p>Install Gradle as previously described <a href="/2009/05/04/ec2-continuous-deployment-building-the-software/">here</a>.</p>
<p>Restart the server to make sure the service is started automatically. After you&#8217;ve done this, point your browser to the buildserver at port 8080. You should see something like this:</p>
<p><img class="aligncenter size-full wp-image-77" title="hudson" src="http://jeppenejsum.files.wordpress.com/2009/05/hudson.png?w=510&#038;h=332" alt="hudson" width="510" height="332" /></p>
<h3>Install Hudson plugins</h3>
<p>We need to configure a number of Hudson plugins, goto http://buildserver:8080/pluginManager/available and install the following plugins:</p>
<ul>
<li>Git plugin &#8211; For access to github.com</li>
<li>Gradle plugin &#8211; Since we use Gradle to build the software</li>
</ul>
<p>Restart Hudson for the changes to take effect</p>
<pre># /etc/init.d/hudson restart</pre>
<h3>Configure</h3>
<p>The Gradle plugin needs to be configured. Go to http://buildserver:8080/configure and enter the path</p>
<p><img class="aligncenter size-full wp-image-79" title="gradle" src="http://jeppenejsum.files.wordpress.com/2009/05/gradle.png?w=510&#038;h=111" alt="gradle" width="510" height="111" /></p>
<p>You should also configure SMTP as appropriate for your system. If you have a Gmail account, you can use this for sending email.</p>
<h2>Setup smoke test to build on new commits</h2>
<p>Now that we&#8217;ve installed and configured Hudson, it&#8217;s (finally) time to configure a smoke test to build whenever changes are comitted to the application. This build should be quick in order to provide quick feedback to developers on their last commit. I usually include the following:</p>
<ul>
<li>Compile the entire application</li>
<li>Run all unit tests</li>
</ul>
<p>but don&#8217;t include any packaging, integration tests or other long running test cases in this task. Incidentally? the above is eactly what happens when we execute the default <em>test </em>task on our Gradle build file.</p>
<p>The steps are</p>
<ul>
<li>Click &#8220;New Job&#8221;</li>
<li>Enter jobname &#8220;Helloworld smoke test&#8221;</li>
<li>The type should be &#8220;Build a free-style software project&#8221;</li>
<li>Click &#8220;Ok&#8221;</li>
</ul>
<p>On the next page, fill out the following sections and tweak as you see fit:</p>
<p style="text-align:center;"><a href="http://jeppenejsum.files.wordpress.com/2009/05/smoke1.png"><img class="aligncenter size-full wp-image-86" title="smoke1" src="http://jeppenejsum.files.wordpress.com/2009/05/smoke1.png?w=306&#038;h=495" alt="smoke1" width="306" height="495" /></a></p>
<h2 style="text-align:left;">Verify</h2>
<p>Press the &#8220;Build Now&#8221; link and the code should build. If you push any changes to github, the code should compile and you should receive an email if anything fails (compilation or tests).</p>
<br />Posted in continuous deployment Tagged: continuous integration, gradle, hudson <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeppenejsum.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeppenejsum.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jeppenejsum.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jeppenejsum.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jeppenejsum.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jeppenejsum.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jeppenejsum.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jeppenejsum.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jeppenejsum.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jeppenejsum.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jeppenejsum.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jeppenejsum.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jeppenejsum.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jeppenejsum.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeppenejsum.wordpress.com&amp;blog=4998745&amp;post=39&amp;subd=jeppenejsum&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeppenejsum.wordpress.com/2009/05/06/ec2-continuous-deployment-managing-the-build-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/acdc9f9dea04591decfd7992de3a6de9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Jeppe</media:title>
		</media:content>

		<media:content url="http://jeppenejsum.files.wordpress.com/2009/05/hudson.png" medium="image">
			<media:title type="html">hudson</media:title>
		</media:content>

		<media:content url="http://jeppenejsum.files.wordpress.com/2009/05/gradle.png" medium="image">
			<media:title type="html">gradle</media:title>
		</media:content>

		<media:content url="http://jeppenejsum.files.wordpress.com/2009/05/smoke1.png" medium="image">
			<media:title type="html">smoke1</media:title>
		</media:content>
	</item>
	</channel>
</rss>
