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.
11
12
13
14
15
16
17
18
19
|
# File 'lib/gantree/deploy.rb', line 11
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.
10
11
12
|
# File 'lib/gantree/deploy.rb', line 10
def name
@name
end
|
Instance Method Details
#application? ⇒ Boolean
43
44
45
46
|
# File 'lib/gantree/deploy.rb', line 43
def application?
results = eb.describe_applications({ application_names: ["#{@name}"]})
results[:applications].length == 1 ? true : false
end
|
#check_dir_name(envs) ⇒ Object
124
125
126
127
128
|
# File 'lib/gantree/deploy.rb', line 124
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
130
131
132
133
134
|
# File 'lib/gantree/deploy.rb', line 130
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/gantree/deploy.rb', line 94
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
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
|
# File 'lib/gantree/deploy.rb', line 60
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
upload_to_s3
create_eb_version
update_application(envs)
if @options[:slack]
msg = "#{ENV['USER']} is deploying #{@packaged_version} to #{@app} "
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
if @options[:release_notes_wiki] == "enabled" && prod_deploy? && @app.include?("-app-")
ReleaseNotes.new(@options[:release_notes_wiki], @app, new_hash).create
`git tag #{tag}`
`git push --tags`
end
version.clean_up
end
|
#deploy_to_one ⇒ Object
37
38
39
40
41
|
# File 'lib/gantree/deploy.rb', line 37
def deploy_to_one
env = @environments.first[:environment_name]
puts "Found Environment: #{env}".green
deploy([env])
end
|
#environment? ⇒ Boolean
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/gantree/deploy.rb', line 49
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
33
34
35
|
# File 'lib/gantree/deploy.rb', line 33
def environment_found?
@environments.length >=1 ? true : false
end
|
#generate_eb_bucket ⇒ Object
144
145
146
147
|
# File 'lib/gantree/deploy.rb', line 144
def generate_eb_bucket
unique_hash = Digest::SHA1.hexdigest ENV['AWS_ACCESS_KEY_ID']
"eb-bucket-#{unique_hash}"
end
|
#new_hash ⇒ Object
152
153
154
|
# File 'lib/gantree/deploy.rb', line 152
def new_hash
@packaged_version.split("-")[2]
end
|
#prod_deploy? ⇒ Boolean
149
150
151
|
# File 'lib/gantree/deploy.rb', line 149
def prod_deploy?
@envs.first.split("-").first == "prod"
end
|
#run ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/gantree/deploy.rb', line 21
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
136
137
138
139
140
141
142
|
# File 'lib/gantree/deploy.rb', line 136
def set_bucket
if @options[:eb_bucket]
bucket = @options[:eb_bucket]
else
bucket = generate_eb_bucket
end
end
|
#update_application(envs) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/gantree/deploy.rb', line 109
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
89
90
91
92
|
# File 'lib/gantree/deploy.rb', line 89
def upload_to_s3
puts "uploading #{@packaged_version} to #{set_bucket}"
s3.buckets["#{set_bucket}"].objects["#{@app}-#{@packaged_version}"].write(:file => @packaged_version)
end
|