Aug 26, 2010

Automatic deployment part 5

Here is the current version of the build script:

<?xml version="1.0" encoding="UTF-8"?>
<project name="my_project" default="deploy">
<property name="config.file" value="builder/build.properties.${dest}" />
<property name="dist.dir" value="${ant.project.name}-r${svn_revision}-b${build_number}" />
<property name="build.dir" value="${workspace}/${dist.dir}" />

<record name="${build.dir}.log" />

<target name="init">
<available file="${config.file}" property="config.exists"/>
<fail message="Config file '${config.file}' not found." unless="config.exists" />
<echo>Config file '${config.file}' exists.</echo>
<property file="${config.file}" />

<available file="${workspace}" property="workspace.exists"/>
<fail message="Workspace '${workspace}' not found." unless="workspace.exists" />
<echo>Workspace '${workspace}' exists.</echo>
<delete dir="${build.dir}" />
<mkdir dir="${build.dir}" />
</target>

<target name="prepare" depends="init">
<copy todir="${build.dir}">
<fileset dir=".">
<exclude name="**/.*" />
<exclude name="build*" />
<exclude name="bkp/" />
<exclude name="builder/" />
<exclude name="cache/" />
<exclude name="scripts/" />
<exclude name="sources/" />
</fileset>
</copy>
<copy file="builder/.htaccess.${dest}" tofile="${build.dir}/.htaccess" verbose="true" />
</target>

<target name="transfer" depends="prepare">
<scp todir="${dest_user}@${dest_host}:${dest_path}/" password="${dest_passwd}" trust="true">
<fileset dir="${workspace}">
<include name="${dist.dir}/"/>
</fileset>
</scp>
</target>

<target name="remote-deploy" depends="transfer">
<sshexec
host="${dest_host}"
username="${dest_user}"
password="${dest_passwd}"
command="
cd ${dest_path};
rm current;
ln -s ${dist.dir} current;"
/>
</target>

<target name="deploy" depends="remote-deploy">
</target>
<project>


The script needs to be invoked like this:
ant -Dworkspace=/tmp -Ddest=dev -Dsvn_revision=123 -Dbuild_number=123

No comments: