Giovanni
view release on metacpan or search on metacpan
lib/Giovanni/Stages.pm view on Meta::CPAN
package Giovanni::Stages;
use Mouse;
use Expect;
use Data::Dumper;
# Stages are defined here and expected to be overridden with plugins.
# the idea is to have different plugins that can extend the existing
# stages real easy. If this stages approach turns out to be too limited
# (ie 1000s of stages in one file, not a good look) we may need to
# rethink this approach.
sub update_cache {
my ($self, $ssh) = @_;
$self->log($ssh, "running update_cache task ...");
return;
}
sub rollout {
my ($self, $ssh) = @_;
$self->log($ssh, "running rollout task ...");
$self->config->{deploy_dir} = $self->config->{root};
my $log = $ssh->capture("mkdir -p " . $self->config->{deploy_dir});
$self->log($ssh, $log);
$self->checkout($ssh);
$self->post_rollout($ssh);
return;
}
sub rollout_timestamped {
my ($self, $ssh) = @_;
$self->log($ssh, "running rollout_timestamped task ...");
my $deploy_dir = join('/', $self->config->{root}, 'releases', time);
my $current = join('/', $self->config->{root}, 'current');
my $log = $ssh->capture("mkdir -p " . $deploy_dir);
$self->config->{deploy_dir} = $deploy_dir;
$self->checkout($ssh);
$log .= $ssh->capture(
"unlink " . $current . "; ln -s " . $deploy_dir . " " . $current);
$self->log($ssh, $log);
$self->post_rollout($ssh);
return;
}
sub rollback_timestamped {
my ($self, $ssh, $offset) = @_;
$self->log($ssh, "running rollback task ...");
my $deploy_dir = join('/', $self->config->{root}, 'releases');
my $current = join('/', $self->config->{root}, 'current');
my @rels = $ssh->capture("ls -1 " . $deploy_dir);
@rels = sort(@rels);
my $link = $ssh->capture("ls -l " . $current . " | sed 's/^.*->\\s*//'");
my @path = split(/\//, $link);
my $current_rel = pop(@path);
my (@past, @future);
foreach my $rel (@rels) {
chomp($rel);
next unless $rel =~ m{^\w};
if ($rel == $current_rel) {
push(@future, $rel);
next;
}
if (@future) {
push(@future, $rel);
}
else {
push(@past, $rel);
( run in 1.472 second using v1.01-cache-2.11-cpan-9581c071862 )