Class: Bam::Deployment
Constant Summary
collapse
- PWD =
Dir.pwd
Instance Method Summary
collapse
Methods included from BamHelpers
#border, #col_width, #wrap_borders, #wrap_top
Constructor Details
#initialize(server, to, from, dry_run, task_config) ⇒ Deployment
6
7
8
9
10
11
12
|
# File 'lib/bam.rb', line 6
def initialize(server, to, from, dry_run, task_config)
@from = from
@server = server
@to = to
@dry_run = dry_run || false
@task_config = task_config
end
|
Instance Method Details
#deploy ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/bam.rb', line 54
def deploy
puts "PRE-DEPLOYMENT TASKS: \n\n"
deploy_tasks @task_config[:pre]
puts(wrap_top("STARTING DEPLOYMENT:"))
cmd = "rsync -avzC #{@from} #{@server}:#{@to} #{exclusions}"
output = "OUTPUT:\n#{cmd}"
puts(wrap_borders(output))
puts "POST-DEPLOYMENT TASKS: \n\n"
deploy_tasks @task_config[:post]
system(cmd) unless @dry_run
end
|
#deploy_tasks(tasks) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/bam.rb', line 67
def deploy_tasks(tasks)
if tasks.length > 0
tasks.each do |task|
remote_task = task.split("remote:")
if remote_task.length > 1
remote_exec remote_task[1]
else
puts "[LOCAL] #{task}"
`#{task}` unless @dry_run
end
end
end
puts "\n"
end
|
#exclusions ⇒ Object
37
38
39
40
41
|
# File 'lib/bam.rb', line 37
def exclusions
exclude_list = get_exclusions.map { |e| "--exclude '#{e}' " }
exclude_list = exclude_list.join
exclude_list
end
|
#get_exclusions ⇒ Object
gets a list of exclusions - exceptions
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/bam.rb', line 23
def get_exclusions
return "" if !has_git_ignores? || !has_git?
git_ignore = File.join PWD, ".gitignore"
exclusions = `cat #{git_ignore}`.split("\n")
exclusions = exclusions.select { |exclusion| exclusion[0,1] != '#' }
exclusions = exclusions - @task_config[:always_include]
if @dry_run
puts wrap_top("EXCLUSIONS:")
puts exclusions.join("\n")
end
exclusions
end
|
#has_git? ⇒ Boolean
14
15
16
|
# File 'lib/bam.rb', line 14
def has_git?
File.exists?(File.join PWD, ".git")
end
|
#has_git_ignores? ⇒ Boolean
18
19
20
|
# File 'lib/bam.rb', line 18
def has_git_ignores?
File.exists?(File.join PWD, ".gitignore")
end
|
#remote_exec(name) ⇒ Object
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/bam.rb', line 43
def remote_exec(name)
remote_task = @task_config[:remote][name.to_sym]
if remote_task.nil?
puts "[REMOTE] TASK: #{name} does not exist"
else
exec_cmd = "ssh #{@server} '#{remote_task}'"
puts @dry_run ? "[REMOTE] #{name} : #{remote_task}" : "[REMOTE] #{name}"
system exec_cmd unless @dry_run
end
end
|