FargateStack.pm

filter: Statementstmt 12.8% 100 / 776 Branchbran 0.4% 1 / 242 Conditioncond 0.0% 0 / 150 MC/DCmcdc 0.0% 0 / 91 Subroutinesub 28.9% 24 / 83 Podpod 4.2% 2 / 47 totaltotal 9.1% 127 / 1389 CC 185 SCAR 51.1
CC
185
Cov
9%
cmd_run_task
812.0
help
462.0
show_config
182.0
CRAP 165.3
« FargateStack/Builder/Autoscaling.pm ↑ Summary FargateStack/Builder/TaskDefinition.pm »
1 package App::FargateStack;
2  
3 ########################################################################
4 # Copyright (C) 2025, TBC Development Group, LLC All rights reserved. #
5 # This is free software and may be modified or redistributed under the #
6 # same terms as Perl itself. #
7 # #
8 # Repository: https://github.com/rlauer6/App-Fargate #
9 ########################################################################
10  
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use App::FargateStack::Builder::Utils qw(jmespath_mapping toCamelCase dmp choose confirm);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use App::FargateStack::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use App::FargateStack::Pod;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use CLI::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use CLI::Simple::Constants qw(:booleans :chars %LOG_LEVELS);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Cwd qw(realpath);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Date::Parse qw(str2time);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use English qw(no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use File::Basename qw(basename fileparse);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use List::Util qw(none any);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use Scalar::Util qw(reftype looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use Text::ASCIITable::EasyTable;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use Term::ANSIColor;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use YAML qw(LoadFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 1 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 # command methods
36 1 with 'App::FargateStack::Init';
37 1 with 'App::FargateStack::Logs';
38 1 with 'App::FargateStack::Route53';
39 1 with 'App::FargateStack::CloudTrail';
40 1 with 'App::FargateStack::CreateStack';
41 1 with 'App::FargateStack::Autoscaling';
42  
43 1 with 'App::BenchmarkRole';
44  
45 # builder methods
46 1 with 'App::FargateStack::Builder';
47 1 with 'App::FargateStack::Builder::Autoscaling';
48 1 with 'App::FargateStack::Builder::IAM';
49 1 with 'App::FargateStack::Builder::Certificate';
50 1 with 'App::FargateStack::Builder::Events';
51 1 with 'App::FargateStack::Builder::EFS';
52 1 with 'App::FargateStack::Builder::HTTPService';
53 1 with 'App::FargateStack::Builder::Cluster';
54 1 with 'App::FargateStack::Builder::LogGroup';
55 1 with 'App::FargateStack::Builder::SecurityGroup';
56 1 with 'App::FargateStack::Builder::Secrets';
57 1 with 'App::FargateStack::Builder::Service';
58 1 with 'App::FargateStack::Builder::S3Bucket';
59 1 with 'App::FargateStack::Builder::SQSQueue';
60 1 with 'App::FargateStack::Builder::TaskDefinition';
61 1 with 'App::FargateStack::Builder::Utils';
62 1 with 'App::FargateStack::Builder::WafV2';
63  
64 1 our $VERSION = '1.0.50';
65  
66 1 ▶use parent qw(CLI::Simple);
Subroutine BEGIN: called CC=1 SCAR=0.0
67  
68 1 __PACKAGE__->use_log4perl( config => $LOG4PERL_CONF );
69  
70 1 ▶caller or __PACKAGE__->main;
Branch: 1 branch
BranchTrueFalseTotal
caller or __PACKAGE__->main 1 0 1
71  
72 ########################################################################
73 0 ▶sub init_logger {
Subroutine init_logger: not called CC=4 SCAR=30.0
Pod undocumented
74 ########################################################################
75 0 my ($self) = @_;
76  
77 0 my $log4perl_conf = $self->get_log4perl_conf;
78  
79 0 ▶ if ( !$self->get_color ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->get_color) 0 0 0
80 0 $log4perl_conf =~ s/ColoredLevels//xsm;
81  
82 0 ▶ if ( $self->get_log_level && $self->get_log_level =~ /debug|trace/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_log_level and $self->get_log_level =~ /debug|trace/msx) 0 0 0
Condition0%0/3
$self->get_log_level and $self->get_log_level =~ /debug|trace/msx
!ll&&!rl&&r
000
MC/DC0%0/2
$self->get_log_level and $self->get_log_level =~ /debug|trace/msx
$self->get_log_level $self->get_log_level =~ /debug|trace/msx
Truth table0%0/3
A and B
A= $self->get_log_levelB= $self->get_log_level =~ /debug|trace/msx
ABresult
0X0
100
111
83 0 $log4perl_conf =~ s/ConversionPattern(.*?)$/ConversionPattern = [%d] (%M:%L) %m%n/xsm;
84 }
85 }
86  
87 0 $self->set_log4perl_conf($log4perl_conf);
88  
89 0 return $self->SUPER::init_logger;
90 }
91  
92 ########################################################################
93 0 ▶sub show_config {
Subroutine show_config: not called CC=13 SCAR=52.0
Pod undocumented
94 ########################################################################
95 0 my ($self) = @_;
96  
97 0 my $config = $self->get_config;
98  
99 0 my $subnets = $self->get_subnets;
100  
101 0 ▶ my $dryrun = $self->command eq 'plan' ? '(dryrun)' : $self->get_dryrun;
Branch: 1 branch
BranchTrueFalseTotal
$self->command eq 'plan' ? : 0 0 0
102  
103 0 $self->section_break;
104  
105 0 $self->log_info( ' account: [%s]', $self->get_account );
106 0 $self->log_info( ' profile: [%s]', $self->get_profile );
107 0 $self->log_info( ' profile source: [%s]', $self->get_profile_source );
108 0 $self->log_info( ' region: [%s]', $self->get_region );
109 0 $self->section_break;
110  
111 0 ▶ $self->log_info( ' route53 profile: [%s]', $config->{route53}->{profile} // q{-} );
Condition0%0/2
$config->{"route53"}{"profile"} // "-"
l!l
00
MC/DC0%0/1
$config->{"route53"}{"profile"} // "-"
$config->{"route53"}{"profile"}
Truth table0%0/2
A
A= $config->{"route53"}{"profile"}
Aresult
11
00
112 0 ▶ $self->log_info( ' route53 zone_id: [%s]', $config->{route53}->{zone_id} // q{-} );
Condition0%0/2
$config->{"route53"}{"zone_id"} // "-"
l!l
00
MC/DC0%0/1
$config->{"route53"}{"zone_id"} // "-"
$config->{"route53"}{"zone_id"}
Truth table0%0/2
A
A= $config->{"route53"}{"zone_id"}
Aresult
11
00
113 0 $self->section_break;
114  
115 0 $self->log_info( ' app name: [%s]', $config->{app}->{name} );
116 0 ▶ $self->log_info( ' app version: [%s]', $config->{app}->{version} // q{-} );
Condition0%0/2
$config->{"app"}{"version"} // "-"
l!l
00
MC/DC0%0/1
$config->{"app"}{"version"} // "-"
$config->{"app"}{"version"}
Truth table0%0/2
A
A= $config->{"app"}{"version"}
Aresult
11
00
117 0 ▶ $self->log_info( ' https service: [%s]', $self->get_http // q{-} );
Condition0%0/2
$self->get_http // "-"
l!l
00
MC/DC0%0/1
$self->get_http // "-"
$self->get_http
Truth table0%0/2
A
A= $self->get_http
Aresult
11
00
118 0 ▶ $self->log_info( ' scheduled events: [%s]', $self->has_events ? 'yes' : 'no' );
Branch: 1 branch
BranchTrueFalseTotal
$self->has_events ? : 0 0 0
119 0 $self->section_break;
120  
121 0 $self->log_info( ' subnets in VPC: [%s]', $config->{vpc_id} );
122 0 ▶ $self->log_info( ' public: [%s]', join q{,}, @{ $subnets->{public} || [] } );
Condition0%0/2
$subnets->{'public'} || []
l!l
00
MC/DC0%0/1
$subnets->{'public'} || []
$subnets->{'public'}
Truth table0%0/2
A
A= $subnets->{'public'}
Aresult
11
00
123 0 ▶ $self->log_info( ' private: [%s]', join q{,}, @{ $subnets->{private} || [] } );
Condition0%0/2
$subnets->{'private'} || []
l!l
00
MC/DC0%0/1
$subnets->{'private'} || []
$subnets->{'private'}
Truth table0%0/2
A
A= $subnets->{'private'}
Aresult
11
00
124 0 $self->section_break;
125  
126 0 $self->log_info( ' config: [%s]', $self->get_config_name );
127 0 ▶ $self->log_info( ' log level: [%s]', $self->get_log_level // 'info' );
Condition0%0/2
$self->get_log_level // "info"
l!l
00
MC/DC0%0/1
$self->get_log_level // "info"
$self->get_log_level
Truth table0%0/2
A
A= $self->get_log_level
Aresult
11
00
128 0 ▶ $self->log_info( ' cache: [%s]', $self->get_cache ? 'enabled' : 'disabled' );
Branch: 1 branch
BranchTrueFalseTotal
$self->get_cache ? : 0 0 0
129 0 ▶ $self->log_warn( ' update config: [%s]', $self->get_update ? 'yes' : 'no' );
Branch: 1 branch
BranchTrueFalseTotal
$self->get_update ? : 0 0 0
130 0 ▶ $self->log_warn( ' dryrun: [%s]', $dryrun ? 'yes' : 'no' );
Branch: 1 branch
BranchTrueFalseTotal
$dryrun ? : 0 0 0
131  
132 0 return;
133 }
134  
135 ########################################################################
136 0 ▶sub check_service_name {
Subroutine check_service_name: not called CC=8 SCAR=42.8
Pod undocumented
137 ########################################################################
138 0 my ( $self, $service_name, $return_on_missing ) = @_;
139  
140 0 my $tasks = $self->common_args('tasks');
141  
142 return $service_name
143 0 ▶ if $service_name && $tasks->{$service_name};
Branch: 1 branch
BranchTrueFalseTotal
if $service_name and $tasks->{$service_name} 0 0 0
Condition0%0/3
$service_name and $tasks->{$service_name}
!ll&&!rl&&r
000
MC/DC0%0/2
$service_name and $tasks->{$service_name}
$service_name $tasks->{$service_name}
Truth table0%0/3
A and B
A= $service_nameB= $tasks->{$service_name}
ABresult
0X0
100
111
144  
145 # if only 1 service in config, then let's stat that
146 0 my ( $default_service, $error ) = grep { $tasks->{$_}->{type} =~ /daemon|http/xsm } keys %{$tasks};
147  
148 return
149 0 ▶ if $default_service || ( !$default_service && $return_on_missing );
Branch: 1 branch
BranchTrueFalseTotal
if $default_service or not $default_service and $return_on_missing 0 0 0
Condition0%0/6
$default_service or not $default_service and $return_on_missing
l!l&&r!l&&!r
000
not $default_service and $return_on_missing
!ll&&!rl&&r
000
MC/DC0%0/3
$default_service or not $default_service and $return_on_missing
$default_service not $default_service $return_on_missing
Truth table0%0/4
A or not(B) and C
A= $default_serviceB= not $default_serviceC= $return_on_missing
ABCresult
1XX1
0111
00X0
0100
150  
151 0 ▶ if ($error) {
Branch: 2 branches
BranchTrueFalseTotal
if ($error) { } 0 0 0
elsif ($service_name) { } 0 0 0
152 0 $self->log_error('ERROR: multiple service defined in configuration.');
153 }
154 elsif ($service_name) {
155 0 $self->log_error( 'ERROR: no such service: [%s] in configuration', $service_name );
156 }
157 else {
158 0 $self->log_error('ERROR: no services defined in configuration');
159 }
160  
161 0 die sprintf "usage: %s status service-name\n", $ENV{SCRIPT_NAME};
162  
163 0 return $service_name;
164 }
165  
166 ########################################################################
167 0 ▶sub cmd_state {
Subroutine cmd_state: not called CC=4 SCAR=30.0
Pod undocumented
168 ########################################################################
169 0 my ( $self, @args ) = @_;
170  
171 0 my ($config_name) = $self->get_args;
172  
173 0 my $options = $self->fetch_option_defaults;
174  
175 0 my $defaults_file = '.fargatestack/defaults.json';
176  
177 0 ▶ if ($config_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_name) 0 0 0
178 0 my ( $name, $path, $ext ) = fileparse( $config_name, qr/[.][^.]+$/xsm );
179  
180 0 $path = realpath($path);
181  
182 0 ▶ my $fqp = sprintf '%s/%s%s', $path, $name, $ext || 'yml';
Condition0%0/2
$ext || 'yml'
l!l
00
MC/DC0%0/1
$ext || 'yml'
$ext
Truth table0%0/2
A
A= $ext
Aresult
11
00
183  
184 0 ▶ die sprintf "ERROR: file not found: [%s]\n", $fqp
Branch: 1 branch
BranchTrueFalseTotal
unless -s $fqp 0 0 0
185 if !-s $fqp;
186  
187 0 $options->{config} = $fqp;
188  
189 0 $self->write_json_file( $defaults_file, $options );
190 0 $config_name = $name;
191 }
192  
193 my $data = [
194 { Profile => $options->{profile},
195 'DNS Profile' => $options->{route53_profile},
196 'Max Events', => $options->{max_events},
197 'Config' => $options->{config},
198 'Region' => $options->{region},
199 }
200 0 ];
201  
202 0 my @columns = ( 'Profile', 'DNS Profile', 'Region', 'Config', 'Max Events' );
203  
204 0 print {*STDOUT} easy_table(
205 table_options => { headingText => sprintf 'Current Defaults: %s', $config_name },
206 columns => \@columns,
207 data => $data,
208 );
209  
210 0 return $SUCCESS;
211 }
212  
213 ########################################################################
214 0 ▶sub cmd_show {
Subroutine cmd_show: not called CC=2 SCAR=17.9
Pod undocumented
215 ########################################################################
216 0 my ( $self, @args ) = @_;
217  
218 0 my ($command) = $self->get_args;
219  
220 0 my %sub_commands = ( 'cloudtrail-events' => \&cmd_cloudtrail_events, );
221  
222 die sprintf "ERROR: not a valid command. Must be one of: \n\t%s\n", join "\n\t", keys %sub_commands
223 0 ▶ if !$sub_commands{$command};
Branch: 1 branch
BranchTrueFalseTotal
unless $sub_commands{$command} 0 0 0
224  
225 0 return $sub_commands{$command}->($self);
226 }
227  
228 ########################################################################
229 0 ▶sub cmd_service_status {
Subroutine cmd_service_status: not called CC=4 SCAR=28.1
Pod undocumented
230 ########################################################################
231 0 my ( $self, @args ) = @_;
232  
233 0 my $service_name = $self->check_service_name( @args, $self->get_args );
234  
235 0 my ( $cluster, $tasks ) = $self->common_args(qw(cluster tasks));
236  
237 0 my $cluster_name = $cluster->{name};
238  
239 0 $self->verify_service($service_name);
240  
241 0 require Text::Wrap;
242 0 Text::Wrap->import('wrap');
243  
244 {
245 ## no critic
246 0 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.2
247 0 $Text::Wrap::columns = 100;
248 }
249  
250 0 my @elems = qw(running_count desired_count status pending_count events task_definition);
251  
252 0 my $query = jmespath_mapping 'services[0]' => \@elems;
253 0 my $ecs = $self->fetch_ecs;
254  
255 0 my $result = $ecs->describe_services(
256 cluster_name => $cluster_name,
257 service_name => $service_name,
258 query => $query,
259 );
260  
261 0 ▶ log_die( $self, "ERROR: could not describe service [%s]\n%s", $service_name, $self->get_ecs->get_error )
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 0 0
262 if !$result;
263  
264 my ( $running_count, $desired_count, $status, $pending_count, $events, $task_definition_arn )
265 0 = @{$result}{@elems};
266  
267 0 ▶ $pending_count //= q{-};
Condition0%0/2
$pending_count //= "-"
l!l
00
MC/DC0%0/1
$pending_count //= "-"
$pending_count
Truth table0%0/2
A
A= $pending_count
Aresult
11
00
268  
269 0 ▶ $status = $self->maybe_color( $status eq 'ACTIVE' ? 'bright_green' : 'bright_yellow' => $status );
Branch: 1 branch
BranchTrueFalseTotal
$status eq 'ACTIVE' ? : 0 0 0
270  
271 0 my $title = sprintf "Service:[%s]\n", $self->maybe_color( bright_white => $service_name );
272  
273 0 $title .= sprintf "Status:[%s] Running:[%s] Pending:[%s] Desired:[%s]\n",
274 $status,
275 $self->maybe_color( green => $running_count ),
276 $self->maybe_color( yellow => $pending_count ),
277 $self->maybe_color( bright_white => $desired_count );
278  
279 0 $title .= sprintf 'Task Definition: [%s]', $self->maybe_color( 'bright_white' => $task_definition_arn );
280  
281 0 my @events = grep {defined} @{ $result->{events} }[ 0 .. ( $self->get_max_events - 1 ) ];
282  
283 0 my @data = map { { 'Time' => $_->{createdAt}, Event => wrap( q{}, q{}, $_->{message} ) } } @events;
284  
285 0 print {*STDOUT} easy_table(
286 table_options => { headingText => $title, allowANSI => $TRUE },
287 data => \@data,
288 columns => [qw(Time Event)],
289 );
290  
291 0 $self->display_task_status($service_name);
292  
293 0 return $SUCCESS;
294 }
295  
296 ########################################################################
297 0 ▶sub display_task_status {
Subroutine display_task_status: not called CC=5 SCAR=34.0
Pod undocumented
298 ########################################################################
299 0 my ( $self, $service_name ) = @_;
300  
301 0 my $ecs = $self->fetch_ecs;
302  
303 0 my $cluster_name = $self->get_config->{cluster}->{name};
304  
305 0 my $task_arns = $ecs->list_tasks( $cluster_name, 'taskArns' );
306 0 $ecs->check_result( message => 'ERROR: could not list tasks for cluster: [%s]', $cluster_name );
307  
308 return
309 0 ▶ if !@{$task_arns};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$task_arns;} 0 0 0
310  
311 0 $task_arns = [ map { basename($_) } @{$task_arns} ];
312  
313 0 my $query
314 = sprintf
315 'tasks[?group == `service:%s`].{started_at:startedAt, task_definition_arn:taskDefinitionArn, last_status:lastStatus, image_digest:containers[0].imageDigest}',
316 $service_name;
317  
318 0 my $service_tasks = $ecs->describe_tasks( $cluster_name, $task_arns, $query );
319 0 $ecs->check_result( message => 'ERROR: Could not describe tasks: [%s]', join q{,}, @{$task_arns} );
320  
321 0 ▶ $self->log_debug( sub { return Dumper( [ service_tasks => $service_tasks ] ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
322  
323 0 my @data;
324  
325 0 foreach my $task ( @{$service_tasks} ) {
326 my ( $image_digest, $task_definition_arn, $started_at, $last_status )
327 0 = @{$task}{qw(image_digest task_definition_arn started_at last_status)};
328  
329 0 my $short_image_digest = abbrev( $image_digest, 16 );
330 0 my $short_task_definition_arn = ( split m{/}xsm, $task_definition_arn )[-1];
331  
332 0 my $latest_task_definition_arn = $self->get_latest_task_definition($service_name);
333  
334 0 my $latest_image_digest = $self->get_latest_image($service_name)->{imageDigest};
335  
336 0 ▶ $last_status = $self->maybe_color( $last_status eq 'RUNNING' ? 'green' : 'yellow' => $last_status );
Branch: 1 branch
BranchTrueFalseTotal
$last_status eq 'RUNNING' ? : 0 0 0
337  
338 $self->log_debug(
339 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
340 0 return Dumper(
341 [ task => $task,
342 latest_image_digest => $latest_image_digest
343 ]
344 );
345 }
346 0 );
347  
348 0 ▶ my $task_definition_status = choose {
Subroutine __ANON__: not called CC=2 SCAR=17.9
349 0 ▶ return $self->maybe_color( green => 'Current' )
Branch: 1 branch
BranchTrueFalseTotal
if $task_definition_arn eq $latest_task_definition_arn 0 0 0
350 if $task_definition_arn eq $latest_task_definition_arn;
351  
352 0 return $self->maybe_color( red => ( split m{/}xsm, $latest_task_definition_arn )[-1] );
353 0 };
354  
355 0 ▶ $image_digest //= q{};
Condition0%0/2
$image_digest //= ""
l!l
00
MC/DC0%0/1
$image_digest //= ""
$image_digest
Truth table0%0/2
A
A= $image_digest
Aresult
11
00
356  
357 0 ▶ my $image_digest_status = choose {
Subroutine __ANON__: not called CC=2 SCAR=17.9
358 0 ▶ return $self->maybe_color( green => 'Current' )
Branch: 1 branch
BranchTrueFalseTotal
if $image_digest eq $latest_image_digest 0 0 0
359 if $image_digest eq $latest_image_digest;
360  
361 0 return $self->maybe_color( red => abbrev( $latest_image_digest, 16 ) );
362 0 };
363  
364 0 push @data,
365 {
366 'Started At' => $started_at,
367 'Status' => $last_status,
368 'Task Definition' => $short_task_definition_arn,
369 'Task Definition Status' => $task_definition_status,
370 'Image Digest' => $short_image_digest,
371 'Image Status' => $image_digest_status,
372 };
373 }
374  
375 0 print {*STDOUT} "\n\n",
376 easy_table(
377 table_options => { headingText => 'Task Status', allowANSI => $TRUE },
378 data => \@data,
379 columns => [ 'Started At', 'Status', 'Task Definition', 'Task Definition Status', 'Image Digest', 'Image Status' ],
380 );
381  
382 0 return;
383 }
384  
385 ########################################################################
386 0 ▶sub get_default_task_name {
Subroutine get_default_task_name: not called CC=6 SCAR=37.4
Pod undocumented
387 ########################################################################
388 0 my ( $self, $type, $filter ) = @_;
389  
390 0 my $tasks = $self->common_args('tasks');
391  
392 0 my ($task_name) = $self->get_args;
393  
394 0 ▶ return $task_name
Branch: 1 branch
BranchTrueFalseTotal
if $task_name 0 0 0
395 if $task_name;
396  
397 0 my @task_names = keys %{$tasks};
398  
399 0 ▶ return $task_names[0]
Branch: 1 branch
BranchTrueFalseTotal
if @task_names == 1 0 0 0
400 if @task_names == 1;
401  
402 0 ▶ $type //= 'task';
Condition0%0/2
$type //= "task"
l!l
00
MC/DC0%0/1
$type //= "task"
$type
Truth table0%0/2
A
A= $type
Aresult
11
00
403  
404 0 my @tasks = grep { $tasks->{$_}->{type} eq $type } keys %{$tasks};
405  
406 0 ▶ if ($filter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filter) 0 0 0
407 0 @tasks = grep { defined $tasks->{$_}->{$filter} } @tasks;
408 }
409  
410 # more than 1, error or we found just 1
411 0 ▶ return $tasks[1] ? $EMPTY : $tasks[0];
Branch: 1 branch
BranchTrueFalseTotal
$tasks[1] ? : 0 0 0
412 }
413  
414 ########################################################################
415 0 ▶sub cmd_run_task {
Subroutine cmd_run_task: not called CC=28 SCAR=67.0
Pod undocumented
416 ########################################################################
417 0 my ($self) = @_;
418  
419 0 my ( $config, $tasks, $dryrun, $cluster, $security_groups )
420 = $self->common_args(qw(config tasks dryrun cluster security_groups));
421  
422 0 my $task_name = $self->get_default_task_name('task');
423  
424 die sprintf "usage: %s run-task task-name\n", $ENV{SCRIPT_NAME}
425 0 ▶ if !$task_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $task_name 0 0 0
426  
427 0 my $task = $tasks->{$task_name};
428  
429 0 ▶ log_die( $self, "ERROR: no such task [%s] defined in config\n", $task_name )
Branch: 1 branch
BranchTrueFalseTotal
unless $task 0 0 0
430 if !$task;
431  
432 log_die( $self, "ERROR: [%s] is not a task\n", $task_name )
433 0 ▶ if $task->{type} ne 'task';
Branch: 1 branch
BranchTrueFalseTotal
if $task->{"type"} ne "task" 0 0 0
434  
435 0 my $subnet_id = $self->get_subnet_id;
436 0 my $is_public = $FALSE;
437  
438 0 ▶ if ( !$subnet_id ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $subnet_id) { } 0 0 0
elsif (&any(sub { $subnet_id eq $_; } , @{$self->get_subnets->{'public'} // [];})) { } 0 0 0
elsif (&none(sub { $subnet_id eq $_; } , @{$self->get_subnets->{'private'} // [];})) { } 0 0 0
439 0 ▶ my @subnets = @{ $self->get_subnets->{private} // [] };
Condition0%0/2
$self->get_subnets->{"private"} // []
l!l
00
MC/DC0%0/1
$self->get_subnets->{"private"} // []
$self->get_subnets->{"private"}
Truth table0%0/2
A
A= $self->get_subnets->{"private"}
Aresult
11
00
440  
441 0 ▶ if ( !@subnets ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@subnets) 0 0 0
442 0 $self->log_warn('run-task: using public subnets is not recommended...');
443 0 ▶ @subnets = @{ $self->get_subnets->{public} // [] };
Condition0%0/2
$self->get_subnets->{"public"} // []
l!l
00
MC/DC0%0/1
$self->get_subnets->{"public"} // []
$self->get_subnets->{"public"}
Truth table0%0/2
A
A= $self->get_subnets->{"public"}
Aresult
11
00
444 }
445  
446 0 $subnet_id = $subnets[0];
447 }
448 0 ▶ elsif ( any { $subnet_id eq $_ } @{ $self->get_subnets->{public} // [] } ) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/2
$self->get_subnets->{"public"} // []
l!l
00
MC/DC0%0/1
$self->get_subnets->{"public"} // []
$self->get_subnets->{"public"}
Truth table0%0/2
A
A= $self->get_subnets->{"public"}
Aresult
11
00
449 0 $self->log_error( 'run-task: subnet-id: [%s] is in a public subnet...consider running your jobs in a private subnet',
450 $subnet_id );
451 0 $is_public = $TRUE;
452 }
453 0 ▶ elsif ( none { $subnet_id eq $_ } @{ $self->get_subnets->{private} // [] } ) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/2
$self->get_subnets->{"private"} // []
l!l
00
MC/DC0%0/1
$self->get_subnets->{"private"} // []
$self->get_subnets->{"private"}
Truth table0%0/2
A
A= $self->get_subnets->{"private"}
Aresult
11
00
454 0 log_die( $self, 'subnet: [%s] is not in a public or private subnet in this VPC.', $subnet_id );
455 }
456  
457 my $network_configuration = {
458 awsvpcConfiguration => {
459 subnets => [$subnet_id],
460 0 ▶ securityGroups => [ $security_groups->{fargate}->{group_id} ],
Branch: 1 branch
BranchTrueFalseTotal
$is_public ? : 0 0 0
461 assignPublicIp => $is_public ? 'ENABLED' : 'DISABLED',
462 }
463 };
464  
465 # check for latest image...
466 0 $self->check_latest_image($task_name);
467  
468 # this may be null if we are in dryrun mode and the config has not been updated
469 my $cluster_name
470 = $dryrun && !$cluster->{name}
471 ? sprintf '%s-cluster', $config->{app}->{name}
472 0 ▶ : $cluster->{name};
Branch: 1 branch
BranchTrueFalseTotal
$dryrun && !$cluster->{'name'} ? : 0 0 0
Condition0%0/3
$dryrun and not $cluster->{"name"}
!ll&&!rl&&r
000
MC/DC0%0/2
$dryrun and not $cluster->{"name"}
$dryrun not $cluster->{"name"}
Truth table0%0/3
A and not(B)
A= $dryrunB= not $cluster->{"name"}
ABresult
0X0
100
111
473  
474 0 $self->log_warn( 'run-task: cluster: [%s] launching task: [%s] in subnet: [%s]...%s',
475 $cluster_name, $task_name, $subnet_id, $dryrun );
476  
477 0 ▶ $self->log_trace( sub { return Dumper( [ awsvpcConfiguration => $network_configuration ] ); } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
478  
479 0 ▶ return $SUCCESS
Branch: 1 branch
BranchTrueFalseTotal
if $dryrun 0 0 0
480 if $dryrun;
481  
482 0 ▶ log_die( $self, 'run-task: cluster has not been created yet...run "apply" first' )
Branch: 1 branch
BranchTrueFalseTotal
unless $cluster_name 0 0 0
483 if !$cluster_name;
484  
485 0 my $ecs = $self->fetch_ecs;
486  
487 my $result = $self->get_ecs->run_task(
488 cluster => $cluster->{name},
489 0 task_definition => $task_name,
490 network_configuration => $network_configuration,
491 );
492  
493 0 ▶ log_die( $self, "ERROR: could not run task [%s]\n%s\n", $task_name, $self->get_ecs->get_error )
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 0 0
494 if !$result;
495  
496 0 my @failures = @{ $result->{failures} };
497  
498 0 ▶ log_die( $self, 'ERROR: task failed to launch: %s', Dumper( \@failures ) )
Branch: 1 branch
BranchTrueFalseTotal
if @failures 0 0 0
499 if @failures;
500  
501 0 ($tasks) = @{ $result->{tasks} };
502  
503 0 my $task_arn = $tasks->{taskArn};
504  
505 0 ▶ my $should_wait = $self->get_wait ? '(waiting)' : $EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
$self->get_wait ? : 0 0 0
506  
507 0 $self->log_warn( 'run-task: task [%s] launched. ARN: [%s]...%s', $task_name, $task_arn, $should_wait );
508  
509 0 my $poll_limit = $self->get_task_timeout / $DEFAULT_ECS_POLL_TIME;
510  
511 0 ▶ if ($should_wait) {
Branch: 1 branch
BranchTrueFalseTotal
if ($should_wait) 0 0 0
512 0 my $poll_count = 0;
513  
514 0 ▶ while ( $poll_count++ < $poll_limit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($poll_count++ < $poll_limit) 0 0 0
515  
516 0 my ( $status, $stopped_reason, $exit_code ) = $self->get_task_status( $cluster_name, $task_arn );
517  
518 $self->log_warn( 'run-task: task [%s] status: [%s], exit code:[%s], reason: [%s]',
519 0 ▶ $task_name, map { $_ // q{-} } ( $status, $exit_code, $stopped_reason ) );
Condition0%0/2
$_ // "-"
l!l
00
MC/DC0%0/1
$_ // "-"
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
520  
521 0 ▶ last if $status eq 'STOPPED';
Branch: 1 branch
BranchTrueFalseTotal
if $status eq "STOPPED" 0 0 0
522  
523 0 sleep $DEFAULT_ECS_POLL_TIME;
524 }
525  
526 0 my $log_group = $config->{log_group}->{name};
527  
528 # by convention our log groups are named after our app
529 0 my $log_stream = sprintf '%s/%s/%s', $config->{app}->{name}, $task_name, ( split /\//xsm, $task_arn )[-1];
530  
531 0 require App::Logs;
532  
533 my $logs = App::Logs->new(
534 0 %{ $self->get_global_options },
535 log_group_name => $log_group,
536 log_stream_name => $log_stream
537 );
538  
539 0 my $events = $logs->get_log_events();
540  
541 0 ▶ log_die( $self, "run-task: unable to get logs from log group: [%s], stream: [%s]\n%s",
Branch: 1 branch
BranchTrueFalseTotal
unless $events 0 0 0
542 $log_group, $log_stream, $logs->get_error )
543 if !$events;
544  
545 0 ▶ while ( $events && @{ $events->{events} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($events and @{$events->{"events"};}) 0 0 0
Condition0%0/3
$events and @{$events->{"events"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$events and @{$events->{"events"};}
$events @{$events->{"events"};}
Truth table0%0/3
A and B
A= $eventsB= @{$events->{"events"};}
ABresult
0X0
100
111
546  
547 0 foreach my $e ( @{ $events->{events} } ) {
548  
549 0 my ( $timestamp, $message ) = @{$e}{qw(timestamp message)};
550 0 $timestamp = scalar localtime $timestamp / 1000;
551  
552 0 print {*STDOUT} sprintf "%s - %s\n", $timestamp, $message;
553 }
554  
555 0 $events = $logs->get_next_log_events( $events->{nextForwardToken} );
556 }
557 }
558  
559 0 return $SUCCESS;
560 }
561  
562 ########################################################################
563 0 ▶sub check_latest_image {
Subroutine check_latest_image: not called CC=5 SCAR=34.0
Pod undocumented
564 ########################################################################
565 0 my ( $self, $task_name ) = @_;
566  
567 0 my $tasks = $self->common_args('tasks');
568  
569 0 my $latest_image = $self->get_latest_image($task_name);
570 0 my $latest_digest = $latest_image->{imageDigest};
571 0 ▶ my $current_digest = $tasks->{$task_name}->{image_digest} // $EMPTY;
Condition0%0/3
$tasks->{$task_name}{"image_digest"} // $App::FargateStack::EMPTY
l!l&&r!l&&!r
000
MC/DC0%0/2
$tasks->{$task_name}{"image_digest"} // $App::FargateStack::EMPTY
$tasks->{$task_name}{"image_digest"} $App::FargateStack::EMPTY
Truth table0%0/3
A // B
A= $tasks->{$task_name}{"image_digest"}B= $App::FargateStack::EMPTY
ABresult
1X1
011
000
572  
573 0 ▶ if ( $current_digest && $current_digest ne $latest_digest ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_digest and $current_digest ne $latest_digest) 0 0 0
Condition0%0/3
$current_digest and $current_digest ne $latest_digest
!ll&&!rl&&r
000
MC/DC0%0/2
$current_digest and $current_digest ne $latest_digest
$current_digest $current_digest ne $latest_digest
Truth table0%0/3
A and B
A= $current_digestB= $current_digest ne $latest_digest
ABresult
0X0
100
111
574 0 $self->log_error('run-task: You are not running the latest image!');
575 0 $self->log_error( 'run-task: [%s] != [%s]', $latest_digest, $current_digest );
576 0 $self->log_error('run-task: run "app-FargateStack register-task" to align the latest image with your task');
577  
578 0 ▶ log_die( $self, 'run-task: use --force to force service creation or align your task with new image' )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_force 0 0 0
579 if !$self->get_force;
580 }
581  
582 0 return $TRUE;
583 }
584  
585 ########################################################################
586 0 ▶sub get_task_status {
Subroutine get_task_status: not called CC=1 SCAR=6.9
Pod undocumented
587 ########################################################################
588 0 my ( $self, $cluster_name, $task_arn ) = @_;
589  
590 0 my @elems = qw(last_status stopped_reason containers);
591  
592 0 my $query = jmespath_mapping 'tasks[0]' => \@elems;
593 0 my $ecs = $self->fetch_ecs;
594  
595 0 my $result = $ecs->describe_tasks( $cluster_name, $task_arn, $query );
596 0 $ecs->check_result( message => 'ERROR: unable to describe task: [%s]', $task_arn );
597  
598 0 my ( $status, $stopped_reason, $containers ) = @{$result}{@elems};
599  
600 0 return ( $status, $stopped_reason, $containers->[0]->{exitCode} );
601 }
602  
603 ########################################################################
604 0 ▶sub get_default_service_name {
Subroutine get_default_service_name: not called CC=3 SCAR=24.8
Pod undocumented
605 ########################################################################
606 0 my ( $self, $skip_arg ) = @_;
607  
608 # skip retrieving the arg (used when we want to allow a count as the first arg)
609 0 ▶ if ( !$skip_arg ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($skip_arg) 0 0 0
610 0 my ($service_name) = $self->get_args;
611  
612 0 ▶ return $service_name
Branch: 1 branch
BranchTrueFalseTotal
if $service_name 0 0 0
613 if $service_name;
614 }
615  
616 0 my $tasks = $self->get_config->{tasks};
617  
618 0 return grep { $tasks->{$_}->{type} =~ /^(https?|daemon)/xsm } keys %{$tasks};
619 }
620  
621 ########################################################################
622 0 ▶sub cmd_deploy_service {
Subroutine cmd_deploy_service: not called CC=13 SCAR=52.0
Pod undocumented
623 ########################################################################
624 0 my ($self) = @_;
625  
626 0 my ( $config, $tasks ) = $self->common_args(qw(config tasks));
627  
628 0 my ( $task_name, $desired_count ) = $self->get_args;
629  
630 0 ▶ if ( $task_name && looks_like_number $task_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($task_name and &looks_like_number($task_name)) 0 0 0
Condition0%0/3
$task_name and &looks_like_number($task_name)
!ll&&!rl&&r
000
MC/DC0%0/2
$task_name and &looks_like_number($task_name)
$task_name &looks_like_number($task_name)
Truth table0%0/3
A and B
A= $task_nameB= &looks_like_number($task_name)
ABresult
0X0
100
111
631 0 $desired_count = $task_name;
632 0 $task_name = $EMPTY;
633 }
634  
635 0 ▶ if ( !$task_name || !exists $tasks->{$task_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($task_name and exists $tasks->{$task_name}) 0 0 0
Condition0%0/3
$task_name and exists $tasks->{$task_name}
!ll&&!rl&&r
000
MC/DC0%0/2
$task_name and exists $tasks->{$task_name}
$task_name exists $tasks->{$task_name}
Truth table0%0/3
A and B
A= $task_nameB= exists $tasks->{$task_name}
ABresult
0X0
100
111
636 0 ( $task_name, my $err ) = $self->get_default_service_name($TRUE); # skip arg
637  
638 0 ▶ if ( $err || !$task_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err or not $task_name) 0 0 0
Condition0%0/3
$err or not $task_name
l!l&&r!l&&!r
000
MC/DC0%0/2
$err or not $task_name
$err not $task_name
Truth table0%0/3
A or not(B)
A= $errB= not $task_name
ABresult
1X1
011
000
639 0 ▶ if ($err) {
Branch: 2 branches
BranchTrueFalseTotal
if ($err) { } 0 0 0
elsif (not $task_name) { } 0 0 0
640 0 $self->log_error('ERROR: multiple services in configuration.');
641 }
642 elsif ( !$task_name ) {
643 0 ▶ $self->log_error( 'ERROR: %s',
Branch: 1 branch
BranchTrueFalseTotal
$task_name ? : 0 0 0
644 $task_name ? "service: [$task_name] not found in configuration" : 'no service types in configuration' );
645 }
646  
647 0 die sprintf "usage: %s deploy-service service-name\n", $ENV{SCRIPT_NAME};
648 }
649 }
650  
651 0 ▶ if ( !$desired_count || !looks_like_number $desired_count ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($desired_count and &looks_like_number($desired_count)) 0 0 0
Condition0%0/3
$desired_count and &looks_like_number($desired_count)
!ll&&!rl&&r
000
MC/DC0%0/2
$desired_count and &looks_like_number($desired_count)
$desired_count &looks_like_number($desired_count)
Truth table0%0/3
A and B
A= $desired_countB= &looks_like_number($desired_count)
ABresult
0X0
100
111
652 0 ▶ $desired_count = $tasks->{$task_name}->{desired_count} // 1;
Condition0%0/2
$tasks->{$task_name}{"desired_count"} // 1
l!l
00
MC/DC0%0/1
$tasks->{$task_name}{"desired_count"} // 1
$tasks->{$task_name}{"desired_count"}
Truth table0%0/2
A
A= $tasks->{$task_name}{"desired_count"}
Aresult
11
00
653 }
654  
655 0 $self->log_info('service: checking to see if task and latest image are aligned...');
656  
657 0 $self->check_latest_image($task_name);
658  
659 0 return $self->build_service( $task_name, $desired_count );
660 }
661  
662 ########################################################################
663 0 ▶sub check_task {
Subroutine check_task: not called CC=5 SCAR=34.0
Pod undocumented
664 ########################################################################
665 0 my ( $self, $task_name, $warn ) = @_;
666  
667 0 ▶ my $level = $warn ? 'warn' : 'die';
Branch: 1 branch
BranchTrueFalseTotal
$warn ? : 0 0 0
668  
669 0 my $config = $self->get_config;
670  
671 return $TRUE
672 0 ▶ if $task_name && $config->{tasks}->{$task_name};
Branch: 1 branch
BranchTrueFalseTotal
if $task_name and $config->{"tasks"}{$task_name} 0 0 0
Condition0%0/3
$task_name and $config->{"tasks"}{$task_name}
!ll&&!rl&&r
000
MC/DC0%0/2
$task_name and $config->{"tasks"}{$task_name}
$task_name $config->{"tasks"}{$task_name}
Truth table0%0/3
A and B
A= $task_nameB= $config->{"tasks"}{$task_name}
ABresult
0X0
100
111
673  
674 0 ▶ log_die( $self, 'ERROR: no such task [%s] defined in config', $task_name )
Branch: 1 branch
BranchTrueFalseTotal
if $level eq "die" 0 0 0
675 if $level eq 'die';
676  
677 0 $self->get_logger->warn( 'WARNING: no such task [%s] defined in config...trying anyway ¯\_(ツ)_/¯', $task_name );
678  
679 0 return;
680 }
681  
682 ########################################################################
683 0 ▶sub cmd_remove_service {
Subroutine cmd_remove_service: not called CC=4 SCAR=30.0
Pod undocumented
684 ########################################################################
685 0 my ($self) = @_;
686  
687 0 my ( $task_name, $err ) = $self->get_default_service_name();
688  
689 die "usage: %s remove-service task-name\n", $ENV{SCRIPT_NAME}
690 0 ▶ if !$task_name || $err;
Branch: 1 branch
BranchTrueFalseTotal
if not $task_name or $err 0 0 0
Condition0%0/3
not $task_name or $err
l!l&&r!l&&!r
000
MC/DC0%0/2
not $task_name or $err
not $task_name $err
Truth table0%0/3
not(A) or B
A= not $task_nameB= $err
ABresult
1X1
011
000
691  
692 0 my ( $config, $cluster, $dryrun ) = $self->common_args(qw(config cluster dryrun));
693  
694 0 my $cluster_name = $cluster->{name};
695  
696 0 $self->verify_service($task_name);
697  
698 0 $self->check_task( $task_name, 'warn' );
699  
700 0 $self->log_warn( 'remove-service: task [%s] will be deleted...%s', $task_name, $dryrun );
701  
702 0 ▶ return $SUCCESS
Branch: 1 branch
BranchTrueFalseTotal
if $dryrun 0 0 0
703 if $dryrun;
704  
705 0 my $ecs = $self->fetch_ecs;
706  
707 0 my $result = $ecs->delete_service( $cluster->{name}, $task_name );
708 0 $ecs->check_result( message => 'ERROR: could not stop service %s', $task_name );
709  
710 0 return $SUCCESS;
711 }
712  
713 ########################################################################
714 0 ▶sub verify_service {
Subroutine verify_service: not called CC=5 SCAR=34.0
Pod undocumented
715 ########################################################################
716 0 my ( $self, $service_name ) = @_;
717  
718 0 my ( $cluster, $config ) = $self->common_args(qw(cluster config));
719  
720 0 ▶ my $cluster_name //= $cluster->{name};
Condition0%0/3
my $cluster_name //= $cluster->{"name"}
l!l&&r!l&&!r
000
MC/DC0%0/2
my $cluster_name //= $cluster->{"name"}
my $cluster_name $cluster->{"name"}
Truth table0%0/3
A //= B
A= my $cluster_nameB= $cluster->{"name"}
ABresult
1X1
011
000
721  
722 0 my $ecs = $self->fetch_ecs;
723  
724 0 my $services = $ecs->list_services( $cluster_name, 'serviceArns' );
725  
726 0 ▶ die sprintf "ERROR: could not list services for cluster: [%s]\n%s", $cluster_name, $ecs->get_error
Branch: 1 branch
BranchTrueFalseTotal
unless $services 0 0 0
727 if !$services;
728  
729 die sprintf "ERROR: no services running in cluster: [%s]\n", $cluster_name
730 0 ▶ if !@{$services};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$services;} 0 0 0
731  
732 die sprintf "ERROR: service [%s] is not running in cluster: [%s]\n", $service_name, $cluster_name
733 0 ▶ if none { $_ =~ /$service_name/xsm } @{$services};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &none(sub { $_ =~ /$service_name/msx; } , @{$services;}) 0 0 0
734  
735 0 return;
736 }
737  
738 ########################################################################
739 0 ▶sub get_task_image_digests {
Subroutine get_task_image_digests: not called CC=1 SCAR=6.9
Pod undocumented
740 ########################################################################
741 0 my ( $self, $task_name ) = @_;
742 0 my $ecs = $self->fetch_ecs;
743  
744 0 my $cluster_name = $self->get_config->{cluster}->{name};
745  
746 0 my $task_arns = $ecs->list_tasks( $cluster_name, 'taskArns' );
747 0 $ecs->check_result( message => 'ERROR: Could not list tasks for cluster: [%s]', $cluster_name );
748  
749 0 my $group = sprintf 'service:%s', $task_name;
750  
751 0 my $query = sprintf 'tasks[?group == `%s`].containers[].{imageDigest:imageDigest}[].imageDigest', $task_name;
752  
753 0 my $image_digests = $ecs->describe_tasks( $cluster_name, $task_arns, $query );
754 0 $ecs->check_result( message => 'ERROR: could not describe tasks for task arns: [%s]', join q{,}, @{$task_arns} );
755  
756 0 return $image_digests;
757 }
758  
759 ########################################################################
760 0 ▶sub get_latest_task_definition {
Subroutine get_latest_task_definition: not called CC=1 SCAR=6.9
Pod undocumented
761 ########################################################################
762 0 my ( $self, $task_name ) = @_;
763  
764 0 my $tasks = $self->get_config->{tasks};
765  
766 0 my $task_definition_arn = $tasks->{$task_name};
767  
768 0 my $ecs = $self->fetch_ecs;
769  
770 0 my $task_definitions = $ecs->list_task_definitions( $task_name, 'taskDefinitionArns' );
771 0 $ecs->check_result( message => 'ERROR: could list task definitions for [%s]', $task_name );
772  
773 my ($latest_task_definition) = sort {
774 0 my ($num_a) = $a =~ /:(\d+)$/xsm;
775 0 my ($num_b) = $b =~ /:(\d+)$/xsm;
776 0 $num_b <=> $num_a
777 0 } @{$task_definitions};
778  
779 0 my ($latest_task_definition_version) = $latest_task_definition =~ /(:\d+)$/xsm;
780 0 my ($task_definition_version) = $task_definition_arn =~ /(:\d+)$/xsm;
781  
782 0 return $latest_task_definition,;
783 }
784  
785 ########################################################################
786 0 ▶sub cmd_update_service {
Subroutine cmd_update_service: not called CC=1 SCAR=6.9
Pod undocumented
787 ########################################################################
788 0 my ( $self, @args ) = @_;
789  
790 0 my $service_name = $self->check_service_name( @args, $self->get_args );
791  
792 0 my ($cluster) = $self->common_args(qw(cluster));
793  
794 0 my $cluster_name = $cluster->{name};
795  
796 0 $self->verify_service($service_name);
797  
798 0 my $ecs = $self->fetch_ecs;
799  
800 0 my $task_definition_arn = $self->get_latest_task_definition($service_name);
801  
802 0 my @elems = qw(status running_count desired_count pending_count task_definition);
803  
804 0 my $result = $ecs->update_service(
805 cluster_name => $cluster_name,
806 service_name => $service_name,
807 task_definition => basename($task_definition_arn),
808 query => jmespath_mapping( service => \@elems ),
809 );
810  
811 0 $ecs->check_result( message => 'ERROR: could not update service: [%s]', $service_name );
812  
813 0 ▶ $self->log_debug( sub { return Dumper( [ result => $result ] ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
814  
815 my @data = {
816 'Status' => $self->maybe_color( bright_white => $result->{status} ),
817 'Running Count' => $self->maybe_color( green => $result->{running_count} ),
818 'Desired Count' => $self->maybe_color( bright_white => $result->{desired_count} ),
819 0 'Pending Count' => $self->maybe_color( yellow => $result->{pending_count} ),
820 };
821  
822 0 print {*STDOUT} easy_table(
823 table_options => {
824 allowANSI => $TRUE,
825 headingText => sprintf "Service Status\nTask Definition: %s",
826 $result->{task_definition}
827 },
828 0 data => \@data,
829 columns => [ 'Status', 'Running Count', 'Pending Count', 'Desired Count' ]
830 );
831  
832 0 print {*STDOUT} <<'END_OF_NOTE';
833 * Note that this command will not force redeployment of your services! To force redeployment of your servicce:
834  
835 app-FargateStack redeploy [service-name]
836  
837 END_OF_NOTE
838  
839 0 return;
840 }
841  
842 ########################################################################
843 0 ▶sub update_task_count {
Subroutine update_task_count: not called CC=2 SCAR=17.9
Pod undocumented
844 ########################################################################
845 0 my ( $self, $task_name, $desired_count ) = @_;
846  
847 0 my ( $config, $cluster ) = $self->common_args(qw(config cluster));
848  
849 0 my $cluster_name = $cluster->{name};
850  
851 0 $self->verify_service($task_name);
852  
853 0 my $ecs = $self->get_ecs;
854  
855 0 my $result = $ecs->update_service(
856 cluster_name => $cluster_name,
857 desired_count => $desired_count,
858 service_name => $task_name,
859 );
860  
861 0 ▶ log_die( $self, "ERROR: could not update service: [%s]\n%s", $task_name, $ecs->get_error )
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 0 0
862 if !$result;
863  
864 0 return $result;
865 }
866  
867 ########################################################################
868 0 ▶sub cmd_start_stop_service {
Subroutine cmd_start_stop_service: not called CC=7 SCAR=40.3
Pod undocumented
869 ########################################################################
870 0 my ($self) = @_;
871  
872 0 my ( $task_name, $count ) = $self->get_args;
873  
874 0 ▶ if ( looks_like_number $task_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($task_name)) 0 0 0
875 0 $count = $task_name;
876 0 $task_name = $EMPTY;
877 }
878  
879 0 $task_name = $self->check_service_name($task_name);
880 0 my $command = $self->command;
881  
882 0 ▶ if ( $command eq 'start-service' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($command eq 'start-service') { } 0 0 0
elsif ($command eq 'update-service') { } 0 0 0
883 0 ▶ $count ||= 1;
Condition0%0/2
$count ||= 1
l!l
00
MC/DC0%0/1
$count ||= 1
$count
Truth table0%0/2
A
A= $count
Aresult
11
00
884 }
885 elsif ( $command eq 'update-service' ) {
886 }
887 else {
888 0 $count = 0;
889 }
890  
891 0 ▶ if ( !$task_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($task_name) 0 0 0
892 0 ▶ if ( $count == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count == 0) 0 0 0
893 0 die sprintf "usage: %s -c config-name stop-service task-name\n", $ENV{SCRIPT_NAME};
894 }
895  
896 0 die sprintf "usage: %s -c config-name start-service task-name [count]\n", $ENV{SCRIPT_NAME};
897 }
898  
899 0 my $result = $self->update_task_count( $task_name, $count );
900  
901 0 sleep 2; # wait a few seconds for status to be updated
902  
903 0 return $self->cmd_service_status($task_name);
904 }
905  
906 ########################################################################
907 0 ▶sub cmd_register_task_definition {
Subroutine cmd_register_task_definition: not called CC=12 SCAR=50.5
Pod undocumented
908 ########################################################################
909 0 my ($self) = @_;
910  
911 0 my ( $config, $tasks, $dryrun ) = $self->common_args(qw(config tasks dryrun));
912  
913 0 my $task_name = $self->get_default_task_name;
914  
915 0 ▶ my $action = $self->get_skip_register ? 'update-target' : 'register';
Branch: 1 branch
BranchTrueFalseTotal
$self->get_skip_register ? : 0 0 0
916  
917 log_die( $self, 'usage: %s %s task-name', $action, $ENV{SCRIPT_NAME} )
918 0 ▶ if !$task_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $task_name 0 0 0
919  
920 0 my $task_definition_file = sprintf 'taskdef-%s.json', $task_name;
921  
922 0 $self->check_task($task_name);
923  
924 0 ▶ log_die( $self, "ERROR: no task definition file found for %s\n", $task_name )
Branch: 1 branch
BranchTrueFalseTotal
unless -s $task_definition_file 0 0 0
925 if !-s $task_definition_file;
926  
927 0 my $task_definition_arn;
928  
929 0 my $ecs = $self->fetch_ecs;
930  
931 0 ▶ if ( !$self->get_skip_register ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->get_skip_register) 0 0 0
932 0 $self->log_warn( 'register: registering task definition for: [%s]...%s', $task_name, $dryrun );
933  
934 0 ▶ if ( !$dryrun ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dryrun) 0 0 0
935 0 my $task_definition = $ecs->register_task_definition($task_definition_file);
936 0 $ecs->check_result( message => 'ERROR: register: could not register [%s]\n%s', $task_definition_file );
937 0 ▶ $self->log_trace( sub { return Dumper( [ task_definition => $task_definition ] ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
938  
939 0 $task_definition_arn = $task_definition->{taskDefinition}->{taskDefinitionArn};
940  
941 0 ▶ log_die( $self, 'register: no taskDefinitionArn found? %s', Dumper( [ task_definition => $task_definition ] ) )
Branch: 1 branch
BranchTrueFalseTotal
unless $task_definition_arn 0 0 0
942 if !$task_definition_arn;
943  
944 0 $self->log_warn( 'register: registered...[%s]', $task_definition_arn );
945  
946 0 $tasks->{$task_name}->{arn} = $task_definition_arn;
947  
948 0 my $latest_image = $self->get_latest_image($task_name);
949  
950 0 $self->log_info( 'register: updating image digest: [%s]', $latest_image->{imageDigest} );
951 0 $tasks->{$task_name}->{image_digest} = $latest_image->{imageDigest};
952  
953 0 $self->update_config; # record new task definition arn
954 }
955 }
956  
957 ## - events -
958 0 ▶ if ( $tasks->{$task_name}->{type} eq 'task' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tasks->{$task_name}{"type"} eq "task") 0 0 0
959 0 require App::Events;
960  
961 0 my $event = $self->fetch_events;
962  
963 0 my $rule_name = sprintf '%s-schedule', $task_name;
964  
965 0 my $target = $event->list_targets_by_rule( $rule_name, 'Targets' );
966 0 $self->check_result( message => 'ERROR: could not list targets for: [%s]', $rule_name );
967  
968 0 ▶ if ( $target && @{$target} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target and @{$target;}) 0 0 0
Condition0%0/3
$target and @{$target;}
!ll&&!rl&&r
000
MC/DC0%0/2
$target and @{$target;}
$target @{$target;}
Truth table0%0/3
A and B
A= $targetB= @{$target;}
ABresult
0X0
100
111
969  
970 # we only need to update the config if we skipped
971 # registration...this is to allow for updating an event target
972 # with a new task definition manually
973 0 ▶ if ( !$dryrun && $self->get_skip_register ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $dryrun and $self->get_skip_register) 0 0 0
Condition0%0/3
not $dryrun and $self->get_skip_register
!ll&&!rl&&r
000
MC/DC0%0/2
not $dryrun and $self->get_skip_register
not $dryrun $self->get_skip_register
Truth table0%0/3
not(A) and B
A= not $dryrunB= $self->get_skip_register
ABresult
0X0
100
111
974 0 $config->{tasks}->{$task_name}->{arn} = $task_definition_arn;
975 0 $self->update_config;
976 }
977  
978 0 $self->create_event_target($task_name);
979 }
980 }
981  
982 0 return $SUCCESS;
983 }
984  
985 ########################################################################
986 0 ▶sub get_latest_image {
Subroutine get_latest_image: not called CC=1 SCAR=6.9
Pod undocumented
987 ########################################################################
988 0 my ( $self, $task_name ) = @_;
989  
990 0 my $tasks = $self->common_args('tasks');
991  
992 0 my $ecr = $self->fetch_ecr;
993  
994 0 my ($repo_name) = split /:/xsm, $tasks->{$task_name}->{image};
995  
996 0 my ($latest) = $ecr->get_latest_image($repo_name);
997  
998 0 return $latest;
999 }
1000  
1001 ########################################################################
1002 0 ▶sub cmd_explain {
Subroutine cmd_explain: not called CC=1 SCAR=6.9
Pod undocumented
1003 ########################################################################
1004 0 my ($self) = @_;
1005  
1006 0 my $config = $self->get_config;
1007  
1008 0 return $SUCCESS;
1009 }
1010  
1011 ########################################################################
1012 0 ▶sub cmd_version {
Subroutine cmd_version: not called CC=2 SCAR=17.9
Pod undocumented
1013 ########################################################################
1014  
1015 0 my $version_stmt = <<'END_OF_TEXT';
1016 %s %s
1017 Copyright 2025 (c) TBC Development Group, LLC.
1018  
1019 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
1020 This is free software: you are free to change and redistribute it.
1021 There is NO WARRANTY, to the extent permitted by law.
1022 END_OF_TEXT
1023  
1024 0 ▶ my $pgm = $ENV{SCRIPT_NAME} // $PROGRAM_NAME;
Condition0%0/3
$ENV{"SCRIPT_NAME"} // $App::FargateStack::PROGRAM_NAME
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{"SCRIPT_NAME"} // $App::FargateStack::PROGRAM_NAME
$ENV{"SCRIPT_NAME"} $App::FargateStack::PROGRAM_NAME
Truth table0%0/3
A // B
A= $ENV{"SCRIPT_NAME"}B= $App::FargateStack::PROGRAM_NAME
ABresult
1X1
011
000
1025  
1026 0 print {*STDOUT} sprintf $version_stmt, $pgm, $VERSION;
1027  
1028 0 return $SUCCESS;
1029 }
1030  
1031 ########################################################################
1032 0 ▶sub cmd_plan {
Subroutine cmd_plan: not called CC=1 SCAR=6.9
Pod undocumented
1033 ########################################################################
1034 0 my ( $self, @args ) = @_;
1035  
1036 0 $self->set_dryrun('(dryrun)');
1037  
1038 0 return $self->build(@args);
1039 }
1040  
1041 ########################################################################
1042 0 ▶sub cmd_apply {
Subroutine cmd_apply: not called CC=1 SCAR=6.9
Pod undocumented
1043 ########################################################################
1044 0 my ( $self, @args ) = @_;
1045  
1046 0 $self->set_dryrun($EMPTY);
1047  
1048 0 return $self->build(@args);
1049 }
1050  
1051 ########################################################################
1052 0 ▶sub cmd_update_target {
Subroutine cmd_update_target: not called CC=1 SCAR=6.9
Pod undocumented
1053 ########################################################################
1054 0 my ( $self, @args ) = @_;
1055  
1056 0 $self->set_skip_register($TRUE);
1057  
1058 0 return $self->cmd_register_task_definition(@args);
1059 }
1060  
1061 ########################################################################
1062 0 ▶sub cmd_stop_task {
Subroutine cmd_stop_task: not called CC=4 SCAR=30.0
Pod undocumented
1063 ########################################################################
1064 0 my ( $self, @args ) = @_;
1065  
1066 0 my ( $config, $tasks ) = $self->common_args(qw(config tasks));
1067  
1068 0 my ($task_id) = $self->get_args;
1069  
1070 0 my ($task_name) = $self->check_service_name( $task_id, $TRUE );
1071  
1072 0 ▶ if ($task_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($task_name) 0 0 0
1073 0 $task_id = $tasks->{$task_name}->{arn};
1074 }
1075  
1076 0 my $ecs = $self->get_ecs;
1077  
1078 die sprintf "usage: %s stop-task task-name|task-id|task-arn\n", $ENV{SCRIPT_NAME}
1079 0 ▶ if none { length $task_id == $_ } ( 32, 36 );
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &none(sub { length $task_id == $_; } , 32, 36) 0 0 0
1080  
1081 0 my $result = $ecs->stop_task( $config->{cluster}->{name}, $task_id );
1082  
1083 0 ▶ log_die( $self, "ERROR: could not stop task: [%s]\n%s", $task_id, $ecs->get_error )
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 0 0
1084 if !$result;
1085  
1086 0 return $SUCCESS;
1087 }
1088  
1089 ########################################################################
1090 0 ▶sub cmd_list_tasks {
Subroutine cmd_list_tasks: not called CC=10 SCAR=45.7
Pod undocumented
1091 ########################################################################
1092 0 my ( $self, @args ) = @_;
1093  
1094 0 my $config = $self->get_config;
1095  
1096 0 my ($desired_status) = map {uc} $self->get_args;
1097 0 ▶ $desired_status //= $EMPTY;
Condition0%0/3
$desired_status //= $App::FargateStack::EMPTY
l!l&&r!l&&!r
000
MC/DC0%0/2
$desired_status //= $App::FargateStack::EMPTY
$desired_status $App::FargateStack::EMPTY
Truth table0%0/3
A //= B
A= $desired_statusB= $App::FargateStack::EMPTY
ABresult
1X1
011
000
1098  
1099 0 my $cluster_name = $config->{cluster}->{name};
1100  
1101 0 my $ecs = $self->get_ecs;
1102  
1103 0 my $result = $ecs->list_tasks(
1104 { cluster_name => $cluster_name,
1105 query => 'taskArns',
1106 desired_status => $desired_status
1107 }
1108 );
1109 0 $ecs->check_result( message => 'ERROR: could not list tasks for cluster: [%s]', $cluster_name );
1110  
1111 0 ▶ if ( !@{$result} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$result;}) 0 0 0
1112 0 print {*STDERR} sprintf "No tasks currently running in cluster: [%s]\n", $cluster_name;
1113  
1114 0 return $SUCCESS;
1115 }
1116  
1117 0 my $task_list = [ map { basename $_ } @{$result} ];
1118  
1119 0 require Text::Wrap;
1120 0 Text::Wrap->import('wrap');
1121  
1122 {
1123 ## no critic
1124 0 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.2
1125 0 $Text::Wrap::columns = 100;
1126 }
1127  
1128 0 my @elems = qw(status task_definition_arn last_status started_at memory cpu attachments task_arn stopped_reason);
1129  
1130 0 my $query = jmespath_mapping 'tasks[]' => \@elems;
1131  
1132 0 $result = $ecs->describe_tasks( $cluster_name, $task_list, $query );
1133  
1134 0 ▶ croak sprintf "ERROR: could not list describe tasks: [%s]\n%s", $cluster_name, $ecs->get_error
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 0 0
1135 if !$result;
1136  
1137 0 my $title = sprintf 'Tasks (cluster: %s)', $cluster_name;
1138  
1139 0 my @data;
1140  
1141 0 foreach ( @{$result} ) {
1142 my ( $status, $last_status, $start_time, $memory, $cpu, $arn, $stopped_reason )
1143 0 = @{$_}{qw(status last_status started_at memory cpu task_arn stopped_reason)};
1144  
1145 0 ▶ $stopped_reason = wrap( q{}, q{}, $stopped_reason // q{} );
Condition0%0/2
$stopped_reason // ""
l!l
00
MC/DC0%0/1
$stopped_reason // ""
$stopped_reason
Truth table0%0/2
A
A= $stopped_reason
Aresult
11
00
1146  
1147 0 my $task_name = basename( $_->{task_definition_arn} );
1148 0 $task_name =~ s/:\d+$//;
1149  
1150 0 ▶ $status //= $last_status;
Condition0%0/3
$status //= $last_status
l!l&&r!l&&!r
000
MC/DC0%0/2
$status //= $last_status
$status $last_status
Truth table0%0/3
A //= B
A= $statusB= $last_status
ABresult
1X1
011
000
1151 0 ▶ $status = $self->maybe_color( $status =~ /running/xsmi ? 'green' : 'red' => $status );
Branch: 1 branch
BranchTrueFalseTotal
$status =~ /running/imsx ? : 0 0 0
1152  
1153 0 ▶ push @data,
Condition0%0/3
$status // $last_status
l!l&&r!l&&!r
000
MC/DC0%0/2
$status // $last_status
$status $last_status
Truth table0%0/3
A // B
A= $statusB= $last_status
ABresult
1X1
011
000
1154 {
1155 'Start Time' => $start_time,
1156 Status => $status // $last_status,
1157 Memory => $memory,
1158 CPU => $cpu,
1159 'Task Id' => basename($arn),
1160 'Task Name' => $task_name,
1161 'Elapsed Time' => elapsed_time($start_time),
1162 'Stopped Reason' => $stopped_reason,
1163 };
1164 }
1165  
1166 0 ▶ print {*STDOUT} easy_table(
Branch: 1 branch
BranchTrueFalseTotal
$desired_status ne 'STOPPED' ? : 0 0 0
1167 table_options => { headingText => $title, allowANSI => $TRUE },
1168 data => \@data,
1169 columns => [
1170 'Task Name', 'Task Id', 'Status', 'Memory', 'CPU',
1171 ( $desired_status ne 'STOPPED' ) ? ( 'Start Time', 'Elapsed Time' ) : ('Stopped Reason')
1172 ],
1173 );
1174  
1175 0 return $SUCCESS;
1176 }
1177  
1178 ########################################################################
1179 0 ▶sub cmd_enable_scheduled_task {
Subroutine cmd_enable_scheduled_task: not called CC=1 SCAR=6.9
Pod undocumented
1180 ########################################################################
1181 0 my ($self) = @_;
1182  
1183 0 return $self->update_rule_state($TRUE);
1184 }
1185  
1186 ########################################################################
1187 0 ▶sub cmd_disable_scheduled_task {
Subroutine cmd_disable_scheduled_task: not called CC=1 SCAR=6.9
Pod undocumented
1188 ########################################################################
1189 0 my ( $self, @args ) = @_;
1190  
1191 0 return $self->update_rule_state($FALSE);
1192 }
1193  
1194 ########################################################################
1195 0 ▶sub cmd_update_policy {
Subroutine cmd_update_policy: not called CC=1 SCAR=6.9
Pod undocumented
1196 ########################################################################
1197 0 my ( $self, @args ) = @_;
1198  
1199 0 $self->set_cache($FALSE);
1200  
1201 0 return $self->build(@args);
1202 }
1203  
1204 ########################################################################
1205 0 ▶sub cmd_destroy {
Subroutine cmd_destroy: not called CC=5 SCAR=34.0
Pod undocumented
1206 ########################################################################
1207 0 my ( $self, @args ) = @_;
1208  
1209 0 my $config = $self->get_config;
1210  
1211 0 ▶ $self->set_dryrun( $self->get_dryrun ? '(dryrun)' : $EMPTY );
Branch: 1 branch
BranchTrueFalseTotal
$self->get_dryrun ? : 0 0 0
1212  
1213 0 my %tasks = %{ $config->{tasks} };
1214  
1215 0 ▶ if ( !$self->get_force ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->get_force) 0 0 0
1216 0 my $warning = <<'END_OF_WARNING';
1217 ** WARNING **
1218  
1219 This command will remove ALL resources provisioned for the cluster: [%s]!
1220  
1221 Resources that were not provisioned by App::FargateStack will NOT be removed.
1222  
1223 END_OF_WARNING
1224 0 print {*STDOUT} sprintf $warning, $config->{cluster}->{name}, scalar %tasks;
1225  
1226 0 ▶ log_die( $self, 'Aborting...' )
Branch: 1 branch
BranchTrueFalseTotal
unless confirm("Are you sure you want to delete the entire stack?") 0 0 0
1227 if !confirm( sprintf 'Are you sure you want to delete the entire stack?' );
1228 }
1229  
1230 0 foreach my $task_name ( keys %tasks ) {
1231 0 $self->log_warn( 'destroy: deleting resources for: [%s]', $task_name );
1232 0 $self->delete_task_resources($task_name);
1233 }
1234  
1235 0 return $SUCCESS;
1236 }
1237  
1238 ########################################################################
1239 0 ▶sub cmd_ {
Subroutine cmd_: not called CC=1 SCAR=6.9
Pod undocumented
1240 ########################################################################
1241 0 my ( $self, @args ) = @_;
1242  
1243 0 print {*STDERR} "TBD\n";
1244  
1245 0 return $SUCCESS;
1246 }
1247  
1248 ########################################################################
1249 0 ▶sub cmd_tasks {
Subroutine cmd_tasks: not called CC=3 SCAR=24.8
Pod undocumented
1250 ########################################################################
1251 0 my ( $self, @args ) = @_;
1252  
1253 0 my $config = $self->get_config;
1254  
1255 0 my $tasks = $config->{tasks};
1256  
1257 0 my $roles = sprintf 'Execution Role: [%s] Task Role: [%s]', $config->{role}->{name}, $config->{task_role}->{name};
1258  
1259 0 my $title = <<'END_OF_TITLE';
1260 Stack Summary
1261  
1262 Cluster: [%s] VPC: [%s] Region: [%s] Tasks: [%s]
1263 %s
1264  
1265 END_OF_TITLE
1266 0 $title = sprintf $title, $config->{cluster}->{name}, $config->{vpc_id}, $config->{region}, scalar keys %{$tasks}, $roles;
1267  
1268 0 my @data;
1269  
1270 0 foreach my $task_name ( keys %{$tasks} ) {
1271 0 my $task = $tasks->{$task_name};
1272  
1273 0 ▶ my $environment = join "\n", map { sprintf '%s: %s', $_, $task->{environment}->{$_} } keys %{ $task->{environment} // {} };
Condition0%0/2
$task->{"environment"} // {}
l!l
00
MC/DC0%0/1
$task->{"environment"} // {}
$task->{"environment"}
Truth table0%0/2
A
A= $task->{"environment"}
Aresult
11
00
1274  
1275 0 push @data, { Task => $task_name, Type => $task->{type}, Size => $task->{size}, Environment => $environment };
1276 }
1277  
1278 0 print {*STDOUT} easy_table(
1279 table_options => { headingText => $title },
1280 data => \@data,
1281 columns => [qw(Task Type Size Environment)],
1282 );
1283  
1284 0 return $SUCCESS;
1285 }
1286  
1287 ########################################################################
1288 0 ▶sub cmd_delete_schedule {
Subroutine cmd_delete_schedule: not called CC=8 SCAR=42.8
Pod undocumented
1289 ########################################################################
1290 0 my ($self) = @_;
1291  
1292 0 my $tasks = $self->get_config->{tasks};
1293  
1294 0 my $task_name = $self->get_default_task_name( 'task', 'schedule' );
1295  
1296 die sprintf "usage: %s delete-schedule task-name\n", $ENV{SCRIPT_NAME}
1297 0 ▶ if !$task_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $task_name 0 0 0
1298  
1299 die sprintf "ERROR: %s is not a schedule task\n", $task_name
1300 0 ▶ if $tasks->{$task_name}->{type} ne 'task' || !$tasks->{$task_name}->{schedule};
Branch: 1 branch
BranchTrueFalseTotal
if $tasks->{$task_name}{"type"} ne "task" or not $tasks->{$task_name}{"schedule"} 0 0 0
Condition0%0/3
$tasks->{$task_name}{"type"} ne "task" or not $tasks->{$task_name}{"schedule"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tasks->{$task_name}{"type"} ne "task" or not $tasks->{$task_name}{"schedule"}
$tasks->{$task_name}{"type"} ne "task" not $tasks->{$task_name}{"schedule"}
Truth table0%0/3
A or not(B)
A= $tasks->{$task_name}{"type"} ne "task"B= not $tasks->{$task_name}{"schedule"}
ABresult
1X1
011
000
1301  
1302 # $task_name must be a schedule because we filtered above
1303 0 ▶ if ( !$self->get_force && scalar keys %{$tasks} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->get_force and scalar keys %{$tasks;} == 1) 0 0 0
Condition0%0/3
not $self->get_force and scalar keys %{$tasks;} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->get_force and scalar keys %{$tasks;} == 1
not $self->get_force scalar keys %{$tasks;} == 1
Truth table0%0/3
not(A) and B
A= not $self->get_forceB= scalar keys %{$tasks;} == 1
ABresult
0X0
100
111
1304  
1305 0 print {*STDERR} <<"END_OF_ERROR";
1306 This is the only task in your configuration.
1307  
1308 If you want to stop the task from running, consider:
1309 * Running: disable-scheduled-task $task_name
1310 (This leaves the task in place but disables the EventBridge rule.)
1311  
1312 If you're sure you want to delete this stack use the --force option.
1313  
1314 Deletion aborted to prevent unintended removal of the entire stack.
1315 END_OF_ERROR
1316 0 exit 1;
1317 }
1318  
1319 0 ▶ if ( !$self->get_force ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->get_force) 0 0 0
1320 0 ▶ log_die( $self, 'Aborting...' )
Branch: 1 branch
BranchTrueFalseTotal
unless confirm(sprintf('Are you sure you want to delete the %s scheduled task', $task_name)) 0 0 0
1321 if !confirm( sprintf 'Are you sure you want to delete the %s scheduled task', $task_name );
1322 }
1323  
1324 0 return $self->delete_task_resources($task_name);
1325 }
1326  
1327 ########################################################################
1328 0 ▶sub cmd_delete_task {
Subroutine cmd_delete_task: not called CC=6 SCAR=37.4
Pod undocumented
1329 ########################################################################
1330 0 my ($self) = @_;
1331  
1332 0 my $tasks = $self->get_config->{tasks};
1333  
1334 0 my $task_name = $self->get_default_task_name('task');
1335  
1336 die sprintf "usage: %s delete-task task-name\n", $ENV{SCRIPT_NAME}
1337 0 ▶ if !$task_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $task_name 0 0 0
1338  
1339 die sprintf "ERROR: [%s] is a not a task\n", $task_name
1340 0 ▶ if $tasks->{$task_name}->{type} ne 'task';
Branch: 1 branch
BranchTrueFalseTotal
if $tasks->{$task_name}{"type"} ne "task" 0 0 0
1341  
1342 die sprintf "ERROR: [%s] is a scheduled task...use 'delete-schedule'\n", $task_name
1343 0 ▶ if $tasks->{$task_name}->{schedule};
Branch: 1 branch
BranchTrueFalseTotal
if $tasks->{$task_name}{"schedule"} 0 0 0
1344  
1345 0 ▶ if ( !$self->get_force && scalar keys %{$tasks} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->get_force and scalar keys %{$tasks;} == 1) 0 0 0
Condition0%0/3
not $self->get_force and scalar keys %{$tasks;} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->get_force and scalar keys %{$tasks;} == 1
not $self->get_force scalar keys %{$tasks;} == 1
Truth table0%0/3
not(A) and B
A= not $self->get_forceB= scalar keys %{$tasks;} == 1
ABresult
0X0
100
111
1346 0 print {*STDERR} <<"END_OF_ERROR";
1347 This is the only task in your configuration.
1348  
1349 If you're finished with this task and want to remove all artifacts,
1350 you can run:
1351 * destroy
1352  
1353 Deletion aborted to prevent unintended removal of the entire stack.
1354 END_OF_ERROR
1355 0 exit 1;
1356 }
1357  
1358 0 return $self->delete_task_resources($task_name);
1359 }
1360  
1361 ########################################################################
1362 0 ▶sub cmd_delete_daemon {
Subroutine cmd_delete_daemon: not called CC=4 SCAR=30.0
Pod undocumented
1363 ########################################################################
1364 0 my ($self) = @_;
1365  
1366 0 my $tasks = $self->get_config->{tasks};
1367 0 my $task_name = $self->get_default_task_name( 'task', 'daemon' );
1368  
1369 0 ▶ die "usage: $ENV{SCRIPT_NAME} delete-daemon task-name\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $task_name 0 0 0
1370 if !$task_name;
1371  
1372 die sprintf "ERROR: [%s] is not a daemon\n", $task_name
1373 0 ▶ if $tasks->{$task_name}->{type} ne 'daemon';
Branch: 1 branch
BranchTrueFalseTotal
if $tasks->{$task_name}{"type"} ne "daemon" 0 0 0
1374  
1375 0 ▶ if ( scalar keys %{$tasks} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$tasks;} == 1) 0 0 0
1376 0 my $msg = <<'END_OF_ERROR';
1377 This is the only task in your configuration.
1378  
1379 You can stop the daemon from running with the "stop-service" command.
1380 END_OF_ERROR
1381 0 print {*STDERR} colored( $msg, 'bright_red' );
1382 }
1383  
1384 0 return $self->delete_task_resources($task_name);
1385 }
1386  
1387 ########################################################################
1388 0 ▶sub cmd_delete_http_service {
Subroutine cmd_delete_http_service: not called CC=5 SCAR=34.0
Pod undocumented
1389 ########################################################################
1390 0 my ($self) = @_;
1391  
1392 0 my $tasks = $self->get_config->{tasks};
1393  
1394 0 my ( $task_name, $err ) = $self->get_default_service_name();
1395  
1396 0 ▶ die "usage: $ENV{SCRIPT_NAME} delete-http task-name\n"
Branch: 1 branch
BranchTrueFalseTotal
if not $task_name or $err 0 0 0
Condition0%0/3
not $task_name or $err
l!l&&r!l&&!r
000
MC/DC0%0/2
not $task_name or $err
not $task_name $err
Truth table0%0/3
not(A) or B
A= not $task_nameB= $err
ABresult
1X1
011
000
1397 if !$task_name || $err;
1398  
1399 die "ERROR: [$task_name] is not an http task"
1400 0 ▶ if !$tasks->{$task_name}->{type} =~ /^https?/xsm;
Branch: 1 branch
BranchTrueFalseTotal
if !$tasks->{$task_name}{"type"} =~ /^https?/msx 0 0 0
1401  
1402 0 ▶ if ( scalar keys %{$tasks} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$tasks;} == 1) 0 0 0
1403 0 my $msg = <<'END_OF_WARNING';
1404 WARNING: This is the only task in your configuration.
1405  
1406 - You can stop the http service from running with the "stop-service" command.
1407 - You can delete only the service with the "delete-service" command.
1408  
1409 END_OF_WARNING
1410 0 print {*STDERR} colored( $msg, 'bright_red' );
1411 }
1412  
1413 0 return $self->delete_task_resources($task_name);
1414 }
1415  
1416 ########################################################################
1417 0 ▶sub cmd_redeploy {
Subroutine cmd_redeploy: not called CC=4 SCAR=30.0
Pod undocumented
1418 ########################################################################
1419 0 my ( $self, @args ) = @_;
1420  
1421 0 my $cluster = $self->common_args('cluster');
1422 0 my $cluster_name = $cluster->{name};
1423  
1424 0 my ( $service_name, $err ) = $self->get_default_service_name;
1425  
1426 die sprintf "usage: %s redeploy service-name\n", $ENV{SCRIPT_NAME}
1427 0 ▶ if !$service_name || $err;
Branch: 1 branch
BranchTrueFalseTotal
if not $service_name or $err 0 0 0
Condition0%0/3
not $service_name or $err
l!l&&r!l&&!r
000
MC/DC0%0/2
not $service_name or $err
not $service_name $err
Truth table0%0/3
not(A) or B
A= not $service_nameB= $err
ABresult
1X1
011
000
1428  
1429 0 my $ecs = $self->get_ecs;
1430  
1431 0 my $result = $ecs->update_service(
1432 cluster_name => $cluster_name,
1433 service_name => $service_name,
1434 force => $TRUE
1435 );
1436  
1437 0 ▶ log_die( $self, "ERROR: could not update service: [%s]\n%s", $service_name, $ecs->get_error )
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 0 0
1438 if !$result;
1439  
1440 0 $self->log_info( 'redeploy: successfully updated service: [%s]', $service_name );
1441  
1442 0 return $SUCCESS;
1443 }
1444  
1445 ########################################################################
1446 0 ▶sub cmd_reset_history {
Subroutine cmd_reset_history: not called CC=1 SCAR=6.9
Pod undocumented
1447 ########################################################################
1448 0 my ( $self, @args ) = @_;
1449  
1450 0 $self->fetch_option_defaults($TRUE);
1451  
1452 0 return $SUCCESS;
1453 }
1454  
1455 ########################################################################
1456 0 ▶sub fetch_option_defaults {
Subroutine fetch_option_defaults: not called CC=7 SCAR=40.3
Pod undocumented
1457 ########################################################################
1458 0 my ( $self, $reset ) = @_;
1459  
1460 0 my $options = {};
1461  
1462 0 my $defaults_file = '.fargatestack/defaults.json';
1463  
1464 0 ▶ if ( -s $defaults_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-s $defaults_file) { } 0 0 0
1465 0 $options = slurp_file( $defaults_file, $TRUE );
1466 }
1467 else {
1468 0 mkdir '.fargatestack';
1469 }
1470  
1471 0 ▶ return $self->write_json_file( $defaults_file, {} )
Branch: 1 branch
BranchTrueFalseTotal
if $reset 0 0 0
1472 if $reset;
1473  
1474 0 ▶ $options->{profile} = $self->get_profile // $options->{profile};
Condition0%0/3
$self->get_profile // $options->{"profile"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_profile // $options->{"profile"}
$self->get_profile $options->{"profile"}
Truth table0%0/3
A // B
A= $self->get_profileB= $options->{"profile"}
ABresult
1X1
011
000
1475 0 ▶ $options->{config} = $self->get_config_name // $options->{config};
Condition0%0/3
$self->get_config_name // $options->{"config"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_config_name // $options->{"config"}
$self->get_config_name $options->{"config"}
Truth table0%0/3
A // B
A= $self->get_config_nameB= $options->{"config"}
ABresult
1X1
011
000
1476 0 $options->{region} = $self->default_region( $options->{region} );
1477 0 ▶ $options->{route53_profile} = $self->get_route53_profile // $options->{route53_profile};
Condition0%0/3
$self->get_route53_profile // $options->{"route53_profile"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_route53_profile // $options->{"route53_profile"}
$self->get_route53_profile $options->{"route53_profile"}
Truth table0%0/3
A // B
A= $self->get_route53_profileB= $options->{"route53_profile"}
ABresult
1X1
011
000
1478 0 ▶ $options->{max_events} = $self->get_max_events // $options->{max_events};
Condition0%0/3
$self->get_max_events // $options->{"max_events"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_max_events // $options->{"max_events"}
$self->get_max_events $options->{"max_events"}
Truth table0%0/3
A // B
A= $self->get_max_eventsB= $options->{"max_events"}
ABresult
1X1
011
000
1479  
1480 0 $self->set_profile( $options->{profile} );
1481 0 $self->set_config_name( $options->{config} );
1482 0 $self->set_route53_profile( $options->{route53_profile} );
1483 0 $self->set_max_events( $options->{max_events} );
1484  
1485 0 $self->write_json_file( $defaults_file, $options );
1486  
1487 0 return $options;
1488 }
1489  
1490 ########################################################################
1491 0 ▶sub build_section_paths {
Subroutine build_section_paths: not called CC=3 SCAR=24.8
Pod undocumented
1492 ########################################################################
1493 0 my @items = @_; # list of strings like '1:Title'
1494  
1495 0 my %paths;
1496 my @stack;
1497  
1498 0 foreach my $line (@items) {
1499 0 ▶ next if $line !~ /^(\d+):(.*)$/xsm;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /^(\d+):(.*)$/msx 0 0 0
1500  
1501 0 my ( $level, $title ) = ( $1, $2 );
1502 0 $level = int $level; # Normalize level
1503  
1504 # Adjust the stack to this level
1505 0 $#stack = $level - 2; # level 1 means index 0, so -2 to truncate above
1506 0 $stack[ $level - 1 ] = $title;
1507  
1508 # Join the stack up to this level
1509 0 my $path = join '/', @stack[ 0 .. $level - 1 ];
1510 0 $paths{$title} = $path;
1511 }
1512  
1513 0 return %paths;
1514 }
1515  
1516 ########################################################################
1517 0 ▶sub parse_pod_sections {
Subroutine parse_pod_sections: not called CC=2 SCAR=17.9
Pod undocumented
1518 ########################################################################
1519 0 my $pod = slurp_file( $INC{'App/FargateStack/Pod.pm'} );
1520 0 my @sections;
1521  
1522 0 ▶ while ( $pod =~ /=head(\d+)\s+(.*?)$/gxsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pod =~ /=head(\d+)\s+(.*?)$/gmsx) 0 0 0
1523 0 push @sections, "$1:$2";
1524 }
1525  
1526 0 return build_section_paths(@sections);
1527 }
1528  
1529 ########################################################################
1530 0 ▶sub help {
Subroutine help: not called CC=21 SCAR=61.4
Pod documented
1531 ########################################################################
1532 0 my ($self) = @_;
1533  
1534 0 my $subject = lc join $SPACE, @ARGV;
1535 0 $subject =~ s/\s+$//xsm;
1536  
1537 0 my %pod_sections = parse_pod_sections();
1538 0 my $section;
1539  
1540 0 ▶ if ( $subject && $subject ne 'help' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subject and $subject ne "help") 0 0 0
Condition0%0/3
$subject and $subject ne "help"
!ll&&!rl&&r
000
MC/DC0%0/2
$subject and $subject ne "help"
$subject $subject ne "help"
Truth table0%0/3
A and B
A= $subjectB= $subject ne "help"
ABresult
0X0
100
111
1541 0 my ( $pod_section, $err ) = grep {/^$subject/smi} keys %pod_sections;
1542  
1543 0 ▶ if ($pod_section) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pod_section) 0 0 0
1544 0 $section = $pod_sections{$pod_section};
1545 0 $section =~ s/[?]/\\?/gxsm;
1546 }
1547 }
1548  
1549 0 ▶ if ( !$section ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($section) 0 0 0
1550 0 ▶ $section = $HELP_SUBJECTS{$subject} // $EMPTY;
Condition0%0/3
$App::FargateStack::HELP_SUBJECTS{$subject} // $App::FargateStack::EMPTY
l!l&&r!l&&!r
000
MC/DC0%0/2
$App::FargateStack::HELP_SUBJECTS{$subject} // $App::FargateStack::EMPTY
$App::FargateStack::HELP_SUBJECTS{$subject} $App::FargateStack::EMPTY
Truth table0%0/3
A // B
A= $App::FargateStack::HELP_SUBJECTS{$subject}B= $App::FargateStack::EMPTY
ABresult
1X1
011
000
1551  
1552 0 ▶ if ( $subject && !$section && $subject ne 'help' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subject and not $section and $subject ne "help") 0 0 0
Condition0%0/6
$subject and not $section and $subject ne "help"
!ll&&!rl&&r
000
$subject and not $section
!ll&&!rl&&r
000
MC/DC0%0/3
$subject and not $section and $subject ne "help"
$subject not $section $subject ne "help"
Truth table0%0/4
A and not(B) and C
A= $subjectB= not $sectionC= $subject ne "help"
ABCresult
0XX0
10X0
1100
1111
1553 0 my @possible_subjects = grep {/$subject/xsmi} keys %HELP_SUBJECTS;
1554  
1555 0 ▶ if ( @possible_subjects == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@possible_subjects == 1) { } 0 0 0
elsif (@possible_subjects) { } 0 0 0
1556 0 $section = $HELP_SUBJECTS{ $possible_subjects[0] };
1557 }
1558 elsif (@possible_subjects) {
1559 0 print {*STDERR} sprintf "'%s' was not found in the help index.\n\nPossible matches:\n\t* %s\n",
1560 $subject,
1561 join "\n\t* ",
1562 @possible_subjects;
1563 0 exit 1;
1564 }
1565 }
1566  
1567 0 ▶ if ( $section && ref $section ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($section and ref $section) { } 0 0 0
elsif ($section) { } 0 0 0
Condition0%0/3
$section and ref $section
!ll&&!rl&&r
000
MC/DC0%0/2
$section and ref $section
$section ref $section
Truth table0%0/3
A and B
A= $sectionB= ref $section
ABresult
0X0
100
111
1568 0 $section = uc $section->[0];
1569 }
1570 elsif ($section) { # a help subject alias
1571 0 my $reference = $HELP_SUBJECTS{$section};
1572 0 $section = uc $reference->[0];
1573 }
1574 }
1575  
1576 0 eval {
1577 0 require IO::Pager;
1578 0 IO::Pager::open( *STDOUT, '|-:utf8', 'Unbuffered' );
1579 };
1580  
1581 0 ▶ if ( $subject && !$section ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subject and not $section) 0 0 0
Condition0%0/3
$subject and not $section
!ll&&!rl&&r
000
MC/DC0%0/2
$subject and not $section
$subject not $section
Truth table0%0/3
A and not(B)
A= $subjectB= not $section
ABresult
0X0
100
111
1582 0 ▶ if ( $subject ne 'help' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subject ne "help") 0 0 0
1583 0 print {*STDERR} sprintf "'%s' is not a valid subject\n", $subject;
1584 }
1585  
1586 0 my @data;
1587  
1588 0 foreach my $keyword ( sort keys %HELP_SUBJECTS ) {
1589 0 my $description = $HELP_SUBJECTS{$keyword};
1590 0 ▶ if ( ref $description ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $description) 0 0 0
1591 0 $description = $description->[1];
1592 }
1593 0 push @data, { Keyword => $keyword, Description => $description };
1594 }
1595  
1596 0 my $table = easy_table(
1597 columns => [qw(Keyword Description)],
1598 data => \@data,
1599 table_options => { headingText => 'Help Subjects' },
1600 );
1601  
1602 0 print {*STDOUT} $table;
1603  
1604 0 exit $SUCCESS;
1605 }
1606  
1607 return pod2usage(
1608 0 ▶ -input => $INC{'App/FargateStack/Pod.pm'},
Branch: 1 branch
BranchTrueFalseTotal
$section ? : 0 0 0
Condition0%0/2
$section // "USAGE"
l!l
00
MC/DC0%0/1
$section // "USAGE"
$section
Truth table0%0/2
A
A= $section
Aresult
11
00
1609 -exitval => 1,
1610 -verbose => 99,
1611 -width => 80,
1612 $section ? ( -sections => $section // 'USAGE' ) : ()
1613 );
1614 }
1615  
1616 ########################################################################
1617 0 ▶sub main {
Subroutine main: not called CC=1 SCAR=6.9
Pod documented
1618 ########################################################################
1619  
1620 0 my @extra_options = qw(
1621 account
1622 alb
1623 config_name
1624 cloudtrail
1625 ec2
1626 ecs
1627 ecr
1628 efs
1629 elbv2
1630 events
1631 existing_resources
1632 http
1633 iam
1634 global_options
1635 logs
1636 log_groups
1637 logger
1638 profile_source
1639 required_resources
1640 route53
1641 sts
1642 secrets
1643 subnets
1644 taskdef_status
1645 );
1646  
1647 0 my @option_specs = qw(
1648 help|h
1649 config|c=s
1650 color!
1651 confirm-all!
1652 create-alb|C
1653 dryrun|d
1654 force|f
1655 history|H!
1656 log-level=s
1657 log-time!
1658 log-wait!
1659 log-poll-time=s
1660 max-events|m=i
1661 output=s
1662 profile|p=s
1663 purge_config
1664 region|r=s
1665 route53-profile|R=s
1666 skip-register|s
1667 subnet-id=s
1668 task-timeout|t
1669 update|u!
1670 unlink|U!
1671 cache!
1672 version|v
1673 wait|w!
1674 );
1675  
1676 0 my %default_options = (
1677 wait => $TRUE,
1678 unlink => $TRUE,
1679 color => $TRUE,
1680 cache => $TRUE,
1681 'log-time' => $TRUE,
1682 'log-wait' => $TRUE,
1683 'log-poll-time' => $DEFAULT_LOG_POLL_TIME,
1684 'task-timeout' => $DEFAULT_ECS_POLL_LIMIT,
1685 history => $TRUE,
1686 update => $TRUE,
1687 'max-events' => $DEFAULT_MAX_EVENTS,
1688 output => 'text',
1689 );
1690  
1691 0 my %commands = (
1692 'add-scaling-policy' => [ \&cmd_add_scaling_policy, 'error', { skip_init => $TRUE, skip_config => $FALSE } ],
1693 'add-scheduled-action' => [ \&cmd_add_scheduled_action, 'error', { skip_init => $TRUE, skip_config => $FALSE } ],
1694 'create-stack' => [ \&cmd_create_stack, 'error', { skip_init => $TRUE, skip_config => $TRUE } ],
1695 'delete-daemon' => \&cmd_delete_daemon,
1696 'delete-http-service' => \&cmd_delete_http_service,
1697 'delete-scaling-policy' => [ \&cmd_delete_autoscaling_policy, 'error', { skip_init => $TRUE, skip_config => $FALSE } ],
1698 'delete-schedule' => \&cmd_delete_schedule,
1699 'delete-scheduled-action' => [ \&cmd_delete_scheduled_action, 'error', { skip_init => $TRUE, skip_config => $FALSE } ],
1700 'delete-service' => [ \&cmd_remove_service, 'info' ],
1701 'delete-task' => \&cmd_delete_task,
1702 'deploy-service' => [ \&cmd_deploy_service, 'info' ],
1703 'disable-scheduled-task' => \&cmd_disable_scheduled_task,
1704 'enable-scheduled-task' => \&cmd_enable_scheduled_task,
1705 'list-tasks' => [ \&cmd_list_tasks, 'error' ],
1706 'list-zones' => [ \&cmd_list_zones, 'error' ],
1707 'register-task' => \&cmd_register_task_definition,
1708 'remove-service' => [ \&cmd_remove_service, 'info' ],
1709 'reset-history' => [ \&cmd_reset_history, 'info', { skip_init => $TRUE, skip_config => $TRUE } ],
1710 'run-task' => \&cmd_run_task,
1711 'start-service' => [ \&cmd_start_stop_service, 'info' ],
1712 'stop-service' => [ \&cmd_start_stop_service, 'error' ],
1713 'stop-task' => [ \&cmd_stop_task, 'error' ],
1714 'update-policy' => \&cmd_update_policy,
1715 'update-service' => [ \&cmd_update_service, 'error', { skip_init => $TRUE } ],
1716 'update-target' => \&cmd_update_target,
1717 apply => \&cmd_apply,
1718 default => [ \&cmd_explain, 'error' ],
1719 destroy => [ \&cmd_destroy, 'error', { skip_init => $TRUE, skip_config => $FALSE } ],
1720 help => [ \&help, 'error', { skip_init => $TRUE, skip_config => $TRUE } ],
1721 logs => [ \&cmd_logs, 'error' ],
1722 plan => \&cmd_plan,
1723 redeploy => \&cmd_redeploy,
1724 show => [ \&cmd_show, 'error', { skip_init => $TRUE, skip_config => $TRUE } ],
1725 state => [ \&cmd_state, 'error', { skip_init => $TRUE, skip_config => $TRUE } ],
1726 status => [ \&cmd_service_status, 'error' ],
1727 tasks => [ \&cmd_tasks, 'error', { skip_init => $TRUE, skip_config => $FALSE } ],
1728 version => [ \&cmd_version, 'error', { skip_init => $TRUE, skip_config => $TRUE } ],
1729 );
1730  
1731 my $fargate_stack = App::FargateStack->new(
1732 commands => \%commands,
1733 default_options => \%default_options,
1734 extra_options => \@extra_options,
1735 option_specs => \@option_specs,
1736 abbreviations => $TRUE,
1737 0 ▶ error_handler => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1738 0 print {*STDERR} shift;
1739 0 return $FALSE;
1740 },
1741 0 alias => {
1742 options => { 'dns-profile' => 'route53-profile' },
1743 commands => {
1744 'create-service' => 'deploy-service',
1745 'delete-autoscaling-policy' => 'delete-scaling-policy',
1746 },
1747 },
1748 );
1749  
1750 0 $fargate_stack->run();
1751  
1752 0 return 0;
1753 }
1754  
1755 1 1;
1756  
1757 __END__
« FargateStack/Builder/Autoscaling.pm ↑ Summary FargateStack/Builder/TaskDefinition.pm »