58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/hashicorptools/code_deploy.rb', line 58
def deploy
g = Git.open('..')
aws_regions = options[:aws_regions] || default_regions
commit = if options[:commit].present?
g.gcommit(options[:commit])
else
branch = options[:branch].nil? ? :main : options[:branch].to_sym
g.checkout(branch)
g.log.first
end
puts "Deploying to environment #{options[:environment]} - regions: #{aws_regions.join(', ')}
commit: #{commit.sha}
message: #{commit.message}"
puts "Deploying for regions: #{aws_regions}"
all_succeeded = true
aws_regions.each_slice(2) do |aws_regions_batch|
puts "Deploying for batch of regions: #{aws_regions_batch}"
threads = []
aws_regions_batch.each do |aws_region|
thread = Thread.new{ region_deployment(aws_region).create_deployment(commit.sha, commit.message) }
threads.push(thread)
end
threads.each_with_index do |thread, index|
begin
thread_succeeded = thread.value
all_succeeded = all_succeeded && thread_succeeded
rescue StandardError => e
puts "[#{aws_regions[index]}] EXCEPTION: #{e}"
all_succeeded = false
end
end
end
exit(all_succeeded)
end
|