Class: Gantree::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/gantree/base.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.check_for_updates(opts) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/gantree/base.rb', line 12
def self.check_for_updates opts
puts opts.inspect
enabled = opts[:auto_updates]
latest_version = `gem search gantree | grep gantree | awk '{ print $2 }' | tr -d '()'`.strip
current_version = VERSION
puts "Auto updates enabled".light_blue if enabled
puts "Auto updates disabled".light_blue if !enabled
puts "Updating from #{current_version} to #{latest_version}...".green
if current_version == latest_version && enabled
system("gem update gantree --force")
else
puts "gem already up to date".light_blue
end
update_configuration(opts[:auto_configure]) if opts[:auto_configure]
Gantree::Config.merge_defaults(opts)
end
|
.update_configuration(repo) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/gantree/base.rb', line 30
def self.update_configuration repo
puts "Auto configuring from #{repo}".light_blue
FileUtils.rm_rf("/tmp/gantreecfg") if File.directory?("/tmp/gantreecfg")
system("git clone #{repo} /tmp/gantreecfg")
FileUtils.cp("/tmp/gantreecfg/.gantreecfg","#{ENV['HOME']}/")
puts "Auto Configured".green
end
|
Instance Method Details
#authenticate_librato ⇒ Object
82
83
84
85
86
|
# File 'lib/gantree/base.rb', line 82
def authenticate_librato
if @options[:librato]
Librato::Metrics.authenticate @options[:librato][:email], @options[:librato][:token]
end
end
|
#cfm ⇒ Object
59
60
61
|
# File 'lib/gantree/base.rb', line 59
def cfm
@cfm ||= AWS::CloudFormation.new
end
|
#check_credentials ⇒ Object
7
8
9
10
|
# File 'lib/gantree/base.rb', line 7
def check_credentials
raise "Please set your AWS Environment Variables" unless ENV['AWS_SECRET_ACCESS_KEY']
raise "Please set your AWS Environment Variables" unless ENV['AWS_ACCESS_KEY_ID']
end
|
#check_template_bucket ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/gantree/base.rb', line 121
def check_template_bucket
puts "DEBUG: #{@options[:cfn_bucket]}"
raise "Set Bucket to Upload Templates with --cfn-bucket" unless @options[:cfn_bucket]
bucket_name = "#{@options[:cfn_bucket]}/#{@options[:stack_name]}"
if s3.buckets[bucket_name].exists?
puts "uploading cfn templates to #{@options[:cfn_bucket]}/#{@options[:stack_name]}"
else
puts "creating bucket #{@options[:cfn_bucket]}/#{@options[:stack_name]} to upload templates"
s3.buckets.create(bucket_name)
end
end
|
#create_default_env ⇒ Object
73
74
75
76
77
78
79
80
|
# File 'lib/gantree/base.rb', line 73
def create_default_env
tags = @options[:stack_name].split("-")
if tags.length == 3
[tags[1],tags[0],"app",tags[2]].join('-')
else
raise "Please Set Envinronment Name with -e"
end
end
|
#eb ⇒ Object
55
56
57
|
# File 'lib/gantree/base.rb', line 55
def eb
@eb ||= AWS::ElasticBeanstalk::Client.new
end
|
#env_type ⇒ Object
88
89
90
91
92
93
94
95
96
|
# File 'lib/gantree/base.rb', line 88
def env_type
if @options[:env].include?("prod")
"prod"
elsif @options[:env].include?("stag")
"stag"
else
""
end
end
|
#error_msg(msg) ⇒ Object
133
134
135
136
|
# File 'lib/gantree/base.rb', line 133
def error_msg msg
puts msg.red
exit 1
end
|
#escape_characters_in_string(string) ⇒ Object
106
107
108
109
|
# File 'lib/gantree/base.rb', line 106
def escape_characters_in_string(string)
pattern = /(\'|\"|\.|\*|\/|\-|\\)/
string.gsub(pattern){|match|"\\" + match}
end
|
#get_latest_docker_solution ⇒ Object
98
99
100
101
102
103
|
# File 'lib/gantree/base.rb', line 98
def get_latest_docker_solution
result = eb.list_available_solution_stacks
solutions = result[:solution_stacks]
docker_solutions = solutions.select { |s| s.include? "running Docker"}
docker_solutions.first
end
|
#print_options ⇒ Object
38
39
40
41
42
|
# File 'lib/gantree/base.rb', line 38
def print_options
@options.each do |param, value|
puts "#{param}: #{value}"
end
end
|
#s3 ⇒ Object
51
52
53
|
# File 'lib/gantree/base.rb', line 51
def s3
@s3 ||= AWS::S3.new
end
|
#set_aws_keys ⇒ Object
44
45
46
47
48
49
|
# File 'lib/gantree/base.rb', line 44
def set_aws_keys
AWS.config(
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
)
end
|
#tag ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/gantree/base.rb', line 64
def tag
origin = `git config --get remote.origin.url`.match("com(.*)\/")[1].gsub(":","").gsub("/","").strip
branch = `git rev-parse --abbrev-ref HEAD`.strip
hash = `git rev-parse --verify --short #{branch}`.strip
"#{origin}-#{branch.gsub('-','')}-#{hash}".gsub("/", "").downcase
rescue
puts "ERROR: Using outside of a git repository".red
end
|
#upload_templates ⇒ Object
111
112
113
114
115
116
117
118
119
|
# File 'lib/gantree/base.rb', line 111
def upload_templates
check_template_bucket
@templates.each do |template|
filename = "cfn/#{@options[:stack_name]}-#{template}.cfn.json"
key = File.basename(filename)
s3.buckets["#{@options[:cfn_bucket]}/#{@options[:stack_name]}"].objects[key].write(:file => filename)
end
puts "templates uploaded"
end
|