capistrano-content 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
14
  gem.name = 'capistrano-content'
15
15
  gem.require_paths = ['lib']
16
- gem.version = '0.0.1'
16
+ gem.version = '0.0.2'
17
17
 
18
18
  # Runtime dependencies
19
19
  gem.add_dependency 'rake'
@@ -0,0 +1,91 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ set :shared_content_path, -> { "#{fetch :shared_path}/shared_contents" }
3
+
4
+ namespace :content do
5
+ desc 'setup the content folders'
6
+ task :setup, :roles => :app do
7
+ commands = "#{try_sudo} mkdir -p #{fetch :shared_content_path};"
8
+ fetch(:content_folders, []).each do |folder, path|
9
+ commands << "#{try_sudo} mkdir -p #{fetch :shared_content_path}/#{folder};"
10
+ end
11
+
12
+ run commands
13
+ end
14
+
15
+ desc 'Import content'
16
+ task :import, :roles => :app do
17
+ transaction do
18
+ tmp_file = random_tmp_file
19
+ on_rollback { run "rm -f #{tmp_file}" }
20
+ backup
21
+ write File.read(arguments), tmp_file
22
+ run <<-CMD
23
+ cd #{fetch :shared_content_path} &&
24
+ tar xf #{tmp_file} &&
25
+ rm -f #{tmp_file}
26
+ CMD
27
+ end
28
+ end
29
+
30
+ desc 'Export content'
31
+ task :export, :roles => :app do
32
+ tmp_file = "#{random_tmp_file}.tar.gz"
33
+ on_rollback { run "rm -f #{fetch :latest_content_backup}" }
34
+ on_rollback { run_locally "rm -f #{tmp_file}" }
35
+ transaction do
36
+ backup
37
+ download fetch(:latest_content_backup), tmp_file
38
+ logger.important "The content folder has been downloaded to #{tmp_file}"
39
+ end
40
+ end
41
+
42
+
43
+ desc '[internal] backup content folders'
44
+ task :backup, :roles => :app do
45
+ set :latest_content_backup,
46
+ "#{fetch :backup_path, "#{fetch :deploy_to}/backups"}/#{fetch :application}_shared_contents_#{Time.now.strftime('%d-%m-%Y_%H-%M-%S')}.tar.gz"
47
+ on_rollback { run "rm -f #{fetch :latest_content_backup}" }
48
+
49
+ run <<-CMD
50
+ cd #{fetch :shared_content_path} &&
51
+ tar chzf #{fetch :latest_content_backup} --exclude='*~' --exclude='*.tmp' --exclude='*.bak' *
52
+ CMD
53
+ end
54
+
55
+ desc '[internal] Link content folders'
56
+ task :link, :roles => :app do
57
+ commands = ""
58
+
59
+ fetch(:content_folders, []).each do |folder, path|
60
+ # At this point, the current_path does not exists and by running an mkdir
61
+ # later, we're actually breaking stuff.
62
+ # So replace current_path with latest_release in the contents_path string
63
+ path.gsub! %r{#{current_path}}, latest_release
64
+
65
+ # Remove the path, making sure it does not exists
66
+ commands << "#{try_sudo} rm -f #{path};"
67
+
68
+ # Make sure we have the folder that'll contain the shared path
69
+ commands << "#{try_sudo} mkdir -p #{File.dirname(path)};"
70
+
71
+ # Create the symlink
72
+ commands << "#{try_sudo} ln -nsf #{shared_path}/shared_contents/#{folder} #{path};"
73
+ end
74
+
75
+ run commands
76
+ end
77
+
78
+ desc '[internal] Cleanup the content folder'
79
+ task :clean, :roles => :app do
80
+ find_params = ["-name '._*'", "-name '*~'", "-name '*.tmp'", "-name '*.bak'"]
81
+ commands = find_params.inject '' do |commands, find_param|
82
+ commands << "#{try_sudo} find #{fetch :shared_content_path} #{find_param} -exec rm -f {} ';';"
83
+ end
84
+
85
+ run commands
86
+ end
87
+ end
88
+
89
+ after 'deploy:setup', 'content:setup'
90
+ after 'deploy:finalize_update', 'content:link'
91
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-content
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -72,8 +72,7 @@ files:
72
72
  - README.md
73
73
  - Rakefile
74
74
  - capistrano-content.gemspec
75
- - lib/capistrano-content.rb
76
- - lib/capistrano-content/version.rb
75
+ - lib/capistrano/ext/content.rb
77
76
  homepage: http://technogate.github.com/content
78
77
  licenses: []
79
78
  post_install_message:
@@ -94,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
93
  version: '0'
95
94
  segments:
96
95
  - 0
97
- hash: 1665194813565621472
96
+ hash: -4263925061984318509
98
97
  requirements: []
99
98
  rubyforge_project:
100
99
  rubygems_version: 1.8.23
@@ -1,5 +0,0 @@
1
- module Capistrano
2
- module Content
3
- VERSION = "0.0.1"
4
- end
5
- end
@@ -1,7 +0,0 @@
1
- require "capistrano-content/version"
2
-
3
- module Capistrano
4
- module Content
5
- # Your code goes here...
6
- end
7
- end