Friday, February 22, 2008

Maven + Artifactory + Continuum

All right then - so I set up my very own (i.e. my team's) Continuous Integration environment. I used:

I installed the whole environment on Linux machine with Java 5.0. I started with Maven 2 and Apache Tomcat 6.x.
Next I downloaded Artifactory and Continuum WAR's and changed their names to artifactory.war and continuum.war accordingly (basically I removed version info).
Then I copied those two WAR's wo TOMCAT_HOME/webapps directory.
Next I configured Atrifactory and Continuum according to their documentation pages - I didn't change anything. It's pretty straightforward.
I also created empty web application TOMCAT_HOME/webapps/projects whose goal is to serve deployed maven sites. This application should have configured WebDAV interface. In order to do this I created WEB-INF/web.xml file for this webapp with following contents:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">

<display-name>Webdav Content Management</display-name>
<description>
Webdav Content Management
</description>

<servlet>
<servlet-name>webdav</servlet-name>
<servlet-class>org.apache.catalina.servlets.WebdavServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<!-- Uncomment this to enable read and write access -->

<init-param>
<param-name>readonly</param-name>
<param-value>false</param-value>
</init-param>

<!--load-on-startup>1</load-on-startup-->
</servlet>

<!-- The mapping for the webdav servlet -->
<servlet-mapping>
<servlet-name>webdav</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

<security-constraint>
<web-resource-collection>
<web-resource-name>The Entire Web Application</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>PUT</http-method>
<http-method>POST</http-method>
<http-method>DELETE</http-method>
<http-method>PROPFIND</http-method>
<http-method>PROPPATCH</http-method>
<http-method>MKCOL</http-method>
<http-method>COPY</http-method>
<http-method>MOVE</http-method>
<http-method>LOCK</http-method>
<http-method>UNLOCK</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>

<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Tomcat Supported Realm</realm-name>
</login-config>

<security-role>
<description>
An example role defined in "conf/tomcat-users.xml"
</description>
<role-name>admin</role-name>
</security-role>
</web-app>


I also had to add tomcat user to TOMCAT_HOME/conf/tomcat-users.xml:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<user username="admin" password="your_password" roles="admin"/>
</tomcat-users>


Continuous Integration environment is almost ready.

My pom.xml contains following configuration:

<!-- Deployment config -->
<distributionManagement>
<repository>
<id>artifactory.internal</id>
<name>Internal Release Repository</name>
<url>dav:http://server_name:port/artifactory/libs-releases/</url>
</repository>
<snapshotRepository>
<id>artifactory.snapshots</id>
<name>Internal Snapshot Repository</name>
<url>dav:http://server_name:port/artifactory/libs-snapshots/</url>
</snapshotRepository>
<site>
<id>website</id>
<url>dav:http://server_name:port/projects/project_name-${pom.version}/</url>
</site>
</distributionManagement>


and Maven on the server side contains following configuration (MAVEN_HOME/conf/settings.xml):

<servers>
<server>
<id>artifactory.internal</id>
<username>admin</username>
<password>your_password</password>
</server>
<server>
<id>artifactory.snapshots</id>
<username>admin</username>
<password>your_password</password>
</server>
<server>
<id>website</id>
<username>admin</username>
<password>your_password</password>
</server>
</servers>


Please note that artifactory admin has albo be present in Tomcat's tomcat-users.xml configuration file.
In my configuration for Artifactory, Continuum and Tomcat administrator user name is admin and has the same password in all three cases. More so I configured WebDAV (XML snippet above) in a way that the Tomcat's user admin has to be in role admin - otherwise Continuum will not be able to deploy site using WebDAV protocol.

That's basically it - I hope this post will be useful for some of you.

And why I chose Artifactory? Because I didn't know about the other options :) If you hesitate and don't know what to choose this blog post can help you: Maven Repository Managers - why we chose Archiva.
I am very satisfied about Artifactory - it works out-of-the-box and is serviceless application.

PS. As blogger is not Wiki you are not allowed to change the contents of this post. Nevertheless if you find some bugs or irrelevant information I would be grateful for your comments. I'll then fix this post and correct the mistakes.

5 comments:

wingerz said...

I just set up Sonatype's Nexus (another repo manager), and it is quite easy. Thanks to the slick GUI you don't have to muck around with XML config files.

Przemysław Bielicki said...

I see your point - this is quite frustrating that in order to add somoe repositories to Artifactory config you have to change the XML.

Good thing is that you can at least reload this config file from the GUI without restarting the server :)

Yoav Landman said...

Starting with version 1.3.0-beta-6 (due any day now) Artifactory is fully configurable via the web UI. The XSD-driven XML configuration is still there at the back if you wish to edit it directly with any code-completing tool.

Przemysław Bielicki said...

Cool :)

Anonymous said...

not sure it's necessary to configure tomcat for webdav anymore, there appears to be a maven extension for it.

http://wiki.jfrog.org/confluence/display/RT12/Using+Artifactory#UsingArtifactory-UsingtheWebDAVWagon