Class: SCM::CopyStrategy

Inherits:
Capistrano::SCM::Plugin
  • Object
show all
Defined in:
lib/capistrano/scm/copy-strategy.rb

Instance Method Summary collapse

Instance Method Details

#archive_to_release_pathObject



64
65
66
67
68
# File 'lib/capistrano/scm/copy-strategy.rb', line 64

def archive_to_release_path
  backend.execute :mkdir, "-p", release_path
   backend.execute :tar, "-xf", "#{repo_path}/#{fetch(:archive_name)}", "-C", release_path
   backend.execute :rm, "#{repo_path}/#{fetch(:archive_name)}"
end

#check_repo_dirObject



30
31
32
33
34
35
36
# File 'lib/capistrano/scm/copy-strategy.rb', line 30

def check_repo_dir
	if !backend.test " [ -d #{repo_path} ] "
		backend.execute :mkdir, "-p", repo_path
	else
		backend.test :rm, "#{repo_path}/*"  		
	end
end

#check_serverObject



26
27
28
# File 'lib/capistrano/scm/copy-strategy.rb', line 26

def check_server
	backend.test :tar, "--version"
end

#create_archiveObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/capistrano/scm/copy-strategy.rb', line 38

def create_archive
	archive_name = fetch(:archive_name)
  include_dir  = fetch(:include_dir)
  exclude_dirs  = Array(fetch(:exclude_dirs))
  exclude_dirs.push(archive_name)
  temp_folder = fetch(:temp_folder)

  FileUtils.copy_entry include_dir, "#{temp_folder}/#{env.release_timestamp}"

  # sh "ls -al #{temp_folder}/#{env.release_timestamp}"
  
  exclude_dirs.map { |dir| 
     FileUtils.rm_rf "#{temp_folder}/#{env.release_timestamp}/#{dir}" 
     FileUtils.rm_rf Dir.glob("#{temp_folder}/#{env.release_timestamp}/#{dir}") 
   }

  sh "ls -al #{temp_folder}/#{env.release_timestamp}"
  
  tar_verbose = fetch(:tar_verbose, true) ? "v" : ""

  cmd = ["tar", "-c#{tar_verbose}zf", archive_name, "-C #{temp_folder}/#{env.release_timestamp}", '.']
		sh cmd.join(' ')
		return archive_name
end

#define_tasksObject



22
23
24
# File 'lib/capistrano/scm/copy-strategy.rb', line 22

def define_tasks
 	eval_rakefile File.expand_path("../tasks/copy-strategy.rake", __FILE__)
end

#register_hooksObject



17
18
19
20
# File 'lib/capistrano/scm/copy-strategy.rb', line 17

def register_hooks
	after "deploy:new_release_path", "copy_strategy:create_release"
	before "deploy:check", "copy_strategy:check"
end

#set_defaultsObject



9
10
11
12
13
14
15
# File 'lib/capistrano/scm/copy-strategy.rb', line 9

def set_defaults
   # Define any variables needed to configure the plugin.
   set_if_empty :include_dir, "."
   set_if_empty :archive_name, "#{env.release_timestamp}.tar.gz"
   set_if_empty :temp_folder, "#{Dir.tmpdir}"

end