Application Deployment

If you have to deploy PHP, Rails, Tomcat or Perl Applications this module will help you automate the deployment task.

You can download this module at github.

There are also prebuilded packages. See get page for more information.

See all commands

Installation

You can install this module out of our Repositories. See Get Rex for more information.

Examples

Simple PHP Deployment

If you want to deploy your PHP Project just create a file Rexfile in the top directory of your project. And follow these steps.

Creating a Package

Create a build task. This task will build a tar.gz archive of your application for distribution. You can give this file for example to your system administrators.

If you want to compress your JavaScript and CSS files, just download yuicompressor and place it anywhere in your filessystem. You also need an up-to-date java installation.

use Rex::Apache::Build;

# set the path to yuicompressor.jar
yui_path "./yuicompressor.jar";

# get the application version from the file index.php
# search for a string $VERSION = "foobar"; and extract "foobar".
# for example $VERSION = "1.0";
get_version_from "index.php", qr{\$VERSION = "([^"]+)";};

desc "Build a new package";
task "build", sub {
       
   # compress all *.js files inside public/js
   # and all *.css files inside public/css
   yui compress => glob("public/js/*.js"), glob("public/css/*.css");
       
   # build the package
   build;
};
            

Uploading to the Server

Now, after building the package you need to upload it to your server.

Add the next line to the other use line.

use Rex::Apache::Deploy Symlink;

And specify the user and the key to connect via ssh to your server. Put this above the build task.

user "deploy";
public_key "/home/deploy/.ssh/id_rsa.pub";
private_key "/home/deploy/.ssh/id_rsa";

Group all your servers so that you don't need to write so much. This will put the servers php01, php02, php03 and php04 in the group named php.

group "php" => "php[01..04]";

Now specify the directory for the deployment. (This is a directory outside your DocumentRoot. Because the DocumentRoot will be a symlink to the version of your application that you want to deploy. So it is easy and fast to rollback your deployment.) And specify the DocumentRoot. This will become a symlink.

deploy_to "/var/deploy";
document_root "/var/www/html";

Now create a deployment task. This task will upload packaged application to the servers defined in the php group and extract it into a subdirectory of the deploy_to directory (named after the version of your application) and will point your DocumentRoot to the new uploaded version.

task "deploy", group => "php", sub {
   deploy;
};

Running the tasks

You can now run the tasks with rex taskname. You can list the tasks with rex -T.

bash# rex build deploy

Simple Tomcat deployment

This example will deploy myapp-1.0.war to the servers tomcat01, tomcat02, tomcat03 and tomcat04. It will deploy the application with the help of the Tomcat Manager Application to the context path /myapp.

use Rex::Apache::Deploy Tomcat;

# Version of the application
my $VERSION = "1.0";

user "deploy";
public_key "/home/deploy/.ssh/id_rsa.pub";
private_key "/home/deploy/.ssh/id_rsa";

group "tomcat" => "tomcat[01..04]";

parallelism 4;

context_path "/myapp";

desc "Deploy Application";
task "deploy", group => "tomcat", sub {
   deploy "myapp-$VERSION.war",
      username => "manager-user",
      password => "manager-password",
      port     => 8080;   
};
            

Comments



Use [code]...[/code] for a code block.
 

ewa.tomczyk@uj.edu.pl - 2011-08-23 17:09:02 Comment

I am forever indetbed to you for this information.


Use [code]...[/code] for a code block.
 
Fork me on GitHub