Skip to content

Instantly share code, notes, and snippets.

@inverse
Last active January 4, 2016 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inverse/8585975 to your computer and use it in GitHub Desktop.
Save inverse/8585975 to your computer and use it in GitHub Desktop.
Basic CodeIgniter deployment using Mercurial via SSH.
<project name="deploy" default="help" basedir=".">
<!--
Required properties:
Repo to pull from
- repo
Location to deploy too
- deploy.location
Host to deploy to
- host
Username of ssh
- username-
SSH key file
- keyfile=
Key file passphase
- passphase
-->
<loadproperties srcFile="local.properties"/>
<tstamp>
<format property="timestamp" pattern="yyyy-MM-dd_HHmmss"/>
</tstamp>
<!-- New public_html directory -->
<property name="public_html.dir" value="public_html_${timestamp}" />
<!-- Update website -->
<target name="update">
<ssh command="cd ${deploy.location}; hg clone ${repo} ${public_html.dir}; cd ${public_html.dir}; rm -rf .hg .hgignore; sed -i &quot;s/'development');/'production');/&quot; index.php" />
<ssh command="cd ${deploy.location}; old_path=0; if test -d public_html; then old_path=$(readlink -f public_html); fi; ln -s ${public_html.dir} public_html_tmp &amp;&amp; mv -Tf public_html_tmp public_html; rm -rf $$old_path" />
</target>
<!-- Macro for running ssh commands easier -->
<macrodef name="ssh">
<attribute name="command"/>
<sequential>
<sshexec host="${host}" username="${username}" keyfile="${keyfile}" passphrase="${passphase}" trust="true" command="@{command}"/>
</sequential>
</macrodef>
<!-- Display help -->
<target name="help">
<echo message="Use this script to deploy CodeIgniter website to production" />
<echo message=" update - deploy the website to live" />
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment