MongoHosting
view release on metacpan or search on metacpan
use utf8;
binmode(STDOUT, ":utf8");
use open qw/:std :utf8/;
use Time::HiRes ();
use Rex -feature => ['1.6', 'disable_strict_host_key_checking'];
use Rex::Config;
use Scalar::Util qw(refaddr);
use Class::Load qw(load_class);
use String::CamelCase qw(camelize);
use DigitalOcean;
use YAML ();
use MongoHosting::ReplicaSet;
use Term::ANSIScreen qw(cls);
use UI::Dialog::Backend::CDialog;
use Mango;
use Mojo::IOLoop;
use Mojo::Promise;
use List::Util qw(all);
$|++;
my $conf = YAML::LoadFile($ENV{DEPLOY_CONFIG} || 'config.yml');
$Rex::Logger::debug = 0;
$Rex::Logger::format = '%D - [%l] - {%h} - %s';
BEGIN {
user 'root';
private_key($ENV{PRIVATE_KEY} || die 'Missing PRIVATE_KEY');
public_key(
(
-r $ENV{PRIVATE_KEY} . '.pub'
? $ENV{PRIVATE_KEY} . '.pub'
: $ENV{PUBLIC_KEY}
)
|| die 'Missing PUBLIC_KEY'
);
key_auth;
}
# my $provider_class_name
# = camelize($conf->{provider} or die 'Missing provider in config');
# my $provider = load_class('MongoHosting::Provider::' . $provider_class_name)->new(
# config => $conf,
# ssh_public_key => Rex::Config::get_public_key,
# api_key => $ENV{PROVIDER_API_KEY} || die 'missing PROVIDER_API_KEY'
# );
sub build_provider {
my $conf = shift;
my $provider_class_name
= camelize($conf->{provider} or die 'Missing provider in config');
my $provider
= load_class('MongoHosting::Provider::' . $provider_class_name)->new(
config => $conf,
ssh_public_key => Rex::Config::get_public_key,
api_key => $ENV{PROVIDER_API_KEY} || die 'missing PROVIDER_API_KEY'
);
return $provider;
}
task deploy => sub {
my @replica_sets = deploy_helper($conf);
};
sub deploy_helper {
my ($conf) = @_;
my $provider = build_provider($conf);
my @replica_sets = ();
foreach my $replica (@{$conf->{replicas}}) {
push @replica_sets,
MongoHosting::ReplicaSet->new(
name => $replica->{name},
type => $replica->{type},
members => [
map { +{%$_, box => $provider->get_box($_->{host})} }
@{$replica->{members}}
]
);
}
my @all = map { @{$_->members} } @replica_sets;
foreach my $member (@all) {
$member->setup_firewall(
( run in 1.868 second using v1.01-cache-2.11-cpan-39bf76dae61 )