sumodev_deploy 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,29 +1,35 @@
1
1
  configuration = Capistrano::Configuration.respond_to?(:instance) ? Capistrano::Configuration.instance(:must_exist) : Capistrano.configuration(:must_exist)
2
2
 
3
3
  configuration.load do
4
- def stop(msg)
5
- puts "\nStopped! \n\treason: #{msg}"
6
- exit 1
4
+ def _cset(name, *args, &block)
5
+ unless exists?(name)
6
+ set(name, *args, &block)
7
+ end
7
8
  end
8
9
 
9
- def client
10
- self[:client] || stop("sumodev_deploy requires that you set client and project names in your capfile")
11
- end
10
+ _cset(:client) { abort "sumodev_deploy requires that you set client and project names in your capfile" }
11
+ _cset(:project) { abort "sumodev_deploy requires that you set client and project names in your capfile"}
12
12
 
13
- def project
14
- self[:project] || stop("sumodev_deploy requires that you set client and project names in your capfile")
15
- end
13
+ _cset(:db_name) { "#{client[0,8]}_#{project[0,7]}"}
16
14
 
17
- def db_name
18
- fetch(:db_name) { "#{client[0,8]}_#{project[0,7]}"}
19
- end
15
+ _cset(:staging_server, 'dev.sumocoders.be')
16
+ _cset(:production_server, nil)
17
+ _cset(:app_servers) { production_server || staging_server }
18
+ _cset(:web_servers) { production_server || staging_server }
19
+ _cset(:db_server) { production_server || staging_server }
20
+
21
+ _cset(:user, 'sites')
22
+ _cset(:homedir) { "/home/#{user}/" }
23
+ _cset(:app_path) { "apps/#{client}/#{project}" }
24
+ _cset(:shared_files_path) { "#{shared_path}/files/"}
25
+ _cset(:document_root) { "#{homedir}#{client}/#{project}" }
20
26
 
21
- set :user, 'sites'
22
- set :application, project
23
- set :deploy_to,"/home/sites/apps/#{client}/#{application}"
24
- set :document_root, "/home/sites/#{client}/#{application}"
27
+ set(:application) { project }
28
+ set(:deploy_to) { "#{homedir}#{app_path}"}
25
29
 
26
- server 'dev.sumocoders.eu', :app, :web, :db, :primary => true
30
+ role(:app) { app_servers }
31
+ role(:web) { web_servers }
32
+ role(:db, :primary => true) { db_server }
27
33
 
28
34
  namespace :sumodev do
29
35
  namespace :db do
@@ -31,12 +37,16 @@ configuration.load do
31
37
  task :create, :roles => :db do
32
38
  run "create_db #{db_name}"
33
39
  end
40
+
41
+ desc "Dump the remote database, and outputs the content so you can pipe it"
42
+ task :dump, :roles => :db do
43
+ system %{ssh sites@#{db_server} mysqldump --set-charset #{db_name}}
44
+ end
34
45
 
35
46
  desc "Imports the database from the server into your local database"
36
47
  task :get, :roles => :db do
37
- # @todo Defv would be nice if this also worked on production server. I think we need some extra vars in the capfile for username, password and host. by default these can be the values used on the dev-server.
38
- system %{mysqladmin create #{db_name}}
39
- system %{ssh sites@dev.sumocoders.eu mysqldump --set-charset #{db_name} | mysql #{db_name}}
48
+ system %{mysqladmin create #{db_name}} # @todo Defv ignore errors
49
+ system %{ssh sites@#{db_server} mysqldump --set-charset #{db_name} | mysql #{db_name}}
40
50
  end
41
51
 
42
52
  desc "Get database info"
@@ -46,9 +56,8 @@ configuration.load do
46
56
 
47
57
  desc "Imports the database from your local server to the remote one"
48
58
  task :put, :roles => :db do
49
- # @todo Defv would be nice if this also worked on production server. I think we need some extra vars in the capfile for username, password and host. by default these can be the values used on the dev-server.
50
- system %{ssh sites@dev.sumocoders.eu "mysqldump --set-charset #{$db_name} > #{current_path}/#{release_name}.sql" }
51
- system %{mysqldump --set-charset #{db_name} | ssh sites@dev.sumocoders.eu mysql #{db_name}}
59
+ system %{ssh sites@#{db_server} "mysqldump --set-charset #{$db_name} > #{current_path}/#{release_name}.sql" }
60
+ system %{mysqldump --set-charset #{db_name} | ssh sites@#{db_server} #{db_name}}
52
61
  end
53
62
  end
54
63
 
@@ -65,13 +74,30 @@ configuration.load do
65
74
  end until path.root?
66
75
  end
67
76
 
77
+ def rsync(direction, from, to, options = {})
78
+ servers = find_servers_for_task(current_task)
79
+ servers = [servers.first] if options[:once]
80
+
81
+ servers.each do |server|
82
+ host_definition = "#{server.user || user}@#{server.host}"
83
+ host_definition << ":#{server.port}" if server.port && server.port != 22
84
+
85
+ case direction
86
+ when :down
87
+ run_locally "rsync -rtlpv #{host_definition}:#{from} #{to}"
88
+ when :up
89
+ run_locally "rsync -rtlp #{from} #{host_definition}:#{to}"
90
+ end
91
+ end
92
+ end
93
+
68
94
  desc "Sync all remote files to your local install"
69
95
  task :get, :roles => :app do
70
96
  path = find_folder_in_parents('frontend/files')
71
97
  if !path
72
- raise "No frontend/files folder found in this or upper folders. Are you sure you're in a Fork project?"
98
+ abort "No frontend/files folder found in this or upper folders. Are you sure you're in a Fork project?"
73
99
  else
74
- system %{rsync -rltp #{user}@dev.sumocoders.eu:#{shared_path}/files/ #{path}}
100
+ rsync :down, shared_files_path, path, :once => true
75
101
  end
76
102
  end
77
103
 
@@ -83,9 +109,9 @@ configuration.load do
83
109
  # check if folder exists
84
110
  path = find_folder_in_parents('frontend/files')
85
111
  if !path
86
- raise "No frontend/files folder found in this or upper folders. Are you sure you're in a Fork project?"
112
+ abort "No frontend/files folder found in this or upper folders. Are you sure you're in a Fork project?"
87
113
  else
88
- system %{rsync -rltp #{path} #{user}@dev.sumocoders.eu:#{shared_path}/files}
114
+ rsync :up, "#{path}/", shared_files_path
89
115
  end
90
116
  end
91
117
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "sumodev_deploy"
5
- s.version = "0.2.1"
5
+ s.version = "0.2.2"
6
6
 
7
7
  s.authors = ["Jan De Poorter"]
8
8
  s.date = "2012-04-18"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sumodev_deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: