Question

I'm using Chef to deploy my web app. Currently I'm deploying a war stored in sonatype nexus of company server using below.

remote_file "#{base_dir}/webapps/prodservice.war" do
  source "http://company.com:8081/nexus/content/repositories/group/com/company/team/team_product_service/1.0.816/team_product_service-1.0.816.war"
  owner "onamer"
  group "gname"
  notifies :restart, "service[#{service_name}]"
end

Is there a way to get the latest war instead of hardcoding the version number in chef recipe ? I don't want to include version number as attribute also as it requires checking-in the attributes file everytime a new version is built. I get the war using a shell script as below and copy it to my apps folder but want to be able to do it with chef.

mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get \
        --settings maven-settings.xml \
        -DrepoUrl=http://company.com:8081/nexus/content/repositories/group-snaps \
        -Dartifact=company.team:$project:1.0-SNAPSHOT:war \
        -Ddest=$tmpfile
    cp $tmpfile $tomcat/webapps/$context.war
Was it helpful?

Solution

You want to use the nexus API to construct a query that gives you the URL to the latest version:

Here's an example using RGAV:

http://company.com:8081/service/local/artifact/maven/redirect?r=REPOg=NAME&a=NAME&v=LATEST

Here's a URL for getting the latest version of log4j for example:

http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=log4j&a=log4j&v=LATEST

And then use this URL in your remote_file:

remote_file "#{base_dir}/webapps/prodservice.war" do
  source "http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=log4j&a=log4j&v=LATEST"
  owner "onamer"
  group "gname"
  notifies :restart, "service[#{service_name}]"
end

OTHER TIPS

Maybe https://github.com/maoo/artifact-deployer could be useful; it's a Chef cookbook (wrapper of https://github.com/opscode-cookbooks/maven) that allows you to specify Maven GAV coordinates as Chef JSON attributes:

"artifacts": {
    "alfresco": {
        "enabled": true,
        "groupId": "org.alfresco",
        "artifactId": "alfresco",
        "type": "war",
        "version": "5.0.a",
        "destination": "/var/lib/tomcat7/webapps",
        "owner": "tomcat7"
    }
}

It also supports additional features, such as unzipping and property patching.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top