Class: Gantree::Deploy
- Inherits:
-
Base
- Object
- Base
- Gantree::Deploy
show all
- Defined in:
- lib/gantree/deploy.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#authenticate_librato, #cfm, #check_credentials, check_for_updates, #check_template_bucket, #create_default_env, #eb, #env_type, #error_msg, #escape_characters_in_string, #get_latest_docker_solution, #print_options, #s3, #set_aws_keys, #tag, update_configuration, #upload_templates
Constructor Details
#initialize(name, options) ⇒ Deploy
Returns a new instance of Deploy.
12
13
14
15
16
17
18
19
20
|
# File 'lib/gantree/deploy.rb', line 12
def initialize name, options
check_credentials
set_aws_keys
@name = name
@options = options
@ext = @options[:ext]
@dockerrun_file = "Dockerrun.aws.json"
print_options
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
11
12
13
|
# File 'lib/gantree/deploy.rb', line 11
def name
@name
end
|
Instance Method Details
#application? ⇒ Boolean
44
45
46
47
|
# File 'lib/gantree/deploy.rb', line 44
def application?
results = eb.describe_applications({ application_names: ["#{@name}"]})
results[:applications].length == 1 ? true : false
end
|
#check_dir_name(envs) ⇒ Object
126
127
128
129
130
|
# File 'lib/gantree/deploy.rb', line 126
def check_dir_name envs
dir_name = File.basename(Dir.getwd)
msg = "WARN: You are deploying from a repo that doesn't match #{@app}"
puts msg.yellow if envs.any? { |env| env.include?(dir_name) } == false
end
|
#check_eb_bucket ⇒ Object
132
133
134
135
136
|
# File 'lib/gantree/deploy.rb', line 132
def check_eb_bucket
bucket = set_bucket
puts "S3 Bucket: #{bucket}".light_blue
s3.buckets.create(bucket) unless s3.buckets[bucket].exists?
end
|
#create_eb_version ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/gantree/deploy.rb', line 96
def create_eb_version
begin
eb.create_application_version({
:application_name => "#{@app}",
:version_label => "#{@packaged_version}",
:source_bundle => {
:s3_bucket => "#{set_bucket}",
:s3_key => "#{@app}-#{@packaged_version}"
}
})
rescue AWS::ElasticBeanstalk::Errors::InvalidParameterValue => e
puts "No Application named #{@app} found #{e}"
end
end
|
#deploy(envs) ⇒ Object
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
|
# File 'lib/gantree/deploy.rb', line 61
def deploy(envs)
@envs = envs
check_dir_name(envs) unless @options[:force]
return if @options[:dry_run]
version = DeployVersion.new(@options, envs[0])
@packaged_version = version.run
puts "packaged_version: #{@packaged_version}"
upload_to_s3
create_eb_version
update_application(envs)
if @options[:slack]
msg = "#{ENV['USER']} is deploying #{@packaged_version} to #{@app} #{@envs.inspect} gantree version #{Gantree::VERSION} "
msg += "Tag: #{@options[:tag]}" if @options[:tag]
Notification.new(@options[:slack]).say(msg) unless @options[:silent]
end
if @options[:librato]
puts "Found Librato Key"
Librato::Metrics.authenticate @options[:librato]["email"], @options[:librato]["token"]
Librato::Metrics.annotate :deploys, "deploys",:source => "#{@app}", :start_time => Time.now.to_i
puts "Librato metric submitted"
end
env = @envs.find {|e| e =~ /-app/ }
if env && @options[:release_notes_wiki] && (prod_deploy? || @options[:release_notes_staging])
ReleaseNotes.new(@options[:release_notes_wiki], env, @packaged_version).create
`git tag #{tag}`
`git push --tags`
end
version.clean_up
end
|
#deploy_to_one ⇒ Object
38
39
40
41
42
|
# File 'lib/gantree/deploy.rb', line 38
def deploy_to_one
env = @environments.first[:environment_name]
puts "Found Environment: #{env}".green
deploy([env])
end
|
#environment? ⇒ Boolean
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/gantree/deploy.rb', line 50
def environment?
results = eb.describe_environments({ environment_names: ["#{@name}"]})[:environments]
if results.length == 0
puts "ERROR: Environment '#{name}' not found"
exit 1
else
@app = results[0][:application_name]
return true
end
end
|
#environment_found? ⇒ Boolean
34
35
36
|
# File 'lib/gantree/deploy.rb', line 34
def environment_found?
@environments.length >=1 ? true : false
end
|
#generate_eb_bucket ⇒ Object
146
147
148
149
|
# File 'lib/gantree/deploy.rb', line 146
def generate_eb_bucket
unique_hash = Digest::SHA1.hexdigest ENV['AWS_ACCESS_KEY_ID']
"eb-bucket-#{unique_hash}"
end
|
#prod_deploy? ⇒ Boolean
151
152
153
|
# File 'lib/gantree/deploy.rb', line 151
def prod_deploy?
@envs.first.split("-").first == "prod"
end
|
#run ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/gantree/deploy.rb', line 22
def run
check_eb_bucket
if application?
DeployApplication.new(@name,@options).run
elsif environment?
puts "Found Environment: #{name}".green
deploy([name])
else
error_msg "You leave me with nothing to deploy".red
end
end
|
#set_bucket ⇒ Object
138
139
140
141
142
143
144
|
# File 'lib/gantree/deploy.rb', line 138
def set_bucket
if @options[:eb_bucket]
bucket = @options[:eb_bucket]
else
bucket = generate_eb_bucket
end
end
|
#update_application(envs) ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/gantree/deploy.rb', line 111
def update_application(envs)
envs.each do |env|
begin
eb.update_environment({
:environment_name => env,
:version_label => @packaged_version
})
puts "Deployed #{@packaged_version} to #{env} on #{@app}".green
rescue AWS::ElasticBeanstalk::Errors::InvalidParameterValue => e
puts "Error: Something went wrong during the deploy to #{env}".red
puts "#{e.message}"
end
end
end
|
#upload_to_s3 ⇒ Object
91
92
93
94
|
# File 'lib/gantree/deploy.rb', line 91
def upload_to_s3
puts "uploading #{@packaged_version} to #{set_bucket}"
s3.buckets["#{set_bucket}"].objects["#{@app}-#{@packaged_version}"].write(:file => @packaged_version)
end
|