Class: Gantree::DeployVersion
Instance Attribute Summary collapse
Attributes inherited from Deploy
#name
Instance Method Summary
collapse
Methods inherited from Deploy
#application?, #check_dir_name, #check_eb_bucket, #create_eb_version, #deploy, #deploy_to_one, #environment?, #environment_found?, #generate_eb_bucket, #prod_deploy?, #set_bucket, #update_application, #upload_to_s3
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(options, env) ⇒ DeployVersion
Returns a new instance of DeployVersion.
10
11
12
13
14
15
16
17
|
# File 'lib/gantree/deploy_version.rb', line 10
def initialize options, env
@options = options
@ext = @options[:ext]
@ext_role = @options[:ext_role]
@project_root = @options[:project_root]
@dockerrun_file = "#{@project_root}Dockerrun.aws.json"
@env = env
end
|
Instance Attribute Details
#dockerrun_file ⇒ Object
Returns the value of attribute dockerrun_file.
9
10
11
|
# File 'lib/gantree/deploy_version.rb', line 9
def dockerrun_file
@dockerrun_file
end
|
#packaged_version ⇒ Object
Returns the value of attribute packaged_version.
9
10
11
|
# File 'lib/gantree/deploy_version.rb', line 9
def packaged_version
@packaged_version
end
|
Instance Method Details
#clean_up ⇒ Object
130
131
132
133
134
135
136
137
|
# File 'lib/gantree/deploy_version.rb', line 130
def clean_up
puts "Cleaning up tmp files".yellow
FileUtils.rm_rf @packaged_version if @packaged_version
FileUtils.rm_rf("/tmp/#{@ext.split('/').last}") if File.directory?("/tmp/#{@ext.split('/').last}")
FileUtils.rm_rf("/tmp/#{@ext_role.split('/').last}:#{get_role_type}") if @ext_role
FileUtils.rm_rf("/tmp/merged_extensions/") if File.directory? "/tmp/merged_extensions/"
puts "All tmp files removed".green
end
|
#clone_repo(repo) ⇒ Object
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/gantree/deploy_version.rb', line 119
def clone_repo repo
repo_name = repo.split('/').last
FileUtils.mkdir("/tmp/#{repo_name}")
if ext_branch? repo
`git clone -b #{get_ext_branch repo} #{get_ext_repo repo} /tmp/#{repo_name}/`
else
`git clone #{get_ext_repo repo} /tmp/#{repo_name}/`
end
FileUtils.cp_r "/tmp/#{repo_name}/.", "/tmp/merged_extensions/.ebextensions/"
end
|
#create_version_files ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/gantree/deploy_version.rb', line 56
def create_version_files
clean_up
version = "#{version_tag}-#{Time.now.strftime("%m-%d-%Y-%H-%M-%S")}"
puts "version: #{version}"
set_auth if @options[:auth]
set_image_path if @options[:image_path]
set_tag_to_deploy
if File.directory?(".ebextensions/") || @ext || @ext_role
zip = "#{@project_root}#{version}.zip"
merge_extensions
puts "The following files are being zipped".yellow
system('ls -l /tmp/merged_extensions/.ebextensions/')
Archive::Zip.archive(zip, ['/tmp/merged_extensions/.ebextensions/', "/tmp/#{@dockerrun_file}"])
zip
else
new_dockerrun = "/tmp/#{version}-Dockerrun.aws.json"
FileUtils.cp("/tmp/Dockerrun.aws.json", new_dockerrun)
new_dockerrun
end
end
|
#docker ⇒ Object
23
24
25
|
# File 'lib/gantree/deploy_version.rb', line 23
def docker
@docker ||= JSON.parse(IO.read(@dockerrun_file))
end
|
#ext? ⇒ Boolean
77
78
79
80
81
82
83
|
# File 'lib/gantree/deploy_version.rb', line 77
def ext?
if @ext
true
else
false
end
end
|
#ext_branch?(repo) ⇒ Boolean
106
107
108
109
110
111
112
|
# File 'lib/gantree/deploy_version.rb', line 106
def ext_branch? repo
if repo.count(":") == 2
true
else
false
end
end
|
#get_ext_branch(repo) ⇒ Object
114
115
116
117
|
# File 'lib/gantree/deploy_version.rb', line 114
def get_ext_branch repo
branch = repo.match(/:.*(:.*)$/)[1]
branch.tr(':','')
end
|
#get_ext_repo(repo) ⇒ Object
98
99
100
101
102
103
104
|
# File 'lib/gantree/deploy_version.rb', line 98
def get_ext_repo repo
if ext_branch? repo
repo.sub(":#{get_ext_branch repo}", '')
else
repo
end
end
|
#get_role_type ⇒ Object
146
147
148
|
# File 'lib/gantree/deploy_version.rb', line 146
def get_role_type
@env.split('-')[2]
end
|
#local_extensions? ⇒ Boolean
94
95
96
|
# File 'lib/gantree/deploy_version.rb', line 94
def local_extensions?
File.directory?(".ebextensions/")
end
|
#merge_extensions ⇒ Object
139
140
141
142
143
144
145
|
# File 'lib/gantree/deploy_version.rb', line 139
def merge_extensions
FileUtils.mkdir("/tmp/merged_extensions/")
FileUtils.mkdir("/tmp/merged_extensions/.ebextensions/")
clone_repo @ext if @ext
clone_repo "#{@ext_role}:#{get_role_type}" if @ext_role
FileUtils.cp_r('.ebextensions/.','/tmp/merged_extensions/.ebextensions') if File.directory? ".ebextensions/"
end
|
#repo? ⇒ Boolean
85
86
87
88
89
90
91
92
|
# File 'lib/gantree/deploy_version.rb', line 85
def repo?
if @ext.include? "github"
puts "Cloning: #{@ext}..."
true
else
false
end
end
|
#run ⇒ Object
19
20
21
|
# File 'lib/gantree/deploy_version.rb', line 19
def run
@packaged_version = create_version_files
end
|
#set_auth ⇒ Object
27
28
29
30
31
32
33
34
35
|
# File 'lib/gantree/deploy_version.rb', line 27
def set_auth
docker["Authentication"] = {}
items = @options[:auth].split("/")
bucket = items.shift
key = items.join("/")
docker["Authentication"]["Bucket"] = bucket
docker["Authentication"]["Key"] = key
IO.write("/tmp/#{@dockerrun_file}", JSON.pretty_generate(docker))
end
|
#set_image_path ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/gantree/deploy_version.rb', line 43
def set_image_path
image = docker["Image"]["Name"]
image.gsub!(/(.*):/, "#{@options[:image_path]}:")
path = "/tmp/#{@dockerrun_file}"
FileUtils.mkdir_p(File.dirname(path)) unless File.exist?(path)
IO.write(path, JSON.pretty_generate(docker))
image
end
|
#set_tag_to_deploy ⇒ Object
37
38
39
40
41
|
# File 'lib/gantree/deploy_version.rb', line 37
def set_tag_to_deploy
image = docker["Image"]["Name"]
image.gsub!(/:(.*)$/, ":#{@options[:tag]}")
IO.write("/tmp/#{@dockerrun_file}", JSON.pretty_generate(docker))
end
|
#version_tag ⇒ Object
52
53
54
|
# File 'lib/gantree/deploy_version.rb', line 52
def version_tag
@options[:tag] || tag
end
|