dimkiriyenko-capone 0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +24 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +29 -0
- data/LICENSE +20 -0
- data/README.md +69 -0
- data/Rakefile +2 -0
- data/capone.gemspec +22 -0
- data/lib/capone.rb +9 -0
- data/lib/capone/version.rb +3 -0
- data/recipes/daemon_strategies/mongrel_cluster.rb +6 -0
- data/recipes/daemon_strategies/passenger.rb +17 -0
- data/recipes/daemon_strategy.rb +7 -0
- data/recipes/db.rb +96 -0
- data/recipes/defaults.rb +33 -0
- data/recipes/delayed_job.rb +7 -0
- data/recipes/gems.rb +23 -0
- data/recipes/nginx.rb +34 -0
- data/recipes/replicate.rb +3 -0
- data/recipes/whenever.rb +17 -0
- metadata +105 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
capone (0.14)
|
5
|
+
capistrano (>= 2.5.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
capistrano (2.6.0)
|
11
|
+
highline
|
12
|
+
net-scp (>= 1.0.0)
|
13
|
+
net-sftp (>= 2.0.0)
|
14
|
+
net-ssh (>= 2.0.14)
|
15
|
+
net-ssh-gateway (>= 1.1.0)
|
16
|
+
highline (1.6.2)
|
17
|
+
net-scp (1.0.4)
|
18
|
+
net-ssh (>= 1.99.1)
|
19
|
+
net-sftp (2.0.5)
|
20
|
+
net-ssh (>= 2.0.9)
|
21
|
+
net-ssh (2.1.4)
|
22
|
+
net-ssh-gateway (1.1.0)
|
23
|
+
net-ssh (>= 1.99.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
capone!
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Denis Barushev
|
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.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Capone
|
2
|
+
|
3
|
+
Capone is the set of Capistrano recipes that help me to deploy my
|
4
|
+
applications.
|
5
|
+
|
6
|
+
Capone by default uses Mongrel cluster (or Passenger) as an application
|
7
|
+
server, nginx as a web server, MySQL as a database server and git as a SCM.
|
8
|
+
|
9
|
+
The latest version of Capone was inspired by Rubaidh's
|
10
|
+
[Rubaidhstrano](http://github.com/rubaidh/rubaidhstrano) and some code has
|
11
|
+
been borrowed from its sources.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Capone could be installed either as a gem or as Rails plugin.
|
16
|
+
|
17
|
+
### Gem (preferred)
|
18
|
+
|
19
|
+
For Rails 3 add to your `Gemfile`:
|
20
|
+
|
21
|
+
gem 'capone', :require => false, :version => '>= 0.1.0'
|
22
|
+
|
23
|
+
For Rails 2 add to the end of your `config/environments/development.rb` file:
|
24
|
+
|
25
|
+
config.gem 'capone', :lib => false, :version => '>= 0.1.0'
|
26
|
+
|
27
|
+
### Rails plugin
|
28
|
+
|
29
|
+
./script/plugin install git://github.com/denis/capone.git
|
30
|
+
|
31
|
+
## Example usage
|
32
|
+
|
33
|
+
To start using Capone you just need to add `require "capone"` to your
|
34
|
+
`config/deploy.rb` file (only if Capone is installed as a gem) and set some
|
35
|
+
variables:
|
36
|
+
|
37
|
+
require "capone"
|
38
|
+
|
39
|
+
set :application, "set your application name here"
|
40
|
+
set :repository, "set your repository location here"
|
41
|
+
set :host, "set your host here"
|
42
|
+
|
43
|
+
# See capone/recipes/defaults.rb for defaults
|
44
|
+
|
45
|
+
## Features
|
46
|
+
|
47
|
+
### Whenever
|
48
|
+
|
49
|
+
Using [whenever](https://github.com/javan/whenever) is as easy as `set`ing `:whenever` to `true`. Just like this:
|
50
|
+
|
51
|
+
set :whenever, true
|
52
|
+
|
53
|
+
Whenever will use your application deploy path as crontab identifier.
|
54
|
+
|
55
|
+
You may wish to override the command, used to invoke whenever, e.g., to use Bundler:
|
56
|
+
|
57
|
+
set :whenever_command, 'bundle exec whenever'
|
58
|
+
|
59
|
+
Other features in process...
|
60
|
+
|
61
|
+
## Thanks
|
62
|
+
|
63
|
+
- Jamis Buck for [Capistrano](http://github.com/jamis/capistrano),
|
64
|
+
- Rubaidh Ltd for their awesome
|
65
|
+
[Rubaidhstrano](http://github.com/rubaidh/rubaidhstrano).
|
66
|
+
|
67
|
+
## Copyright
|
68
|
+
|
69
|
+
Copyright (c) 2009 Denis Barushev. See LICENSE for details.
|
data/Rakefile
ADDED
data/capone.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "capone/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "dimkiriyenko-capone"
|
7
|
+
s.version = Capone::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Denis Barushev", "Dmitriy Kiriyenko"]
|
10
|
+
s.email = ["barushev@gmail.com", "dmitriy.kiriyenko@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/dmitriy-kiriyenko/capone"
|
12
|
+
s.summary = %q{Capone is the set of rake tasks and capistrano recipes.}
|
13
|
+
s.description = %q{Capone is the set of rake tasks and capistrano recipes.
|
14
|
+
Use it to avoid writing typical scenarios and maintaining them
|
15
|
+
in favour of configuring your builds and deploys declaratively.}
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
s.add_dependency "capistrano", ">= 2.5.0"
|
22
|
+
end
|
data/lib/capone.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
namespace :deploy do
|
2
|
+
desc "Start application."
|
3
|
+
task :start, :roles => :app do
|
4
|
+
run "touch #{current_release}/tmp/restart.txt"
|
5
|
+
end
|
6
|
+
|
7
|
+
desc "Stop application."
|
8
|
+
task :stop, :roles => :app do
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Restart application."
|
12
|
+
task :restart, :roles => :app do
|
13
|
+
run "touch #{current_release}/tmp/restart.txt"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
depend :remote, :gem, "passenger", ">=2.2.2"
|
data/recipes/db.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
namespace :capone do
|
2
|
+
namespace :db do
|
3
|
+
desc <<-DESC
|
4
|
+
Create MySQL user and database using data from config/database.yml.
|
5
|
+
DESC
|
6
|
+
task :setup, :roles => :db, :only => { :primary => true } do
|
7
|
+
config = YAML::load(File.open("config/database.yml"))[rails_env]
|
8
|
+
root_password = Capistrano::CLI.password_prompt(prompt="Enter a root password for MySQL: ")
|
9
|
+
|
10
|
+
run "mysql --user='root' --password='#{root_password}' -e \"CREATE DATABASE IF NOT EXISTS #{config["database"]} DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; GRANT ALL PRIVILEGES ON #{config["database"]}.* TO '#{config["username"]}'@'localhost' IDENTIFIED BY '#{config["password"]}' WITH GRANT OPTION;\""
|
11
|
+
end
|
12
|
+
|
13
|
+
desc <<-DESC
|
14
|
+
Load fixtures from db/fixtures to the database.
|
15
|
+
DESC
|
16
|
+
task :load_fixtures, :roles => :db, :only => { :primary => true } do
|
17
|
+
run "rake db:fixtures:load FIXTURES_PATH=db/fixtures RAILS_ENV=#{rails_env} -f #{release_path}/Rakefile"
|
18
|
+
end
|
19
|
+
|
20
|
+
desc <<-DESC
|
21
|
+
Dumps the database for the current environment into db/env-data.sql.bz2.
|
22
|
+
Any existing backup will be overwritten.
|
23
|
+
DESC
|
24
|
+
task :backup, :roles => :db, :only => { :primary => true } do
|
25
|
+
config = YAML::load(File.open("config/database.yml"))[rails_env]
|
26
|
+
case config["adapter"]
|
27
|
+
when "mysql"
|
28
|
+
cmd = ["mysqldump"]
|
29
|
+
cmd << "--host='#{config['host']}'" unless config["host"].nil?
|
30
|
+
cmd << "--user='#{config['username'].nil? ? 'root' : config['username']}'"
|
31
|
+
cmd << "--password='#{config['password']}'" unless config["password"].nil?
|
32
|
+
cmd << config["database"]
|
33
|
+
cmd << "| bzip2 > #{current_path}/db/#{rails_env}-data.sql.bz2"
|
34
|
+
run cmd.join(" ")
|
35
|
+
else
|
36
|
+
puts "Task not supported by '#{config['adapter']}'."
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
desc <<-DESC
|
41
|
+
Dump the database for the current environment and take a local copy.
|
42
|
+
DESC
|
43
|
+
task :download_backup, :roles => :db, :only => { :primary => true } do
|
44
|
+
backup
|
45
|
+
get "#{current_path}/db/#{rails_env}-data.sql.bz2", "db/#{rails_env}-data.sql.bz2"
|
46
|
+
end
|
47
|
+
|
48
|
+
desc <<-DESC
|
49
|
+
Load an existing database dump into the development environment's database.
|
50
|
+
DESC
|
51
|
+
task :load_backup do
|
52
|
+
run_locally "rake db:drop"
|
53
|
+
run_locally "rake db:create"
|
54
|
+
|
55
|
+
config = YAML::load(File.open("config/database.yml"))["development"]
|
56
|
+
case config["adapter"]
|
57
|
+
when "mysql"
|
58
|
+
cmd = ["bzcat db/#{rails_env}-data.sql.bz2 | mysql"]
|
59
|
+
cmd << "--host='#{config['host']}'" unless config["host"].nil?
|
60
|
+
cmd << "--user='#{config['username'].nil? ? 'root' : config['username']}'"
|
61
|
+
cmd << "--password='#{config['password']}'" unless config["password"].nil?
|
62
|
+
cmd << config["database"]
|
63
|
+
run_locally cmd.join(" ")
|
64
|
+
else
|
65
|
+
puts "Task not supported by '#{config['adapter']}'."
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
task :replicate do
|
70
|
+
download_backup
|
71
|
+
load_backup
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
on :load do
|
77
|
+
if fetch(:setup_database_after_deploy_setup, true)
|
78
|
+
after "deploy:setup", "capone:db:setup"
|
79
|
+
end
|
80
|
+
if fetch(:load_fixtures_to_database_after_deploy_cold, false)
|
81
|
+
after "deploy:cold", "capone:db:load_fixtures"
|
82
|
+
end
|
83
|
+
|
84
|
+
if fetch(:backup_database_before_migrations, false)
|
85
|
+
before "deploy:migrate", "capone:db:backup"
|
86
|
+
end
|
87
|
+
|
88
|
+
if fetch(:disable_web_during_migrations, false)
|
89
|
+
before "deploy:migrations", "deploy:web:disable"
|
90
|
+
after "deploy:migrations", "deploy:web:enable"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
depend :remote, :command, "mysql"
|
95
|
+
depend :remote, :command, "mysqldump"
|
96
|
+
depend :remote, :command, "bzip2"
|
data/recipes/defaults.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
set :scm, :git
|
2
|
+
set :deploy_via, :remote_cache
|
3
|
+
|
4
|
+
set :rails_env, "production"
|
5
|
+
|
6
|
+
set(:deploy_to) { "/var/www/apps/#{application}" }
|
7
|
+
|
8
|
+
role(:app) { host }
|
9
|
+
role(:web) { host }
|
10
|
+
role(:db, :primary => true) { host }
|
11
|
+
|
12
|
+
set :use_sudo, false
|
13
|
+
|
14
|
+
# Needed for proper password prompts
|
15
|
+
default_run_options[:pty] = true
|
16
|
+
|
17
|
+
# SSH options
|
18
|
+
ssh_options[:forward_agent] = true
|
19
|
+
|
20
|
+
# You can redefine these variables in your config/deploy.rb
|
21
|
+
|
22
|
+
# set :daemon_strategy, :mongrel_cluster
|
23
|
+
# set :web_server, :nginx
|
24
|
+
|
25
|
+
# set :install_gems, true
|
26
|
+
|
27
|
+
# set :backup_database_before_migrations, false
|
28
|
+
# set :disable_web_during_migrations, false
|
29
|
+
# set :setup_database_after_deploy_setup, true
|
30
|
+
# set :load_fixtures_to_database_after_deploy_cold, false
|
31
|
+
|
32
|
+
# set :whenever, false
|
33
|
+
# set :delayed_job, false
|
data/recipes/gems.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
namespace :capone do
|
2
|
+
namespace :gems do
|
3
|
+
desc <<-DESC
|
4
|
+
Install gems needed by application.
|
5
|
+
DESC
|
6
|
+
task :install, :roles => :app do
|
7
|
+
run "rake gems:install -f #{release_path}/Rakefile RAILS_ENV=#{rails_env}"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc <<-DESC
|
11
|
+
Update installed gems.
|
12
|
+
DESC
|
13
|
+
task :update, :roles => :app do
|
14
|
+
sudo "gem update --no-rdoc --no-ri"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
on :load do
|
20
|
+
if fetch(:install_gems, true)
|
21
|
+
after "deploy:update_code", "capone:gems:install"
|
22
|
+
end
|
23
|
+
end
|
data/recipes/nginx.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
namespace :capone do
|
2
|
+
namespace :nginx do
|
3
|
+
desc <<-DESC
|
4
|
+
Enable virtual host.
|
5
|
+
DESC
|
6
|
+
task :enable_vhost, :roles => :web do
|
7
|
+
sudo "ln -fs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
|
8
|
+
sudo "/etc/init.d/nginx reload"
|
9
|
+
end
|
10
|
+
|
11
|
+
desc <<-DESC
|
12
|
+
Disable virtual host.
|
13
|
+
DESC
|
14
|
+
task :disable_vhost, :roles => :web do
|
15
|
+
sudo "rm /etc/nginx/sites-enabled/#{application}"
|
16
|
+
sudo "/etc/init.d/nginx reload"
|
17
|
+
end
|
18
|
+
|
19
|
+
desc <<-DESC
|
20
|
+
Reload nginx configuration if the application nginx virtual host config file was changed.
|
21
|
+
DESC
|
22
|
+
task :reload_if_config_file_changed, :roles => :web do
|
23
|
+
run "bash -c \"if ! cmp #{previous_release}/config/nginx.conf #{current_path}/config/nginx.conf; then #{sudo} /etc/init.d/nginx reload; fi\""
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
on :load do
|
29
|
+
if fetch(:web_server, :nginx) == :nginx
|
30
|
+
before "deploy:start", "capone:nginx:enable_vhost"
|
31
|
+
after "deploy:stop", "capone:nginx:disable_vhost"
|
32
|
+
after "deploy:restart", "capone:nginx:reload_if_config_file_changed"
|
33
|
+
end
|
34
|
+
end
|
data/recipes/whenever.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
namespace :capone do
|
2
|
+
namespace :whenever do
|
3
|
+
desc <<-DESC
|
4
|
+
Update the crontab file with whenever.
|
5
|
+
DESC
|
6
|
+
task :update_crontab, :roles => :db do
|
7
|
+
whenever_command = fetch(:whenever_command, "whenever")
|
8
|
+
run "cd #{release_path} && #{whenever_command} --set environment=#{rails_env} --update-crontab #{deploy_to}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
on :load do
|
14
|
+
if fetch(:whenever, false)
|
15
|
+
after "deploy:symlink", "capone:whenever:update_crontab"
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dimkiriyenko-capone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 15
|
9
|
+
version: "0.15"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Denis Barushev
|
13
|
+
- Dmitriy Kiriyenko
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-20 00:00:00 +03:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: capistrano
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 27
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 5
|
33
|
+
- 0
|
34
|
+
version: 2.5.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: |-
|
38
|
+
Capone is the set of rake tasks and capistrano recipes.
|
39
|
+
Use it to avoid writing typical scenarios and maintaining them
|
40
|
+
in favour of configuring your builds and deploys declaratively.
|
41
|
+
email:
|
42
|
+
- barushev@gmail.com
|
43
|
+
- dmitriy.kiriyenko@gmail.com
|
44
|
+
executables: []
|
45
|
+
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
extra_rdoc_files: []
|
49
|
+
|
50
|
+
files:
|
51
|
+
- .gitignore
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
54
|
+
- LICENSE
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- capone.gemspec
|
58
|
+
- lib/capone.rb
|
59
|
+
- lib/capone/version.rb
|
60
|
+
- recipes/daemon_strategies/mongrel_cluster.rb
|
61
|
+
- recipes/daemon_strategies/passenger.rb
|
62
|
+
- recipes/daemon_strategy.rb
|
63
|
+
- recipes/db.rb
|
64
|
+
- recipes/defaults.rb
|
65
|
+
- recipes/delayed_job.rb
|
66
|
+
- recipes/gems.rb
|
67
|
+
- recipes/nginx.rb
|
68
|
+
- recipes/replicate.rb
|
69
|
+
- recipes/whenever.rb
|
70
|
+
has_rdoc: true
|
71
|
+
homepage: https://github.com/dmitriy-kiriyenko/capone
|
72
|
+
licenses: []
|
73
|
+
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
requirements: []
|
98
|
+
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.5.2
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Capone is the set of rake tasks and capistrano recipes.
|
104
|
+
test_files: []
|
105
|
+
|