16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
88
89
90
91
92
93
|
# File 'lib/capistrano-scm-local_copy.rb', line 16
def define_tasks
namespace :archive do
archive_plugin = self
task :create_release do
archive_name = fetch(:archive_name)
on release_roles :all do
execute :mkdir, '-p', release_path
temp_file = capture(:mktemp)
upload!(archive_name, temp_file)
execute :mv, '-fv', temp_file, archive_name
execute :unzip, '-q -d', release_path, archive_name
execute :rm, '-fv', archive_name, temp_file
end
end
desc 'Create archive'
task :create_archive do
archive_name = fetch(:archive_name)
puts "Create archive #{archive_name}"
include_dir = fetch(:include_dir)
excludes = fetch(:excludes) + [archive_name]
run_locally do
archive_objects = FileList[include_dir]
excludes.each do |file|
archive_objects = archive_objects.exclude(file)
end
Zip::File.open(archive_name, Zip::File::CREATE) do |zip_file|
archive_objects.each do |object|
if File.directory?(object)
Dir.glob("#{object}/**/*.*").each do |child_file|
zip_file.add(child_file, File.join('./', child_file))
end
else
zip_file.add(object, File.join('./', object))
end
end
end
end
end
task :set_current_revision do
set :current_revision, archive_plugin.md5(fetch(:archive_name))
end
Rake::Task['deploy:log_revision'].clear_actions
desc 'log revision'
task :log_revision do
on release_roles :all do
execute :echo,
'"from local files,',
"(archive md5: #{fetch(:current_revision)})",
"deployed as release #{fetch(:release_timestamp)}",
"by #{local_user}\"",
'>>',
revision_log
end
end
task :clean do
archive_name = fetch(:archive_name)
puts "Clean: remove #{archive_name}"
FileUtils.rm(archive_name, force: true)
end
task :clean_all do
puts 'Clean deploy_*.zip archives'
Dir.glob('./deploy_*.zip').each { |file| FileUtils.rm(file, force: true) }
end
before :create_archive, :clean_all
before :clean, :set_current_revision
after :create_release, :clean
before :create_release, :create_archive
end
end
|