Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <property file="${user.home}/build.properties" />
  2. <fail unless="play.path" message="Property play.path not set in build.properties file"/>
  3. <fail unless="project.version" message="Property project.version not set"/>
  4. <fail unless="project.path" message="Property project.path not set in build.properties file"/>
  5.  
  6. <property name="play.cache.repository" value="${play.path}/repository/cache/my.group.com" />
  7. <property name="play.stage.dir" value="/target/staged" />
  8.  
  9. <tstamp/>
  10. <property name="project.version.timestamp" value="${project.version}-${DSTAMP}${TSTAMP}"/>
  11.  
  12. <!-- On deploy we don't need to send all the files in the stage folder, but only the ones specific to our project -->
  13. <patternset id="project.files.pattern">
  14.     <include name="**/foo-*.jar"/>
  15.     <include name="**/bar-*.jar"/>
  16.     <include name="**/api-*.jar"/>
  17.     <include name="**/joda-time*.jar"/>
  18. </patternset>
  19.  
  20. <!-- This is what we'll call from Jenkins -->
  21. <target name="jenkins-play-build" description="Specific target for jenkins">
  22.    <antcall target="play-stage"/>
  23.    <antcall target="deploy"/>
  24. </target>
  25.  
  26. <target name="play-stage" description="Does a full build and stage of our Play apps">
  27.     <!-- We have some maven projects which we want to update by deleting this folder-->
  28.     <delete dir="${play.cache.repository}"/>
  29.     <exec executable="${play.path}/play" dir="${my.repository.path}/foo">
  30.       <arg value="clean"/>
  31.       <arg value="compile"/>
  32.       <arg value="stage"/>
  33.     </exec>
  34.     <exec executable="${play.path}/play" dir="${my.repository.path}/bar">
  35.       <arg value="clean"/>
  36.       <arg value="compile"/>
  37.       <arg value="stage"/>
  38.     </exec>
  39.     <exec executable="${play.path}/play" dir="${my.repository.path}/api">
  40.       <arg value="clean"/>
  41.       <arg value="compile"/>
  42.       <arg value="stage"/>
  43.     </exec>
  44. </target>
  45.  
  46. <target name="play-deploy" description="Deploys the given project">
  47.     <fail unless="project.version.timestamp" message="Property version.timestamp needed to continue"/>
  48.     <fail unless="deploy.server" message="Property needed to continue"/>
  49.     <fail unless="webapp" message="Property webapp needed to continue"/>
  50.     <property name="scp.path" value="${remote.user}@${remote.server}:${remote.dir}/webapps/${webapp}" />
  51.     <sshexec
  52.      host="${remote.server}"
  53.      username="${remote.user}"
  54.      keyfile="${user.home}/.ssh/id_rsa" trust="true"
  55.      command="mkdir ${remote.dir}/webapps/${webapp}/${project.version.timestamp}" failonerror="false"/>
  56.     <scp toDir="${scp.path}/${project.version.timestamp}" keyfile="${user.home}/.ssh/id_rsa" trust="true">
  57.       <fileset dir="${project.path}/${webapp}/${play.stage.dir}" casesensitive="yes">
  58.         <patternset refid="project.files.pattern"/>
  59.       </fileset>
  60.     </scp>
  61. </target>
  62.  
  63. <!-- Deploy each of the projects separately. Repeat for each project. -->
  64. <target name="play-deploy-foo" depends="check-play-foo-staged" if="project.foo.staged">
  65.    <antcall target="play-deploy">
  66.     <param name="webapp" value="foo"/>
  67.    </antcall>
  68. </target>
  69. <target name="check-play-foo-staged">
  70.       <echo message="Check path ${project.path}/foo$/{play.stage.dir} exists"/>
  71.       <available file="${project.path}/foo/${play.stage.dir}" type="dir" property="project.foo.staged"/>
  72. </target>
  73.  
  74. <!-- This is the target which binds everything together for the deploy -->
  75. <target name="deploy" description="Deploy all applications">
  76.    <antcall target="play-deploy-foo"/>
  77.    <antcall target="play-deploy-api"/>
  78.    <antcall target="play-deploy-bar"/>
  79.    <sshexec
  80.    host="${remote.server}"
  81.    username="${remote.user}"
  82.    keyfile="${user.home}/.ssh/id_rsa" trust="true"
  83.    command="/home/play/bin/deploy ${project.version.timestamp}"/>
  84. </target>