Showing posts with label deployment. Show all posts
Showing posts with label deployment. Show all posts

Friday, July 20, 2007

Use Ant to deploy to remote hosts

Ant is an awesome compile/package/deployment tool for Java code. But it's not limited to Java programs only. Currently, I'm working on a PHP site. We actually use ant to deploy our app. I don't really want to list the details here, but I can explain the basic steps.
1. Staging
During this step, you use ant filter feature to customize all the configuration and resources. For example, you might have different database for different environment. Developer's web server talks to Dev database, QA's web server talks to QA database, and prod's web server talks to Prod database. You use ant copy and filter feature to stage all the file from source location to a target location.
2. Packaging
Simple use ant tar and zip feature to package everything into a compressed file. You might want to add times stamp or version number to the tar file so you know which version you are deploying.
3. Deployment
To transfer the application package to a remote host, you should use ant scp task. Since we have multiple web servers, we also use ant for task which tokenize a list of host names and create a for loop so the embedded scp task will copy files to each remote host. On the remote hosts, you should have a directory for holding all the app packages. You can use sshexec to remotely create any directories.
4. Installation
You can easy write a shell script and deploy the shell script along with the application package or use ant sshexec to unpackage the application. However, I highly recommend the use of a separated shell script. Becuase you won't have to relay on ant to install your software which means you can install/rollback/rollforward your production server from anywhere.

Sunday, May 13, 2007

Hello PHP (and Ant)

I started the new job a week ago. The new gig requires me writing code in PHP. As a scripting language, PHP is very easy to use. It has great support for database connection, rich library and recently added AJAX features. But being a scripting language, it is also very easy to make a mess in your code base or development cycle. I noticed some developers check out source code and directly point their web server at their source code directory. I guess it make sense if the developer wants to see results quickly when he modifies source code. But I am always afraid of sharing the same files for development and deployment. If the application generates files at run time and the generated files might be accidentally checked into repository since they are in the development file directory. One mistake I have made myself in the past is to modify a code in the application directory and forgot to check it in. Also, in situation where it's impossible to run the entire application on a local host, it's just not possible to check out source code to a remote deployment box. I decided to take the responsibility of separating development environment and deployment environment. Since I love Java so much, I use Ant to filter and copy PHP scripts from source directory to staging directory, and use a shell script to move staged scripts to the correct deployment directory. This works out well.