cap-drupal 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.mkd +25 -0
- data/README.rdoc +17 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/cap-drupal +81 -0
- data/lib/cap-drupal.rb +0 -0
- data/lib/recipes/drupal.rb +132 -0
- data/test/helper.rb +10 -0
- data/test/test_cap-drupal.rb +7 -0
- metadata +78 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Mathieu ELie
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.mkd
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Cap Drupal
|
2
|
+
|
3
|
+
Capistrano drupal helpers
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
# gem install cap-drupal
|
8
|
+
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
mkdir config
|
13
|
+
cap-drupal .
|
14
|
+
cap multistage:prepare
|
15
|
+
|
16
|
+
Now you have this tree
|
17
|
+
|
18
|
+
.
|
19
|
+
+--- config
|
20
|
+
| +--- deploy
|
21
|
+
| | +--- production.rb
|
22
|
+
| | +--- development.rb
|
23
|
+
| | +--- preview.rb
|
24
|
+
| +--- deploy.rb
|
25
|
+
+--- Capfile
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= cap-drupal
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Mathieu ELie. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "cap-drupal"
|
8
|
+
gem.summary = %Q{Drupal capistrano recipes}
|
9
|
+
gem.description = %Q{Capistrano recipes fitted to our needs/workflow at websiteburo, could be useful elsewhere}
|
10
|
+
gem.email = "mathieuelie@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/mathieue/cap-drupal"
|
12
|
+
gem.authors = ["Mathieu Elie"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "cap-drupal #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/cap-drupal
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
OptionParser.new do |opts|
|
6
|
+
opts.banner = "Usage: #{File.basename($0)} [path]"
|
7
|
+
|
8
|
+
opts.on("-h", "--help", "Displays this help info") do
|
9
|
+
puts opts
|
10
|
+
exit 0
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
opts.parse!(ARGV)
|
15
|
+
rescue OptionParser::ParseError => e
|
16
|
+
warn e.message
|
17
|
+
puts opts
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
if ARGV.empty?
|
23
|
+
abort "Please specify the directory to capify, e.g. `#{File.basename($0)} .'"
|
24
|
+
elsif !File.exists?(ARGV.first)
|
25
|
+
abort "`#{ARGV.first}' does not exist."
|
26
|
+
elsif !File.directory?(ARGV.first)
|
27
|
+
abort "`#{ARGV.first}' is not a directory."
|
28
|
+
elsif ARGV.length > 1
|
29
|
+
abort "Too many arguments; please specify only the directory to capify."
|
30
|
+
end
|
31
|
+
|
32
|
+
def unindent(string)
|
33
|
+
indentation = string[/\A\s*/]
|
34
|
+
string.strip.gsub(/^#{indentation}/, "")
|
35
|
+
end
|
36
|
+
|
37
|
+
files = {
|
38
|
+
"Capfile" => unindent(<<-FILE),
|
39
|
+
require 'capistrano/ext/multistage'
|
40
|
+
require 'recipes/drupal'
|
41
|
+
load "config/deploy"
|
42
|
+
FILE
|
43
|
+
|
44
|
+
"config/deploy.rb" => unindent(<<-FILE),
|
45
|
+
# project specific settings / all staging area
|
46
|
+
|
47
|
+
set :application, "myapp"
|
48
|
+
|
49
|
+
set :default_stage, "development"
|
50
|
+
set :stages, %w(development preview production)
|
51
|
+
|
52
|
+
###########################################
|
53
|
+
# this conf should be in staging specific conf (dev/preview/etc...)
|
54
|
+
# ex: config/deploy/development.rb
|
55
|
+
# set :deploy_to, "/path/to/app"
|
56
|
+
|
57
|
+
# user generated content
|
58
|
+
# set :ugc_path, "\#{deploy_to}/sites/default/files"
|
59
|
+
# set :application_host, "mysite.net"
|
60
|
+
|
61
|
+
# role :web, "mysite.net"
|
62
|
+
# role :db, "mysite.net", :primary => true
|
63
|
+
FILE
|
64
|
+
}
|
65
|
+
|
66
|
+
base = ARGV.shift
|
67
|
+
files.each do |file, content|
|
68
|
+
file = File.join(base, file)
|
69
|
+
if File.exists?(file)
|
70
|
+
warn "[skip] `#{file}' already exists"
|
71
|
+
elsif File.exists?(file.downcase)
|
72
|
+
warn "[skip] `#{file.downcase}' exists, which could conflict with `#{file}'"
|
73
|
+
elsif !File.exists?(File.dirname(file))
|
74
|
+
warn "[skip] directory `#{File.dirname(file)}' does not exist"
|
75
|
+
else
|
76
|
+
puts "[add] writing `#{file}'"
|
77
|
+
File.open(file, "w") { |f| f.write(content) }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
puts "[done] capified with cap drupal!"
|
data/lib/cap-drupal.rb
ADDED
File without changes
|
@@ -0,0 +1,132 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
# nb of dumps to keep after a clean
|
3
|
+
# nb of ugc files dirs backup
|
4
|
+
|
5
|
+
unless exists?(:max_keep_dump)
|
6
|
+
set :max_keep_dump, 5
|
7
|
+
end
|
8
|
+
|
9
|
+
unless exists?(:max_keep_backup)
|
10
|
+
set :max_keep_backup, 3
|
11
|
+
end
|
12
|
+
|
13
|
+
namespace :drupal do
|
14
|
+
|
15
|
+
desc "clear all drupal caches"
|
16
|
+
task :clearcache, :roles => :db do
|
17
|
+
run "sudo drush -r \"#{deploy_to}\" cc all"
|
18
|
+
end
|
19
|
+
|
20
|
+
namespace :clean do
|
21
|
+
namespace :db do
|
22
|
+
desc "list db dumps to delete"
|
23
|
+
task :check, :roles => :db do
|
24
|
+
dumps_to_delete do |dump|
|
25
|
+
puts "will delete #{dump}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
desc "delete db dumps over max_keep_dump"
|
29
|
+
task :commit, :roles => :db do
|
30
|
+
dumps_to_delete do |dump|
|
31
|
+
run "rm #{dump}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
namespace :ugc do
|
36
|
+
desc "list ugc backups to delete"
|
37
|
+
task :check, :roles => :web do
|
38
|
+
backups_to_delete do |backup|
|
39
|
+
puts "will delete #{backup}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
desc "delete ugc backups over max_keep_backup"
|
43
|
+
task :commit, :roles => :web do
|
44
|
+
backups_to_delete do |backup|
|
45
|
+
run "rm -rf #{backup}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
namespace :db do
|
52
|
+
desc "dump the db to cap user home directory"
|
53
|
+
task :dump, :roles => :db do
|
54
|
+
filename = "#{application}-#{stage}-#{now}.sql"
|
55
|
+
run "sudo drush -r \"#{deploy_to}\" sql-dump > ~/#{filename}"
|
56
|
+
end
|
57
|
+
|
58
|
+
desc "get the latest db dump to current local dir"
|
59
|
+
task :latest, :roles => :db do
|
60
|
+
dumps = capture("ls -xt ~/#{application}-#{stage}-*sql").split.reverse
|
61
|
+
get(dumps.last, "#{dumps.last.split('/').last}")
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "dump the db and download to local dir"
|
65
|
+
task :download, :roles => :db do
|
66
|
+
dump
|
67
|
+
latest
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# user generated content
|
72
|
+
namespace :ugc do
|
73
|
+
|
74
|
+
desc "show the ugc files current size"
|
75
|
+
task :size, :role => :web do
|
76
|
+
run "du -sh #{ugc_path}"
|
77
|
+
end
|
78
|
+
|
79
|
+
desc "copy user generated content to cap user home"
|
80
|
+
task :backup, :role => :web do
|
81
|
+
size
|
82
|
+
dirname = "~/#{application}-#{stage}-#{now}-ugc"
|
83
|
+
run "sudo cp -a #{ugc_path} #{dirname}"
|
84
|
+
run "sudo chown -R #{user}:#{user} #{dirname}"
|
85
|
+
run "touch #{dirname}"
|
86
|
+
end
|
87
|
+
|
88
|
+
desc "get the latest ugc backup"
|
89
|
+
task :latest, :role => :web do
|
90
|
+
backups = capture("ls -dxt ~/#{application}-#{stage}-*-ugc").split.reverse
|
91
|
+
size
|
92
|
+
puts "rsync, this could take a while..."
|
93
|
+
system "rsync -lrp --human-readable --progress --delete #{user}@#{application_host}:#{backups.last}/ #{ugc_local_cache}"
|
94
|
+
puts "local rsync from local cache to final dir"
|
95
|
+
system "rsync -lrp #{ugc_local_cache}/ #{backups.last.split('/').last}"
|
96
|
+
end
|
97
|
+
|
98
|
+
desc "backup and dowload user generated content"
|
99
|
+
task :download, :roles => :db do
|
100
|
+
backup
|
101
|
+
latest
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
before "drupal:db:dump", "drupal:clearcache"
|
107
|
+
|
108
|
+
# used to name new files
|
109
|
+
def now
|
110
|
+
now = Time.now.strftime("%Y-%m-%d-%H.%M.%S")
|
111
|
+
end
|
112
|
+
|
113
|
+
def ugc_local_cache
|
114
|
+
"tmp-#{application}"
|
115
|
+
end
|
116
|
+
|
117
|
+
def dumps_to_delete
|
118
|
+
dumps = capture("ls -xt ~/#{application}-#{stage}-*sql").split
|
119
|
+
dumps.slice!(0, max_keep_dump)
|
120
|
+
dumps.each do |dump|
|
121
|
+
yield dump
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def backups_to_delete
|
126
|
+
backups = capture("ls -dxt ~/#{application}-#{stage}-*-ugc").split
|
127
|
+
backups.slice!(0, max_keep_backup)
|
128
|
+
backups.each do |backup|
|
129
|
+
yield backup
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cap-drupal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mathieu Elie
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-09-13 00:00:00 +02:00
|
13
|
+
default_executable: cap-drupal
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Capistrano recipes fitted to our needs/workflow at websiteburo, could be useful elsewhere
|
26
|
+
email: mathieuelie@gmail.com
|
27
|
+
executables:
|
28
|
+
- cap-drupal
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.mkd
|
34
|
+
- README.rdoc
|
35
|
+
files:
|
36
|
+
- .document
|
37
|
+
- .gitignore
|
38
|
+
- LICENSE
|
39
|
+
- README.mkd
|
40
|
+
- README.rdoc
|
41
|
+
- Rakefile
|
42
|
+
- VERSION
|
43
|
+
- bin/cap-drupal
|
44
|
+
- lib/cap-drupal.rb
|
45
|
+
- lib/recipes/drupal.rb
|
46
|
+
- test/helper.rb
|
47
|
+
- test/test_cap-drupal.rb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://github.com/mathieue/cap-drupal
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options:
|
54
|
+
- --charset=UTF-8
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.3.5
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Drupal capistrano recipes
|
76
|
+
test_files:
|
77
|
+
- test/test_cap-drupal.rb
|
78
|
+
- test/helper.rb
|