-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRakefile
165 lines (126 loc) · 5.3 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
require './lib/cluster'
require 'colorize'
Dir['./lib/tasks/*.rake'].each { |file| load file }
namespace :admin do
namespace :cluster do
desc Cluster::RakeDocs.new('admin:cluster:init').desc
task init: ['cluster:configtest', 'cluster:config_sync_check'] do
vpc = Cluster::VPC.find_or_create
Cluster::VPC.init_peering
Cluster::SubscribesSnsEndpoints.subscribe
rds_create = Concurrent::Future.execute do
Cluster::RDS.find_or_create
end
stack = Cluster::Stack.find_or_create
puts %Q|Stack "#{stack.name}" initialized, id: #{stack.stack_id}|
layers = Cluster::Layers.find_or_create
Cluster::Instances.find_or_create
Cluster::S3DistributionBucket.find_or_create(Cluster::Base.distribution_bucket_name)
Cluster::S3ArchiveBucket.find_or_create(Cluster::Base.s3_file_archive_bucket_name)
Cluster::S3ColdArchiveBucket.find_or_create(Cluster::Base.s3_cold_archive_bucket_name)
layers.each do |layer|
puts %Q|Layer: "#{layer.name}" => #{layer.layer_id}|
Cluster::Instances.find_in_layer(layer).each do |instance|
puts %Q| Instance: #{instance.hostname} => status: #{instance.status}, ec2_instance_id: #{instance.ec2_instance_id}|
end
end
begin
rds_create.value!
rescue => e
puts "Something went wrong creating rds cluster: #{rds_create.reason}"
puts e.backtrace
end
Cluster::RegistersRDSInstance.register
Cluster::App.find_or_create
# update the stack config so it gets the RDS cluster endpoint
Cluster::Stack.update
puts
puts %Q|Initializing the cluster does not start instances. To start them, use "./bin/rake stack:instances:start"|
puts
puts %Q|Initializing the cluster starts your RDS cluster! Please run 'rds:stop' if you're not starting the opsworks cluster right away!|.yellow
end
desc Cluster::RakeDocs.new('admin:cluster:delete').desc
task delete: ['cluster:configtest', 'cluster:config_sync_check', 'cluster:production_failsafe'] do
puts 'deleting app'
Cluster::App.delete
puts 'deleting sns topic and subscriptions'
Cluster::SNS.delete
rds_delete = Concurrent::Future.execute do
puts 'deleting RDS cluster'
# RDS Clusters won't delete when in a stopped state! :(
existing_rds = Cluster::RDS.find_existing
if existing_rds
Cluster::RDS.start
end
Cluster::RDS.delete
end
puts 'deleting instances'
Cluster::Instances.delete
puts 'deleting stack'
Cluster::Stack.delete
puts 'deleting instance profile'
Cluster::InstanceProfile.delete
puts 'deleting service role'
Cluster::ServiceRole.delete
puts 'skip deleting S3 distribution, file archive, and cold archive buckets and assets'
# puts 'deleting S3 distribution, file archive, and cold archive buckets and assets'
# Cluster::S3DistributionBucket.delete(Cluster::Base.distribution_bucket_name)
# Cluster::S3ArchiveBucket.delete(Cluster::Base.s3_file_archive_bucket_name)
# Cluster::S3ColdArchiveBucket.delete(Cluster::Base.s3_cold_archive_bucket_name)
puts 'deleting analytics buckets'
Cluster::S3AnalyticsBuckets.delete
puts 'deleting SQS queues'
Cluster::SQS.delete_queue(Cluster::Base.useractions_queue_name)
puts 'deleting CloudWatch log groups'
Cluster::Layers.delete_log_groups
begin
rds_delete.value!
rescue => e
puts "Something went wrong deleting the rds cluster: #{rds_delete.reason}"
# reraise the exception to stop execution of the delete
# (not sure this is better than continuing, but seems less likely to result
# in orphaned rds resources if the vpc and cluster config hang around too)
raise
end
puts 'deleting VPC'
Cluster::VPC.delete
puts 'deleting configuration files'
Cluster::RemoteConfig.new.delete
end
desc Cluster::RakeDocs.new('admin:cluster:subscribe').desc
task subscribe: ['cluster:configtest', 'cluster:config_sync_check'] do
Cluster::SubscribesSnsEndpoints.subscribe
end
end
namespace :users do
desc Cluster::RakeDocs.new('admin:users:list').desc
task list: ['cluster:configtest', 'cluster:config_sync_check'] do
Cluster::IAMUser.all.each do |user|
puts %Q|#{user.user_name} => #{user.arn}|
end
end
end
desc Cluster::RakeDocs.new('admin:republish_maven_cache').desc
task republish_maven_cache: ['cluster:configtest', 'cluster:config_sync_check'] do
asset_bucket_name = Cluster::Base.shared_asset_bucket_name
a_public_host = Cluster::Instances.online.find do |instance|
(instance.public_dns != nil) && instance.hostname.match(/admin/)
end
system %Q|ssh -C #{a_public_host.public_dns} 'sudo bash -c "cd /root && tar cvfz - .m2/"' > oc_maven_cache.tgz|
puts %Q|Uploading oc_maven_cache.tgz to #{asset_bucket_name}|
Cluster::Assets.publish_support_asset_to(
bucket: asset_bucket_name,
file_name: 'oc_maven_cache.tgz',
permissions: 'public'
)
puts 'done.'
File.unlink('oc_maven_cache.tgz')
end
end
task :default do
Rake.application.tasks.each do |task|
puts "./bin/rake #{task.name}"
end
puts
puts 'Run "./bin/rake -T" for full task output'
end