NAME

Rex::Apache::Inject - Configuration Injection module for Rex::Apache::Deploy

DESCRIPTION

This is a (R)?ex module to inject configuration parameters into packages (*.tar.gz, *.tar.bz2, *.zip or *.war).

You can find examples and howtos on http://rexify.org/

GETTING HELP

DEPENDENCIES

SYNOPSIS

use Rex::Apache::Inject Properties;

template_file "inject.conf";
template_search_for "*.properties";

desc "Inject LIVE Configuration";
task "inject", sub {
  inject "mypkg-1.0.1.tar.gz";
};

desc "Inject LIVE Configuration";
task "inject", sub {
  inject "mypkg-1.0.1.tar.gz",
       pre_pack_hook => sub {
           say "Pre Pack Hook";
       },
       post_pack_hook => {
           say "Post Pack Hook";
       };
};

INJECT METHODS

Properties

This method is for Java-Like Property files.

use Rex::Apache::Inject Properties;

template_file "inject.conf";
template_search_for "*.properties";

task "inject", sub {
   inject "myapp.war";
};

This will search all files named *.properties inside of myapp.war and replace the parameters with these defined in template_file.

Format of the template_file is the same as the property files.

my.property.one = Value1
my.property.two = Value no two
Template

This is a special method. It will search for template files within the archive and will generate new ones with the parameters defined in template_file.

use Rex::Apache::Inject Template;

template_file "inject.conf";
template_search_for "*.template.*";

generate_real_name sub {
  my ($template_file_name) = @_;
  $template_file_name =~ s/\.template//;
  return $template_file_name;
};

task "inject", sub {
   inject "myapp.tar.gz";
};

This will search for files named *.template.* inside of myapp.tar.gz. And will generate new files on the basis of generate_real_name.

Example:

# Template Configuration file (inside myapp.tar.gz): config.template.php
<?php
  $db['host'] = "@db.host@";
  $db['port'] = @db.port@;
  $db['user'] = "@db.user@";
  $db['pass'] = "@db.pass@";
?>

# Template file (specified by ,,template_file'')
db.host = "db01"
db.port = 3306
db.user = "myuser"
db.pass = "mypass"

The inject action will generate a file called config.php with the following content:

<?php
  $db['host'] = "db01";
  $db['port'] = 3306;
  $db['user'] = "myuser";
  $db['pass'] = "mypass";
?>
YAML

This method will parse YAML files inside the archive. For this method you need to have the YAML Module installed.

template_file "live_config.yml";
template_search_for "application.yml";

task "inject", sub {
   inject "myapp.tar.gz",
     pre_pack_hook => sub {
        run "BUNDLE_PATH=vendor/bundle bundle install";
     };
};

This will search the file application.yml inside of myapp.tar.gz and replace the configuration values inside of it with these defined in live_config.yml. Also it do a pre pack hook that will run bundle install.