使用Chef从Sonatype Nexus部署战争

时间:2014-07-29 18:12:41

标签: java maven chef nexus

我正在使用Chef来部署我的网络应用。目前我正在使用下面部署一个存储在公司服务器的sonatype nexus中的战争。

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

有没有办法获得最新的战争,而不是硬编码厨师食谱中的版本号?我不想将版本号包含为属性,因为每次构建新版本时都需要签入属性文件。我使用如下的shell脚本获得战争并将其复制到我的应用程序文件夹,但希望能够与主厨一起完成。

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

2 个答案:

答案 0 :(得分:4)

您希望使用nexus API构建一个查询,为您提供最新版本的URL:

以下是使用RGAV的示例:

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

这里是获取最新版log4j的URL,例如:

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

然后在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

答案 1 :(得分:0)

也许https://github.com/maoo/artifact-deployer可能有用;它是一个厨师食谱(https://github.com/opscode-cookbooks/maven的包装),允许您将Maven GAV坐标指定为Chef JSON属性:

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

它还支持其他功能,例如解压缩和属性修补。