| 1 | package CloudDeploy::CommandLine::Update { | ||
| 2 | use MooseX::App; | ||
| 3 | use CloudDeploy::Utils; | ||
| 4 | use CloudDeploy::DeploymentCollection; | ||
| 5 | use Moose::Util::TypeConstraints qw/enum/; | ||
| 6 | |||
| 7 | parameter deployment => (is => 'ro', isa => 'Str', required => 1); | ||
| 8 | |||
| 9 | option comments => (is => 'ro', isa => 'Str|Undef', documentation => "Comments to include with deployment"); | ||
| 10 | |||
| 11 | option class => ( | ||
| 12 | is => 'ro', | ||
| 13 | isa => 'Str', | ||
| 14 | documentation => 'Override the class that is read from the database. Use with care: the new class should be able to accept the same parameters as the old class' | ||
| 15 | ); | ||
| 16 | |||
| 17 | option mode => ( | ||
| 18 | is => 'ro', | ||
| 19 | isa=> enum([ qw/cfn deployment_engine/ ]), | ||
| 20 | documentation => "Whether to activate the new deployment engine or not. Needed for all non CloudFormation related deployments. One of: cfn, deployment_engine", | ||
| 21 | default=>'cfn' | ||
| 22 | ); | ||
| 23 | |||
| 24 | option no_version_control => ( | ||
| 25 | is => 'ro', | ||
| 26 | isa => 'Bool', | ||
| 27 | documentation => "DANGEROUS!!! Disables stack version control. This will bypass all attempts of clouddeploy detecting other people's updates while you are working", | ||
| 28 | default => 0, | ||
| 29 | ); | ||
| 30 | |||
| 31 | sub run { | ||
| 32 | my ($self) = @_; | ||
| 33 | |||
| 34 | if( $self->mode eq 'cfn' ) { | ||
| 35 | my $deployments = CloudDeploy::DeploymentCollection->new(account => $ENV{'CPSD_AWS_ACCOUNT'}); | ||
| 36 | my $deploy = $deployments->get_deployment($self->deployment); | ||
| 37 | |||
| 38 | my $class = (defined $self->class) ? $self->class : $deploy->type; | ||
| 39 | |||
| 40 | my $module = load_class($class); | ||
| 41 | |||
| 42 | my @attached = | ||
| 43 | map { $_->name } | ||
| 44 | grep { $_->does('Attached') } | ||
| 45 | $module->{params_class}->meta->get_all_attributes; | ||
| 46 | |||
| 47 | my $params = $deploy->params; | ||
| 48 | delete $params->{ $_ } for (@attached); | ||
| 49 | |||
| 50 | my $merged_params = $module->{params_class}->new_with_options(%{ $params }, update => 1, argv => $self->extra_argv); | ||
| 51 | |||
| 52 | my $obj = $module->{class}->new(params => $merged_params); | ||
| 53 | |||
| 54 | my $deployer = $obj->get_deployer({ | ||
| 55 | access_key => $ENV{AWS_ACCESS_KEY_ID}, | ||
| 56 | secret_key => $ENV{AWS_SECRET_ACCESS_KEY}, | ||
| 57 | account => $ENV{CPSD_AWS_ACCOUNT}, | ||
| 58 | comments => $self->comments, | ||
| 59 | },'CCfnX::CloudFormationDeployer', 'CCfnX::PersistentDeployment'); | ||
| 60 | |||
| 61 | if ($self->no_version_control) { | ||
| 62 | $deployer->reset_stack_version; | ||
| 63 | } | ||
| 64 | else { | ||
| 65 | # Will not let execution continue if version control doesn't find this | ||
| 66 | # update to be safe | ||
| 67 | $deployer->assert_stack_version_ok; | ||
| 68 | } | ||
| 69 | |||
| 70 | $deployer->redeploy; | ||
| 71 | |||
| 72 | } elsif ($self->mode eq 'deployment_engine') { | ||
| 73 | |||
| 74 | my $module = load_class($self->deployment); | ||
| 75 | my $obj = $module->{class}->new(params => $module->{params_class}->new_with_options(argv => $self->extra_argv)); | ||
| 76 | |||
| 77 | my $deployer = $obj->get_deployer({ | ||
| 78 | account => $ENV{CPSD_AWS_ACCOUNT}, | ||
| 79 | comments => $self->comments, | ||
| 80 | },'CCfnX::DeploymentEngine'); | ||
| 81 | |||
| 82 | $deployer->redeploy; | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | } | ||
| 87 | |||
| 88 | 1; |