Deploy Interceptor

Introduction

This interceptor reads and stores a_deploy.tag file to check for new deployments to a server or server cluster. If the tag has been udpated, the interceptor tells the application (ColdBox) to reinitialize itself. So basically, you don't have to worry about restarting applications or cleaning stuff out or removing files. Just worry about getting another cup of coffee.

How it works?

Once the application starts up, it reads the date/time stamp on the tag file and saves it on memory as a setting. This deploy interceptor will save you countless pains and mishaps when deploying new builds to a production server or cluster of servers. As each server receives a new request, the deploy tag is compared, if changes are detected, the framework re-initializes the entire application on that specific server and then processing continues with all the new code initialized. What else do you do? Well, maybe get more sleep when doing deploys.

Making Life Easy: ANT

You can use the included ANT script to touch the file with a new timestamp when doing new deploys to your production server or server cluster. Then just make sure you include the file in your deploy.

<?xml version="1.0"?>
<!-- ====================================================================== 
    ********************************************************************************
    Copyright 2005-2008 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
    www.coldboxframework.com | www.luismajano.com | www.ortussolutions.com
    ********************************************************************************
    Deploy tag stamper
    by Luis Majano                                                                                 
    ====================================================================== -->
<project name="deploytag" default="do.deploytag" basedir=".">
    
    <description>
        Creates a new deploy tag timestamp
    </description>
    
    <property name="deploytag.path" value="_deploy.tag" />
    
    <target name="init">
        <!-- Init TimeStamp -->
        <tstamp>
            <format pattern="MMM-dd-yyyy HH:mm:ss" property="TODAY"/>
        </tstamp>
        <available file="${deploytag.path}"   property="isFileAvail" />
    </target>
    
    <target name="do.delete.tag" if="isFileAvail">
        <delete file="${deploytag.path}"  />
    </target>
    
    <target name="do.deploytag" depends="init, do.delete.tag">
        <!-- echo tag -->
        <echo file="${deploytag.path}">DEPLOYING ON:${TODAY}</echo>
    </target>
    
</project>

How to set it up?

  • Place the _deploy.tag and deploy.xml ANT task in your /config directory of your application.
  • Add the Deploy interceptor declaration:
<Interceptor class="coldbox.system.interceptors.deploy">
        <Property name="tagFile">config/_deploy.tag</Property>
        <Property name="deployCommandObject">model.deployCommand</Property>
</Interceptor>

Interceptor Properties

  • tagFile : config/_deploy.tag [required] The location of the tag file.
  • deployCommandObject : The class path of the deploy command object to use [optional].

Deploy Command Object

This object is a cfc that must implement an init(controller) method and an execute() method. This command object will be executed before the framework reinit bit is set so you can do any kind of cleanup code or anything you like before the application is re-initialized. Below is a simple example:

<cfcomponent name="DeployCommand" output="false">
        <cffunction name="init" access="public" returntype="any" hint="Constructor" output="false" >
                <cfargument name="controller" required="true" type="coldbox.system.controller" hint="The coldbox controller">
                <cfset instance = structnew()>
                <cfset instance.controller = arguments.controller>
        </cffunction>
        
        <cffunction name="execute" access="public" returntype="void" hint="Execute Command" output="false" >
                <!--- Do your cleanup code or whatever you want here. --->
                <cfset getPlugin("logger").logEntry("information","New deploy detected, performing cleanup...")>
        </cffunction>
</cfcomponent>

Overview

Maintaining deploys in a production environment of one or more servers can be a drag. You don't want to re-initialize the servers or reboot them if necessary. With this nifty interceptor, all you do is deploy with a tag file and the interceptor does the rest. Now you can have more time to play Warcraft (Shhh don't tell the boss)