soprano 0.61 → 0.90

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/soprano/db.rb ADDED
@@ -0,0 +1,88 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :soprano do
3
+ namespace :db do
4
+ desc <<-DESC
5
+ Create MySQL user and database using data from config/database.yml.
6
+ DESC
7
+ task :setup, :roles => :db, :only => { :primary => true } do
8
+ config = YAML::load(File.open("config/database.yml"))[rails_env]
9
+ root_password = Capistrano::CLI.password_prompt(prompt="Enter a root password for MySQL: ")
10
+
11
+ 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;\""
12
+ end
13
+
14
+ desc <<-DESC
15
+ Dumps the database for the current environment into db/env-data.sql.bz2.
16
+ Any existing backup will be overwritten.
17
+ DESC
18
+ task :backup, :roles => :db, :only => { :primary => true } do
19
+ config = YAML::load(File.open("config/database.yml"))[rails_env]
20
+ case config["adapter"]
21
+ when "mysql", "mysql2"
22
+ cmd = ["mysqldump"]
23
+ cmd << "--host='#{config['host']}'" unless config["host"].nil?
24
+ cmd << "--user='#{config['username'].nil? ? 'root' : config['username']}'"
25
+ cmd << "--password='#{config['password']}'" unless config["password"].nil?
26
+ cmd << config["database"]
27
+ cmd << "| bzip2 > #{current_path}/db/#{rails_env}-data.sql.bz2"
28
+ run cmd.join(" ")
29
+ else
30
+ puts "Task not supported by '#{config['adapter']}'."
31
+ end
32
+ end
33
+
34
+ desc <<-DESC
35
+ Dump the database for the current environment and take a local copy.
36
+ DESC
37
+ task :download_backup, :roles => :db, :only => { :primary => true } do
38
+ backup
39
+ get "#{current_path}/db/#{rails_env}-data.sql.bz2", "db/#{rails_env}-data.sql.bz2"
40
+ end
41
+
42
+ desc <<-DESC
43
+ Load an existing database dump into the development environment's database.
44
+ DESC
45
+ task :load_backup do
46
+ run_locally "rake db:drop"
47
+ run_locally "rake db:create"
48
+
49
+ config = YAML::load(File.open("config/database.yml"))["development"]
50
+ case config["adapter"]
51
+ when "mysql", "mysql2"
52
+ cmd = ["bzcat db/#{rails_env}-data.sql.bz2 | mysql"]
53
+ cmd << "--host='#{config['host']}'" unless config["host"].nil?
54
+ cmd << "--user='#{config['username'].nil? ? 'root' : config['username']}'"
55
+ cmd << "--password='#{config['password']}'" unless config["password"].nil?
56
+ cmd << config["database"]
57
+ run_locally cmd.join(" ")
58
+ else
59
+ puts "Task not supported by '#{config['adapter']}'."
60
+ end
61
+ end
62
+
63
+ task :replicate do
64
+ download_backup
65
+ load_backup
66
+ end
67
+ end
68
+ end
69
+
70
+ on :load do
71
+ if fetch(:setup_database_after_deploy_setup, false)
72
+ after "deploy:setup", "soprano:db:setup"
73
+ end
74
+
75
+ if fetch(:backup_database_before_migrations, false)
76
+ before "deploy:migrate", "soprano:db:backup"
77
+ end
78
+
79
+ if fetch(:disable_web_during_migrations, false)
80
+ before "deploy:migrations", "deploy:web:disable"
81
+ after "deploy:migrations", "deploy:web:enable"
82
+ end
83
+ end
84
+
85
+ depend :remote, :command, "mysql"
86
+ depend :remote, :command, "mysqldump"
87
+ depend :remote, :command, "bzip2"
88
+ end
@@ -0,0 +1,20 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ set :scm, :git
3
+ set :deploy_via, :remote_cache
4
+
5
+ set :rails_env, "production"
6
+
7
+ set(:deploy_to) { "/var/www/apps/#{application}" }
8
+
9
+ role(:app) { host }
10
+ role(:web) { host }
11
+ role(:db, :primary => true) { host }
12
+
13
+ set :use_sudo, false
14
+
15
+ # Needed for proper password prompts
16
+ default_run_options[:pty] = true
17
+
18
+ # SSH options
19
+ ssh_options[:forward_agent] = true
20
+ end
@@ -0,0 +1,9 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ on :load do
3
+ if fetch(:delayed_job, false)
4
+ after "deploy:stop", "delayed_job:stop"
5
+ after "deploy:start", "delayed_job:start"
6
+ after "deploy:restart", "delayed_job:restart"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,36 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :soprano do
3
+ namespace :nginx do
4
+ desc <<-DESC
5
+ Enable virtual host.
6
+ DESC
7
+ task :enable_vhost, :roles => :web do
8
+ sudo "ln -fs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
9
+ sudo "/etc/init.d/nginx reload"
10
+ end
11
+
12
+ desc <<-DESC
13
+ Disable virtual host.
14
+ DESC
15
+ task :disable_vhost, :roles => :web do
16
+ sudo "rm /etc/nginx/sites-enabled/#{application}"
17
+ sudo "/etc/init.d/nginx reload"
18
+ end
19
+
20
+ desc <<-DESC
21
+ Reload nginx configuration if the application nginx virtual host config file was changed.
22
+ DESC
23
+ task :reload_if_config_file_changed, :roles => :web do
24
+ run "bash -c \"if ! cmp #{previous_release}/config/nginx.conf #{current_path}/config/nginx.conf; then #{sudo} /etc/init.d/nginx reload; fi\""
25
+ end
26
+ end
27
+ end
28
+
29
+ on :load do
30
+ if fetch(:link_vhost_from_app, true)
31
+ before "deploy:start", "soprano:nginx:enable_vhost"
32
+ after "deploy:stop", "soprano:nginx:disable_vhost"
33
+ after "deploy:restart", "soprano:nginx:reload_if_config_file_changed"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :deploy do
3
+ desc "Start application."
4
+ task :start, :roles => :app do
5
+ run "touch #{current_release}/tmp/restart.txt"
6
+ end
7
+
8
+ desc "Stop application."
9
+ task :stop, :roles => :app do
10
+ end
11
+
12
+ desc "Restart application."
13
+ task :restart, :roles => :app do
14
+ run "touch #{current_release}/tmp/restart.txt"
15
+ end
16
+ end
17
+
18
+ depend :remote, :gem, "passenger", ">=2.2.2"
19
+ end
@@ -0,0 +1,45 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :remote do
3
+ def get_cmd
4
+ cmd = self[:cmd]
5
+ raise "A command must be given. Pleae, call the task with -s cmd=\"your command\"" unless cmd
6
+ cmd
7
+ end
8
+
9
+ def remote_call(command)
10
+ run wrap_command(command) do |channel, stream, data|
11
+ puts "#{data}"
12
+ break if stream == :err
13
+ end
14
+ end
15
+
16
+ def wrap_command(command)
17
+ "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec #{command}"
18
+ end
19
+
20
+ desc "execute an arbitrary command from application folder"
21
+ task "command", :roles => :app do
22
+ remote_call get_cmd
23
+ end
24
+
25
+ desc "execute an arbitrary rake task from application folder"
26
+ task "rake", :roles => :app do
27
+ remote_call "rake #{get_cmd}"
28
+ end
29
+
30
+ desc "execute an arbitrary thor script from application folder"
31
+ task "thor", :roles => :app do
32
+ remote_call "thor #{get_cmd}"
33
+ end
34
+
35
+ desc "execute an arbitrary ruby script in application environment"
36
+ task "runner", :roles => :app do
37
+ remote_call "script/rails runner \"#{get_cmd}\""
38
+ end
39
+
40
+ desc "tail the application log"
41
+ task :tail, :roles => :app do
42
+ remote_call("tail -n 10000 -f log/#{rails_env}.log")
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,32 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ def unicorn_conf
3
+ fetch(:unicorn_conf, "#{current_path}/config/unicorn.rb")
4
+ end
5
+
6
+ def unicorn_bin
7
+ fetch(:unicorn_bin, 'bundle exec unicorn')
8
+ end
9
+
10
+ def unicorn_pid
11
+ fetch(:unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid")
12
+ end
13
+
14
+ namespace :deploy do
15
+ desc "Start application."
16
+ task :start, :roles => :app do
17
+ run "cd #{current_path} && #{unicorn_bin} -c #{unicorn_conf} -E #{rails_env} -D"
18
+ end
19
+
20
+ desc "Stop application."
21
+ task :stop, :roles => :app do
22
+ run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -QUIT `cat #{unicorn_pid}`; fi"
23
+ end
24
+
25
+ desc "Restart application."
26
+ task :restart, :roles => :app do
27
+ run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -USR2 `cat #{unicorn_pid}`; else cd #{current_path} && #{unicorn_bin} -c #{unicorn_conf} -E #{rails_env} -D; fi"
28
+ end
29
+ end
30
+
31
+ depend :remote, :gem, "passenger", ">=2.2.2"
32
+ end
@@ -1,3 +1,3 @@
1
- module Capone
2
- VERSION = "0.61"
1
+ module Soprano
2
+ VERSION = "0.90"
3
3
  end
data/lib/soprano.rb CHANGED
@@ -1,9 +1,4 @@
1
- unless Capistrano::Configuration.respond_to?(:instance)
2
- abort "Soprano requires Capistrano 2"
3
- end
4
-
5
- Capistrano::Configuration.instance.load do
6
- Dir["#{File.dirname(__FILE__)}/../recipes/*.rb"].each do |recipe|
7
- load(recipe)
8
- end
9
- end
1
+ require 'soprano/version'
2
+ require 'soprano/defaults'
3
+ require 'soprano/remote'
4
+ require 'soprano/db'
data/soprano.gemspec CHANGED
@@ -4,7 +4,7 @@ require "soprano/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "soprano"
7
- s.version = Capone::VERSION
7
+ s.version = Soprano::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Dmitriy Kiriyenko"]
10
10
  s.email = ["dmitriy.kiriyenko@gmail.com"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soprano
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.61'
4
+ version: '0.90'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -59,16 +59,14 @@ files:
59
59
  - README.md
60
60
  - Rakefile
61
61
  - lib/soprano.rb
62
+ - lib/soprano/db.rb
63
+ - lib/soprano/defaults.rb
64
+ - lib/soprano/delayed_job.rb
65
+ - lib/soprano/nginx_vhost.rb
66
+ - lib/soprano/passenger.rb
67
+ - lib/soprano/remote.rb
68
+ - lib/soprano/unicorn.rb
62
69
  - lib/soprano/version.rb
63
- - recipes/daemon_strategy.rb
64
- - recipes/db.rb
65
- - recipes/defaults.rb
66
- - recipes/delayed_job.rb
67
- - recipes/nginx.rb
68
- - recipes/remote.rb
69
- - recipes/replicate.rb
70
- - recipes/servers/mongrel_cluster.rb
71
- - recipes/servers/passenger.rb
72
70
  - soprano.gemspec
73
71
  homepage: https://github.com/dmitriy-kiriyenko/soprano
74
72
  licenses: []
@@ -1,10 +0,0 @@
1
- on :load do
2
- strategy = fetch(:daemon_strategy, nil)
3
-
4
- if strategy && [:passenger, :mongrel_cluster].include?(strategy)
5
- puts "Providing strategy via set :daemon_strategy, #{strategy} is deprecated!"
6
- puts "Use require 'servers/#{strategy}' instead."
7
-
8
- load File.join(File.dirname(__FILE__), "servers", "#{strategy}.rb")
9
- end
10
- end
data/recipes/db.rb DELETED
@@ -1,97 +0,0 @@
1
- namespace :soprano 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", "mysql2"
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", "mysql2"
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", "soprano:db:setup"
79
- end
80
-
81
- if fetch(:load_fixtures_to_database_after_deploy_cold, false)
82
- after "deploy:cold", "soprano:db:load_fixtures"
83
- end
84
-
85
- if fetch(:backup_database_before_migrations, false)
86
- before "deploy:migrate", "soprano:db:backup"
87
- end
88
-
89
- if fetch(:disable_web_during_migrations, false)
90
- before "deploy:migrations", "deploy:web:disable"
91
- after "deploy:migrations", "deploy:web:enable"
92
- end
93
- end
94
-
95
- depend :remote, :command, "mysql"
96
- depend :remote, :command, "mysqldump"
97
- depend :remote, :command, "bzip2"
data/recipes/defaults.rb DELETED
@@ -1,30 +0,0 @@
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 :install_gems, true
23
-
24
- # set :backup_database_before_migrations, false
25
- # set :disable_web_during_migrations, false
26
- # set :setup_database_after_deploy_setup, true
27
- # set :load_fixtures_to_database_after_deploy_cold, false
28
-
29
- # set :whenever, false
30
- # set :delayed_job, false
@@ -1,7 +0,0 @@
1
- on :load do
2
- if fetch(:delayed_job, false)
3
- after "deploy:stop", "delayed_job:stop"
4
- after "deploy:start", "delayed_job:start"
5
- after "deploy:restart", "delayed_job:restart"
6
- end
7
- end
data/recipes/nginx.rb DELETED
@@ -1,34 +0,0 @@
1
- namespace :soprano 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(:link_vhost_from_app, false)
30
- before "deploy:start", "soprano:nginx:enable_vhost"
31
- after "deploy:stop", "soprano:nginx:disable_vhost"
32
- after "deploy:restart", "soprano:nginx:reload_if_config_file_changed"
33
- end
34
- end
data/recipes/remote.rb DELETED
@@ -1,43 +0,0 @@
1
- namespace :remote do
2
- def get_cmd
3
- cmd = self[:cmd]
4
- raise "A command must be given. Pleae, call the task with -s cmd=\"your command\"" unless cmd
5
- cmd
6
- end
7
-
8
- def remote_call(command)
9
- run wrap_command(command) do |channel, stream, data|
10
- puts "#{data}"
11
- break if stream == :err
12
- end
13
- end
14
-
15
- def wrap_command(command)
16
- "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec #{command}"
17
- end
18
-
19
- desc "execute an arbitrary command from application folder"
20
- task "command", :roles => :app do
21
- remote_call get_cmd
22
- end
23
-
24
- desc "execute an arbitrary rake task from application folder"
25
- task "rake", :roles => :app do
26
- remote_call "rake #{get_cmd}"
27
- end
28
-
29
- desc "execute an arbitrary thor script from application folder"
30
- task "thor", :roles => :app do
31
- remote_call "thor #{get_cmd}"
32
- end
33
-
34
- desc "execute an arbitrary ruby script in application environment"
35
- task "runner", :roles => :app do
36
- remote_call "script/rails runner \"#{get_cmd}\""
37
- end
38
-
39
- desc "tail the application log"
40
- task :tail, :roles => :app do
41
- remote_call("tail -n 10000 -f log/#{rails_env}.log")
42
- end
43
- end
data/recipes/replicate.rb DELETED
@@ -1,3 +0,0 @@
1
- task :replicate do
2
- soprano.db.replicate
3
- end
@@ -1,6 +0,0 @@
1
- require "mongrel_cluster/recipes"
2
-
3
- set :mongrel_conf, "#{deploy_to}/current/config/mongrel_cluster.yml"
4
-
5
- depend :remote, :gem, "mongrel", ">=1.1.5"
6
- depend :remote, :gem, "mongrel_cluster", ">=1.0.5"
@@ -1,17 +0,0 @@
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"