capistrano-db-tasks 0.2.1 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -2,7 +2,7 @@ CapistranoDbTasks
2
2
  =================
3
3
 
4
4
  Add database AND assets tasks to capistrano to a Rails project.
5
- It only works with capistrano 2. Any pull requests for capistrano 3 support are welcome :)
5
+ It only works with capistrano 3. Older versions until 0.3 works with capistrano 2.
6
6
 
7
7
  Currently
8
8
 
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
- require 'rake/rdoctask'
3
+ require 'rdoc/task'
4
4
  require 'bundler'
5
5
  require 'bundler/gem_tasks'
6
6
 
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_development_dependency "capistrano", "> 2.0.0"
21
+ s.add_runtime_dependency "capistrano", ">= 3.0.0"
22
22
  end
@@ -2,22 +2,26 @@ module Asset
2
2
  extend self
3
3
 
4
4
  def remote_to_local(cap)
5
- servers = cap.find_servers :roles => :app
6
- port = cap.port rescue 22
7
- [cap.assets_dir].flatten.each do |dir|
8
- system("rsync -a --del -L -K -vv --progress --rsh='ssh -p #{port}' #{cap.user}@#{servers.first}:#{cap.current_path}/#{dir} #{cap.local_assets_dir}")
5
+ servers = Capistrano::Configuration.env.send(:servers)
6
+ server = servers.detect { |s| s.roles.include?(:app) }
7
+ port = server.netssh_options[:port] || 22
8
+ user = server.netssh_options[:user]
9
+ [cap.fetch(:assets_dir)].flatten.each do |dir|
10
+ system("rsync -a --del -L -K -vv --progress --rsh='ssh -p #{port}' #{user}@#{server}:#{cap.current_path}/#{dir} #{cap.fetch(:local_assets_dir)}")
9
11
  end
10
12
  end
11
13
 
12
14
  def local_to_remote(cap)
13
- servers = cap.find_servers :roles => :app
14
- port = cap.port rescue 22
15
- [cap.assets_dir].flatten.each do |dir|
16
- system("rsync -a --del -L -K -vv --progress --rsh='ssh -p #{port}' ./#{dir} #{cap.user}@#{servers.first}:#{cap.current_path}/#{cap.local_assets_dir}")
15
+ servers = Capistrano::Configuration.env.send(:servers)
16
+ server = servers.detect { |s| s.roles.include?(:app) }
17
+ port = server.netssh_options[:port] || 22
18
+ user = server.netssh_options[:user]
19
+ [cap.fetch(:assets_dir)].flatten.each do |dir|
20
+ system("rsync -a --del -L -K -vv --progress --rsh='ssh -p #{port}' ./#{dir} #{user}@#{server}:#{cap.current_path}/#{cap.fetch(:local_assets_dir)}")
17
21
  end
18
22
  end
19
23
 
20
24
  def to_string(cap)
21
- [cap.assets_dir].flatten.join(" ")
25
+ [cap.fetch(:assets_dir)].flatten.join(" ")
22
26
  end
23
27
  end
@@ -61,36 +61,33 @@ module Database
61
61
  class Remote < Base
62
62
  def initialize(cap_instance)
63
63
  super(cap_instance)
64
- @config = ""
65
- @cap.run("cat #{@cap.current_path}/config/database.yml") do |c, s, d|
66
- @config += d
67
- end
68
- @config = YAML.load(ERB.new(@config).result)[@cap.rails_env.to_s]
64
+ @config = @cap.capture("cat #{@cap.current_path}/config/database.yml")
65
+ @config = YAML.load(ERB.new(@config).result)[@cap.fetch(:rails_env).to_s]
69
66
  end
70
67
 
71
68
  def dump
72
- @cap.run "cd #{@cap.current_path} && #{dump_cmd} | bzip2 - - > #{output_file}"
69
+ @cap.execute "cd #{@cap.current_path} && #{dump_cmd} | bzip2 - - > #{output_file}"
73
70
  self
74
71
  end
75
72
 
76
73
  def download(local_file = "#{output_file}")
77
74
  remote_file = "#{@cap.current_path}/#{output_file}"
78
- @cap.get remote_file, local_file
75
+ @cap.download! remote_file, local_file
79
76
  end
80
77
 
81
78
  # cleanup = true removes the mysqldump file after loading, false leaves it in db/
82
79
  def load(file, cleanup)
83
80
  unzip_file = File.join(File.dirname(file), File.basename(file, '.bz2'))
84
81
  # @cap.run "cd #{@cap.current_path} && bunzip2 -f #{file} && RAILS_ENV=#{@cap.rails_env} bundle exec rake db:drop db:create && #{import_cmd(unzip_file)}"
85
- @cap.run "cd #{@cap.current_path} && bunzip2 -f #{file} && RAILS_ENV=#{@cap.rails_env} && #{import_cmd(unzip_file)}"
86
- @cap.run("cd #{@cap.current_path} && rm #{unzip_file}") if cleanup
82
+ @cap.execute "cd #{@cap.current_path} && bunzip2 -f #{file} && RAILS_ENV=#{@cap.fetch(:rails_env)} && #{import_cmd(unzip_file)}"
83
+ @cap.execute("cd #{@cap.current_path} && rm #{unzip_file}") if cleanup
87
84
  end
88
85
  end
89
86
 
90
87
  class Local < Base
91
88
  def initialize(cap_instance)
92
89
  super(cap_instance)
93
- @config = YAML.load(ERB.new(File.read(File.join('config', 'database.yml'))).result)[@cap.local_rails_env.to_s]
90
+ @config = YAML.load(ERB.new(File.read(File.join('config', 'database.yml'))).result)[fetch(:local_rails_env).to_s]
94
91
  puts "local #{@config}"
95
92
  end
96
93
 
@@ -98,15 +95,15 @@ module Database
98
95
  def load(file, cleanup)
99
96
  unzip_file = File.join(File.dirname(file), File.basename(file, '.bz2'))
100
97
  # system("bunzip2 -f #{file} && bundle exec rake db:drop db:create && #{import_cmd(unzip_file)} && bundle exec rake db:migrate")
101
- @cap.logger.info("executing local: bunzip2 -f #{file} && #{import_cmd(unzip_file)}")
98
+ @cap.info "executing local: bunzip2 -f #{file} && #{import_cmd(unzip_file)}"
102
99
  system("bunzip2 -f #{file} && #{import_cmd(unzip_file)}")
103
100
  if cleanup
104
- @cap.logger.info("removing #{unzip_file}")
101
+ @cap.info "removing #{unzip_file}"
105
102
  File.unlink(unzip_file)
106
103
  else
107
- @cap.logger.info("leaving #{unzip_file} (specify :db_local_clean in deploy.rb to remove)")
104
+ @cap.info "leaving #{unzip_file} (specify :db_local_clean in deploy.rb to remove)"
108
105
  end
109
- @cap.logger.info("Completed database import")
106
+ @cap.info "Completed database import"
110
107
  end
111
108
 
112
109
  def dump
@@ -116,7 +113,7 @@ module Database
116
113
 
117
114
  def upload
118
115
  remote_file = "#{@cap.current_path}/#{output_file}"
119
- @cap.upload output_file, remote_file
116
+ @cap.upload! output_file, remote_file
120
117
  end
121
118
  end
122
119
 
@@ -1,114 +1,102 @@
1
- if Capistrano::Configuration.instance(false)
2
-
3
- Capistrano::Configuration.instance(true).load do |instance|
4
-
5
- require File.expand_path("#{File.dirname(__FILE__)}/util")
6
- require File.expand_path("#{File.dirname(__FILE__)}/database")
7
- require File.expand_path("#{File.dirname(__FILE__)}/asset")
8
-
9
- instance.set :local_rails_env, ENV['RAILS_ENV'] || 'development' unless exists?(:local_rails_env)
10
- instance.set :rails_env, 'production' unless exists?(:rails_env)
11
- instance.set :db_local_clean, false unless exists?(:db_local_clean)
12
- instance.set :assets_dir, 'system' unless exists?(:assets_dir)
13
- instance.set :local_assets_dir, 'public' unless exists?(:local_assets_dir)
14
-
15
- namespace :db do
16
- namespace :remote do
17
- desc 'Synchronize your remote database using local database data'
18
- task :sync, :roles => :db do
19
- if Util.prompt 'Are you sure you want to REPLACE THE REMOTE DATABASE with local database'
20
- Database.local_to_remote(instance)
21
- end
1
+ require File.expand_path("#{File.dirname(__FILE__)}/util")
2
+ require File.expand_path("#{File.dirname(__FILE__)}/database")
3
+ require File.expand_path("#{File.dirname(__FILE__)}/asset")
4
+
5
+ set :local_rails_env, ENV['RAILS_ENV'] || 'development' unless fetch(:local_rails_env)
6
+ set :rails_env, 'production' unless fetch(:rails_env)
7
+ set :db_local_clean, false unless fetch(:db_local_clean)
8
+ set :assets_dir, 'system' unless fetch(:assets_dir)
9
+ set :local_assets_dir, 'public' unless fetch(:local_assets_dir)
10
+
11
+ namespace :db do
12
+ namespace :remote do
13
+ desc 'Synchronize your remote database using local database data'
14
+ task :sync do
15
+ on roles(:db) do
16
+ if Util.prompt 'Are you sure you want to REPLACE THE REMOTE DATABASE with local database'
17
+ Database.local_to_remote(self)
22
18
  end
23
19
  end
20
+ end
21
+ end
24
22
 
25
- namespace :local do
26
- desc 'Synchronize your local database using remote database data'
27
- task :sync, :roles => :db do
28
- puts "Local database: #{Database::Local.new(instance).database}"
29
- if Util.prompt 'Are you sure you want to erase your local database with server database'
30
- Database.remote_to_local(instance)
31
- end
23
+ namespace :local do
24
+ desc 'Synchronize your local database using remote database data'
25
+ task :sync do
26
+ on roles(:db) do
27
+ puts "Local database: #{Database::Local.new(self).database}"
28
+ if Util.prompt 'Are you sure you want to erase your local database with server database'
29
+ Database.remote_to_local(self)
32
30
  end
33
31
  end
32
+ end
33
+ end
34
34
 
35
- desc 'Synchronize your local database using remote database data'
36
- task :pull do
37
- db.local.sync
38
- end
35
+ desc 'Synchronize your local database using remote database data'
36
+ task :pull => "db:local:sync"
39
37
 
40
- desc 'Synchronize your remote database using local database data'
41
- task :push do
42
- db.remote.sync
43
- end
44
- end
38
+ desc 'Synchronize your remote database using local database data'
39
+ task :push => "db:remote:sync"
40
+ end
45
41
 
46
- namespace :assets do
47
- namespace :remote do
48
- desc 'Synchronize your remote assets using local assets'
49
- task :sync, :roles => :app do
50
- puts "Assets directories: #{assets_dir}"
51
- if Util.prompt "Are you sure you want to erase your server assets with local assets"
52
- Asset.local_to_remote(instance)
53
- end
42
+ namespace :assets do
43
+ namespace :remote do
44
+ desc 'Synchronize your remote assets using local assets'
45
+ task :sync do
46
+ on roles(:app) do
47
+ puts "Assets directories: #{fetch(:assets_dir)}"
48
+ if Util.prompt "Are you sure you want to erase your server assets with local assets"
49
+ Asset.local_to_remote(self)
54
50
  end
55
51
  end
52
+ end
53
+ end
56
54
 
57
- namespace :local do
58
- desc 'Synchronize your local assets using remote assets'
59
- task :sync, :roles => :app do
60
- puts "Assets directories: #{local_assets_dir}"
61
- if Util.prompt "Are you sure you want to erase your local assets with server assets"
62
- Asset.remote_to_local(instance)
63
- end
55
+ namespace :local do
56
+ desc 'Synchronize your local assets using remote assets'
57
+ task :sync do
58
+ on roles(:app) do
59
+ puts "Assets directories: #{fetch(:local_assets_dir)}"
60
+ if Util.prompt "Are you sure you want to erase your local assets with server assets"
61
+ Asset.remote_to_local(self)
64
62
  end
65
63
  end
66
-
67
- desc 'Synchronize your local assets using remote assets'
68
- task :pull do
69
- assets.local.sync
70
- end
71
-
72
- desc 'Synchronize your remote assets using local assets'
73
- task :push do
74
- assets.remote.sync
75
- end
76
64
  end
65
+ end
77
66
 
78
- namespace :app do
79
- namespace :remote do
80
- desc 'Synchronize your remote assets AND database using local assets and database'
81
- task :sync do
82
- if Util.prompt "Are you sure you want to REPLACE THE REMOTE DATABASE AND your remote assets with local database and assets(#{assets_dir})"
83
- Database.local_to_remote(instance)
84
- Asset.local_to_remote(instance)
85
- end
86
- end
87
- end
67
+ desc 'Synchronize your local assets using remote assets'
68
+ task :pull => "assets:local:sync"
88
69
 
89
- namespace :local do
90
- desc 'Synchronize your local assets AND database using remote assets and database'
91
- task :sync do
92
- puts "Local database : #{Database::Local.new(instance).database}"
93
- puts "Assets directories : #{local_assets_dir}"
94
- if Util.prompt "Are you sure you want to erase your local database AND your local assets with server database and assets(#{assets_dir})"
95
- Database.remote_to_local(instance)
96
- Asset.remote_to_local(instance)
97
- end
98
- end
99
- end
70
+ desc 'Synchronize your remote assets using local assets'
71
+ task :push => "assets:remote:sync"
72
+ end
100
73
 
101
- desc 'Synchronize your local assets AND database using remote assets and database'
102
- task :pull do
103
- app.local.sync
74
+ namespace :app do
75
+ namespace :remote do
76
+ desc 'Synchronize your remote assets AND database using local assets and database'
77
+ task :sync do
78
+ if Util.prompt "Are you sure you want to REPLACE THE REMOTE DATABASE AND your remote assets with local database and assets(#{assets_dir})"
79
+ Database.local_to_remote(self)
80
+ Asset.local_to_remote(self)
104
81
  end
82
+ end
83
+ end
105
84
 
106
- desc 'Synchronize your remote assets AND database using local assets and database'
107
- task :push do
108
- app.remote.sync
85
+ namespace :local do
86
+ desc 'Synchronize your local assets AND database using remote assets and database'
87
+ task :sync do
88
+ puts "Local database : #{Database::Local.new(self).database}"
89
+ puts "Assets directories : #{fetch(:local_assets_dir)}"
90
+ if Util.prompt "Are you sure you want to erase your local database AND your local assets with server database and assets(#{assets_dir})"
91
+ Database.remote_to_local(self)
92
+ Asset.remote_to_local(self)
109
93
  end
110
-
111
94
  end
112
95
  end
113
96
 
97
+ desc 'Synchronize your local assets AND database using remote assets and database'
98
+ task :pull => "app:local:sync"
99
+
100
+ desc 'Synchronize your remote assets AND database using local assets and database'
101
+ task :push => "app:remote:sync"
114
102
  end
@@ -1,10 +1,6 @@
1
1
  module Util
2
2
  def self.prompt(msg, prompt = "(y)es, (n)o ")
3
- answer = Capistrano::CLI.ui.ask("#{msg} #{prompt} ? ") do |q|
4
- q.overwrite = false
5
- q.validate = /^y$|^yes$|^n$|^no$/i
6
- q.responses[:not_valid] = prompt
7
- end
8
- (answer =~ /^y$|^yes$/i) == 0
3
+ ask(:answer, "#{msg} #{prompt} ? ")
4
+ (fetch(:answer) =~ /^y$|^yes$/i) == 0
9
5
  end
10
6
  end
@@ -1,3 +1,3 @@
1
1
  module CapistranoDbTasks
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-db-tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: '0.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -16,17 +16,17 @@ dependencies:
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>'
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 2.0.0
22
- type: :development
21
+ version: 3.0.0
22
+ type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>'
27
+ - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 2.0.0
29
+ version: 3.0.0
30
30
  description: A collection of capistrano tasks for syncing assets and databases
31
31
  email:
32
32
  - sebastien.gruhier@xilinus.com
@@ -61,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
61
  version: '0'
62
62
  segments:
63
63
  - 0
64
- hash: 22134957769426335
64
+ hash: 2376160182580984421
65
65
  required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  none: false
67
67
  requirements:
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  segments:
72
72
  - 0
73
- hash: 22134957769426335
73
+ hash: 2376160182580984421
74
74
  requirements: []
75
75
  rubyforge_project: capistrano-db-tasks
76
76
  rubygems_version: 1.8.23