| 1 | # | ||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||
| 3 | # | ||||||||||
| 4 | # vim: set ts=2 sw=2 tw=0: | ||||||||||
| 5 | # vim: set expandtab: | ||||||||||
| 6 | |||||||||||
| 7 | =head1 NAME | ||||||||||
| 8 | |||||||||||
| 9 | Rex::Apache::Deploy - Deploy module for Rex | ||||||||||
| 10 | |||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||
| 12 | |||||||||||
| 13 | This is a (R)?ex module to ease the deployments of Tomcat, Perl, Rails, PHP or other languages. | ||||||||||
| 14 | |||||||||||
| 15 | You can find examples and howtos on L<http://rexify.org/> | ||||||||||
| 16 | |||||||||||
| 17 | =head1 GETTING HELP | ||||||||||
| 18 | |||||||||||
| 19 | =over 4 | ||||||||||
| 20 | |||||||||||
| 21 | =item * Web Site: L<http://rexify.org/> | ||||||||||
| 22 | |||||||||||
| 23 | =item * IRC: irc.freenode.net #rex | ||||||||||
| 24 | |||||||||||
| 25 | =back | ||||||||||
| 26 | |||||||||||
| 27 | =head1 DEPENDENCIES | ||||||||||
| 28 | |||||||||||
| 29 | =over 4 | ||||||||||
| 30 | |||||||||||
| 31 | =item * | ||||||||||
| 32 | |||||||||||
| 33 | L<Rex> | ||||||||||
| 34 | |||||||||||
| 35 | =item * | ||||||||||
| 36 | |||||||||||
| 37 | L<YAML> | ||||||||||
| 38 | |||||||||||
| 39 | =item * | ||||||||||
| 40 | |||||||||||
| 41 | L<LWP::Simple> | ||||||||||
| 42 | |||||||||||
| 43 | =item * | ||||||||||
| 44 | |||||||||||
| 45 | zip | ||||||||||
| 46 | |||||||||||
| 47 | =item * | ||||||||||
| 48 | |||||||||||
| 49 | unzip | ||||||||||
| 50 | |||||||||||
| 51 | =item * | ||||||||||
| 52 | |||||||||||
| 53 | tar | ||||||||||
| 54 | |||||||||||
| 55 | =item * | ||||||||||
| 56 | |||||||||||
| 57 | bzip2 | ||||||||||
| 58 | |||||||||||
| 59 | =item * | ||||||||||
| 60 | |||||||||||
| 61 | wget | ||||||||||
| 62 | |||||||||||
| 63 | =back | ||||||||||
| 64 | |||||||||||
| 65 | If you're using windows, you can install them from here: http://sourceforge.net/projects/gnuwin32/files/ | ||||||||||
| 66 | Don't forget to add the bin directory of the installation to your %PATH% environment variable. | ||||||||||
| 67 | |||||||||||
| 68 | =head1 SYNOPSIS | ||||||||||
| 69 | |||||||||||
| 70 | use Rex::Apache::Deploy Symlink; | ||||||||||
| 71 | |||||||||||
| 72 | deploy_to "/var/deploy"; | ||||||||||
| 73 | |||||||||||
| 74 | document_root "/var/www/myhost/htdocs"; | ||||||||||
| 75 | |||||||||||
| 76 | generate_deploy_directory sub { | ||||||||||
| 77 | my ($file) = @_; | ||||||||||
| 78 | $file =~ m/-(\d+\.\d+\.\d+)\.tar\.gz$/; | ||||||||||
| 79 | return $1; | ||||||||||
| 80 | }; | ||||||||||
| 81 | |||||||||||
| 82 | desc "Deploy to Apache"; | ||||||||||
| 83 | task "deploy", group => "frontend", sub { | ||||||||||
| 84 | deploy "mypkg-1.0.1.tar.gz"; | ||||||||||
| 85 | }; | ||||||||||
| 86 | |||||||||||
| 87 | |||||||||||
| 88 | =head1 DEPLOY METHODS | ||||||||||
| 89 | |||||||||||
| 90 | =over 4 | ||||||||||
| 91 | |||||||||||
| 92 | =item Symlink | ||||||||||
| 93 | |||||||||||
| 94 | This method will upload your package (*.tar.gz, *.tar.bz2 or *.zip) all you servers and extract it in the directory you specified with I<deploy_to> concatenated with the result of I<generate_deploy_directory>. After that it will create a symlink from I<document_root> to this new directory. | ||||||||||
| 95 | |||||||||||
| 96 | deploy_to "/var/deploy"; | ||||||||||
| 97 | document_root "/var/www"; | ||||||||||
| 98 | generate_deploy_directory sub { return "1.0"; }; | ||||||||||
| 99 | |||||||||||
| 100 | This will upload the file to I</var/deploy/1.0> and create a symlink from I</var/www> to I</var/deploy/1.0>. | ||||||||||
| 101 | |||||||||||
| 102 | =item Tomcat | ||||||||||
| 103 | |||||||||||
| 104 | This method is for Tomcat deployments. You need to have the Tomcat Manage application running on your Tomcat servers. It will upload your package to I</tmp/some-random-chars.war>, call the Tomcat Manager to undeploy the current context and deploy the new war archive. After that it will delete the uploaded temporary war file. | ||||||||||
| 105 | |||||||||||
| 106 | context_path "/myapp"; | ||||||||||
| 107 | |||||||||||
| 108 | task "deploy", group => "middleware", sub { | ||||||||||
| 109 | deploy "myapp.war", | ||||||||||
| 110 | username => "manager-user", | ||||||||||
| 111 | password => "manager-password", | ||||||||||
| 112 | port => 8080, | ||||||||||
| 113 | manager_url => "/manager"; | ||||||||||
| 114 | }; | ||||||||||
| 115 | |||||||||||
| 116 | This will deploy I<myapp.war> to the tomcat listening on port I<8080> with the manager application found under I<http://the-server:8080/manager>. | ||||||||||
| 117 | |||||||||||
| 118 | =back | ||||||||||
| 119 | |||||||||||
| 120 | =head2 SWITCHING INSTANCES | ||||||||||
| 121 | |||||||||||
| 122 | If you have multiple Tomcat Instances you can manage them with the I<jk> command. | ||||||||||
| 123 | |||||||||||
| 124 | jk disable => 'name'; | ||||||||||
| 125 | jk enable => 'name'; | ||||||||||
| 126 | |||||||||||
| 127 | |||||||||||
| 128 | =cut | ||||||||||
| 129 | |||||||||||
| 130 | package Rex::Apache::Deploy; | ||||||||||
| 131 | |||||||||||
| 132 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 133 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 134 | |||||||||||
| 135 | 1 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 136 | 1 | ▶ | use Rex::Commands::Run; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 137 | 1 | ▶ | use Rex::Logger; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 138 | |||||||||||
| 139 | 1 | ▶ | use Cwd qw(getcwd); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 140 | |||||||||||
| 141 | 1 | our $VERSION = '0.12.0'; | |||||||||
| 142 | |||||||||||
| 143 | ###### commonly used | ||||||||||
| 144 | 1 | our @COMMONS = (); | |||||||||
| 145 | |||||||||||
| 146 | 1 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=5 SCAR=19.8
| |||||||||||
| 147 | |||||||||||
| 148 | 1 | my ($call_class) = caller; | |||||||||
| 149 | 1 | ▶ | return unless $call_class; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 150 | |||||||||||
| 151 | 1 | ▶ | return unless $_[1]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 152 | |||||||||||
| 153 | 0 | ▶ | die("Invalid input format") unless ( $_[1] =~ m/^[a-z0-9_]+$/i ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 154 | |||||||||||
| 155 | 1 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 156 | 0 | for my $exp (@COMMONS) { | |||||||||
| 157 | 0 | *{"${call_class}::$exp"} = \&$exp; | |||||||||
| 158 | } | ||||||||||
| 159 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 160 | |||||||||||
| 161 | 0 | eval "use $_[0]::$_[1] '$call_class';"; | |||||||||
| 162 | |||||||||||
| 163 | } | ||||||||||
| 164 | |||||||||||
| 165 | 1 | 1; | |||||||||