Module: ShootsDeploy
- Defined in:
- lib/shoots_deploy.rb,
lib/shoots_deploy/version.rb
Defined Under Namespace
Classes: Bucket, Configuration, HostedZone
Constant Summary
collapse
- VERSION =
"0.9.1"
Class Method Summary
collapse
Class Method Details
.create_configure_populate_main_bucket(configuration, directory: Dir.pwd) ⇒ Object
86
87
88
89
90
91
|
# File 'lib/shoots_deploy.rb', line 86
def self.create_configure_populate_main_bucket(configuration, directory: Dir.pwd)
main_bucket = Bucket.initialize_with_name(configuration.main_bucket_name)
main_bucket.upload_files_from(directory)
main_bucket.configure_policy
main_bucket.configure_to_serve_website
end
|
.deploy ⇒ Object
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
|
# File 'lib/shoots_deploy.rb', line 7
def self.deploy
if deployed_before?
configuration = Configuration.initialize_from_file
initialize_aws(region: configuration.region, secret_key: configuration.secret_key, access_key: configuration.access_key)
bucket = Bucket.new(configuration.main_bucket_name)
bucket.sync_site_with(Dir.pwd)
else
access_key = get_access_key
secret_key = get_secret_key
region = select_region
configuration = Configuration.new(region: region, access_key: access_key, secret_key: secret_key)
initialize_aws(region: configuration.region, secret_key: configuration.secret_key, access_key: configuration.access_key)
if use_custom_domain? && use_route_53?
configuration.root_domain = get_root_domain
configuration.subdomain = get_subdomain
hosted_zone = HostedZone.new(configuration)
if use_root_domain_with_route_53?(configuration) configuration.main_bucket_name = configuration.root_domain
configuration.secondary_bucket_name = configuration.subdomain + '.' +configuration.root_domain
configuration.subdomain_url = configuration.secondary_bucket_name
create_configure_populate_main_bucket(configuration)
secondary_bucket = Bucket.initialize_with_name(configuration.secondary_bucket_name)
secondary_bucket.configuration = configuration
secondary_bucket.redirect_traffic
hosted_zone.configure_alias_record
hosted_zone.configure_cname_record
else configuration.main_bucket_name = configuration.subdomain + '.' + configuration.root_domain
configuration.subdomain_url = configuration.main_bucket_name
create_configure_populate_main_bucket(configuration)
hosted_zone.configure_cname_record
end
puts "\nSet up your domain to use the Amazon Route 53 as your DNS by changing to the following nameservers:"
puts hosted_zone.ns_resource_records
notify_user_of_temporary_s3_url(configuration)
elsif use_custom_domain? configuration.subdomain_url = configuration.main_bucket_name = get_url
create_configure_populate_main_bucket(configuration)
puts "\nSet up your DNS with the corresponding CNAME and point it to `#{configuration.s3_website_endpoint}`.\nIf you want your root domain to be redirected to this website, set up the necessary redirection rules."
notify_user_of_temporary_s3_url(configuration)
else configuration.main_bucket_name = get_site_name
create_configure_populate_main_bucket(configuration)
puts "\nYou can see your website at #{configuration.s3_website_endpoint}"
end
configuration.create_config_file
end
end
|
.deployed_before? ⇒ Boolean
78
79
80
|
# File 'lib/shoots_deploy.rb', line 78
def self.deployed_before?
File.exist?(Dir.pwd + '/' + Configuration::CONFIG_FILE)
end
|
.get_access_key ⇒ Object
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/shoots_deploy.rb', line 106
def self.get_access_key
access_key = ''
while access_key.empty?
print "\nWhat's your AWS access key? "
access_key = gets.chomp
end
access_key
end
|
.get_root_domain ⇒ Object
143
144
145
146
147
|
# File 'lib/shoots_deploy.rb', line 143
def self.get_root_domain
prompt = "What is your root domain? eg. example.com"
confirmation_message = "You root domain is"
get_user_input_with_prompt(prompt, confirmation_message: confirmation_message)
end
|
.get_secret_key ⇒ Object
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/shoots_deploy.rb', line 117
def self.get_secret_key
secret_key = ''
while secret_key.empty?
print "\nWhat's your AWS secret key? "
secret_key = gets.chomp
end
secret_key
end
|
.get_site_name ⇒ Object
161
162
163
164
165
|
# File 'lib/shoots_deploy.rb', line 161
def self.get_site_name
prompt = "What is the name of your site? (something unique to prevent S3 bucket name clashing)"
confirmation_message = "Your site name is"
get_user_input_with_prompt(prompt, confirmation_message: confirmation_message)
end
|
.get_subdomain ⇒ Object
149
150
151
152
153
|
# File 'lib/shoots_deploy.rb', line 149
def self.get_subdomain
prompt = "What is your preferred subdomain? eg. www or hello"
confirmation_message = "Your preferred subdomain is"
get_user_input_with_prompt(prompt, confirmation_message: confirmation_message)
end
|
.get_url ⇒ Object
155
156
157
158
159
|
# File 'lib/shoots_deploy.rb', line 155
def self.get_url
prompt = "What will your website URL be? eg. www.example.com"
confirmation_message = "Your website's url will be"
get_user_input_with_prompt(prompt, confirmation_message: confirmation_message)
end
|
.get_user_confirmation(prompt) ⇒ Object
177
178
179
180
181
182
183
184
185
|
# File 'lib/shoots_deploy.rb', line 177
def self.get_user_confirmation(prompt)
while true
print "\n#{prompt}: "
input = gets.chomp
print "\nAre you sure? (y/n): "
confirmation = gets.chomp
break input if confirmation == 'y'
end
end
|
167
168
169
170
171
172
173
174
175
|
# File 'lib/shoots_deploy.rb', line 167
def self.get_user_input_with_prompt(prompt, confirmation_message: "You entered")
while true
print "\n#{prompt}: "
input = gets.chomp
print "\n#{confirmation_message} #{input}. Is that right? (y/n): "
confirmation = gets.chomp
break input if confirmation == 'y'
end
end
|
.initialize_aws(region: nil, access_key: nil, secret_key: nil) ⇒ Object
82
83
84
|
# File 'lib/shoots_deploy.rb', line 82
def self.initialize_aws(region: nil, access_key: nil, secret_key: nil)
AWS.config(access_key_id: access_key, secret_access_key: secret_key, region: region)
end
|
.notify_user_of_temporary_s3_url(configuration) ⇒ Object
187
188
189
|
# File 'lib/shoots_deploy.rb', line 187
def self.notify_user_of_temporary_s3_url(configuration)
puts "\nIn the meantime, you can see your website at #{configuration.s3_website_endpoint}"
end
|
.select_region ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/shoots_deploy.rb', line 93
def self.select_region
while true
puts "\nSelect your region eg."
AWS.regions.to_a.each_with_index { |r, i| puts "#{i+1}. #{r.name}" }
print "\nType the number of the region: "
region_index = gets.chomp.to_i - 1
selected_region = AWS.regions.map { |r| r.name }[region_index]
print "\nYou have selected #{selected_region}.\nIs that right? (y/n): "
confirmation = gets.chomp
break selected_region if confirmation == 'y' end
end
|
.use_custom_domain? ⇒ Boolean
128
129
130
131
|
# File 'lib/shoots_deploy.rb', line 128
def self.use_custom_domain?
@custom_domain = @custom_domain || get_user_confirmation("Do you want to use a custom domain for your site? (type y/n)")
@custom_domain == 'y'
end
|
.use_root_domain_with_route_53?(configuration) ⇒ Boolean
138
139
140
141
|
# File 'lib/shoots_deploy.rb', line 138
def self.use_root_domain_with_route_53?(configuration)
use_root_domain = get_user_confirmation("Do you want to use your root domain, #{configuration.root_domain} for this site? (type y/n)")
use_root_domain == 'y'
end
|
.use_route_53? ⇒ Boolean
133
134
135
136
|
# File 'lib/shoots_deploy.rb', line 133
def self.use_route_53?
use_route_53 = get_user_confirmation("Do you want to use AWS Route 53 as your DNS provider? (type y/n)")
use_route_53 == 'y'
end
|