screcipes 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  Capistrano::Configuration.instance.load do
2
2
  _cset :normal_symlinks, %w(
3
3
  config/database.yml
4
+ public/assets/
4
5
  )
5
6
 
6
7
  _cset :weird_symlinks, {
@@ -13,188 +13,190 @@ require 'pathname'
13
13
  # Released under the MIT license.
14
14
  # Kindly sponsored by Screen Concept, www.screenconcept.ch
15
15
  #
16
- namespace :sync do
16
+ Capistrano::Configuration.instance.load do
17
+ namespace :sync do
17
18
 
18
- after "deploy:setup", "sync:setup"
19
-
20
- desc <<-DESC
21
- Creates the sync dir in shared path. The sync directory is used to keep
22
- backups of database dumps and archives from synced directories. This task will
23
- be called on 'deploy:setup'
24
- DESC
25
- task :setup do
26
- run "cd #{shared_path}; mkdir sync"
27
- end
28
-
29
- namespace :down do
19
+ after "deploy:setup", "sync:setup"
30
20
 
31
21
  desc <<-DESC
32
- Syncs the database and declared directories from the selected multi_stage environment
33
- to the local development environment. This task simply calls both the 'sync:down:db' and
34
- 'sync:down:fs' tasks.
22
+ Creates the sync dir in shared path. The sync directory is used to keep
23
+ backups of database dumps and archives from synced directories. This task will
24
+ be called on 'deploy:setup'
35
25
  DESC
36
- task :default do
37
- db and fs
26
+ task :setup do
27
+ run "cd #{shared_path}; mkdir sync"
38
28
  end
39
29
 
40
- desc <<-DESC
41
- Syncs database from the selected mutli_stage environement to the local develoment environment.
42
- The database credentials will be read from your local config/database.yml file and a copy of the
43
- dump will be kept within the shared sync directory. The amount of backups that will be kept is
44
- declared in the sync_backups variable and defaults to 5.
45
- DESC
46
- task :db, :roles => :db, :only => { :primary => true } do
47
-
48
- filename = "database.#{stage}.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2"
49
- on_rollback { delete "#{shared_path}/sync/#{filename}" }
30
+ namespace :down do
50
31
 
51
- # Remote DB dump
52
- username, password, database = database_config(stage)
53
- run "mysqldump -u #{username} --password='#{password}' #{database} | bzip2 -9 > #{shared_path}/sync/#{filename}" do |channel, stream, data|
54
- puts data
32
+ desc <<-DESC
33
+ Syncs the database and declared directories from the selected multi_stage environment
34
+ to the local development environment. This task simply calls both the 'sync:down:db' and
35
+ 'sync:down:fs' tasks.
36
+ DESC
37
+ task :default do
38
+ db and fs
55
39
  end
56
- purge_old_backups "database"
57
40
 
58
- # Download dump
59
- download "#{shared_path}/sync/#{filename}", filename
41
+ desc <<-DESC
42
+ Syncs database from the selected mutli_stage environement to the local develoment environment.
43
+ The database credentials will be read from your local config/database.yml file and a copy of the
44
+ dump will be kept within the shared sync directory. The amount of backups that will be kept is
45
+ declared in the sync_backups variable and defaults to 5.
46
+ DESC
47
+ task :db, :roles => :db, :only => { :primary => true } do
48
+
49
+ filename = "database.#{stage}.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2"
50
+ on_rollback { delete "#{shared_path}/sync/#{filename}" }
51
+
52
+ # Remote DB dump
53
+ username, password, database = database_config(stage)
54
+ run "mysqldump -u #{username} --password='#{password}' #{database} | bzip2 -9 > #{shared_path}/sync/#{filename}" do |channel, stream, data|
55
+ puts data
56
+ end
57
+ purge_old_backups "database"
60
58
 
61
- # Local DB import
62
- username, password, database = database_config('development')
63
- system "bzip2 -d -c #{filename} | mysql -u #{username} --password='#{password}' #{database}; rm -f #{filename}"
59
+ # Download dump
60
+ download "#{shared_path}/sync/#{filename}", filename
64
61
 
65
- logger.important "sync database from the stage '#{stage}' to local finished"
66
- end
67
-
68
- desc <<-DESC
69
- Sync declared directories from the selected multi_stage environment to the local development
70
- environment. The synced directories must be declared as an array of Strings with the sync_directories
71
- variable. The path is relative to the rails root.
72
- DESC
73
- task :fs, :roles => :web, :once => true do
62
+ # Local DB import
63
+ username, password, database = database_config('development')
64
+ system "bzip2 -d -c #{filename} | mysql -u #{username} --password='#{password}' #{database}; rm -f #{filename}"
74
65
 
75
- server, port = host_and_port
66
+ logger.important "sync database from the stage '#{stage}' to local finished"
67
+ end
76
68
 
77
- Array(fetch(:sync_directories, [])).each do |syncdir|
78
- unless File.directory? "#{syncdir}"
79
- logger.info "create local '#{syncdir}' folder"
80
- Dir.mkdir "#{syncdir}"
69
+ desc <<-DESC
70
+ Sync declared directories from the selected multi_stage environment to the local development
71
+ environment. The synced directories must be declared as an array of Strings with the sync_directories
72
+ variable. The path is relative to the rails root.
73
+ DESC
74
+ task :fs, :roles => :web, :once => true do
75
+
76
+ server, port = host_and_port
77
+
78
+ Array(fetch(:sync_directories, [])).each do |syncdir|
79
+ unless File.directory? "#{syncdir}"
80
+ logger.info "create local '#{syncdir}' folder"
81
+ Dir.mkdir "#{syncdir}"
82
+ end
83
+ logger.info "sync #{syncdir} from #{server}:#{port} to local"
84
+ destination, base = Pathname.new(syncdir).split
85
+ system "rsync --verbose --archive --compress --copy-links --delete --stats --rsh='ssh -p #{port}' #{user}@#{server}:#{shared_path}/#{syncdir} #{destination.to_s}"
81
86
  end
82
- logger.info "sync #{syncdir} from #{server}:#{port} to local"
83
- destination, base = Pathname.new(syncdir).split
84
- system "rsync --verbose --archive --compress --copy-links --delete --stats --rsh='ssh -p #{port}' #{user}@#{server}:#{shared_path}/#{syncdir} #{destination.to_s}"
87
+
88
+ logger.important "sync filesystem from the stage '#{stage}' to local finished"
85
89
  end
86
90
 
87
- logger.important "sync filesystem from the stage '#{stage}' to local finished"
88
91
  end
89
92
 
90
- end
93
+ namespace :up do
91
94
 
92
- namespace :up do
95
+ desc <<-DESC
96
+ Syncs the database and declared directories from the local development environment
97
+ to the selected multi_stage environment. This task simply calls both the 'sync:up:db' and
98
+ 'sync:up:fs' tasks.
99
+ DESC
100
+ task :default do
101
+ db and fs
102
+ end
93
103
 
94
- desc <<-DESC
95
- Syncs the database and declared directories from the local development environment
96
- to the selected multi_stage environment. This task simply calls both the 'sync:up:db' and
97
- 'sync:up:fs' tasks.
98
- DESC
99
- task :default do
100
- db and fs
101
- end
104
+ desc <<-DESC
105
+ Syncs database from the local develoment environment to the selected mutli_stage environement.
106
+ The database credentials will be read from your local config/database.yml file and a copy of the
107
+ dump will be kept within the shared sync directory. The amount of backups that will be kept is
108
+ declared in the sync_backups variable and defaults to 5.
109
+ DESC
110
+ task :db, :roles => :db, :only => { :primary => true } do
102
111
 
103
- desc <<-DESC
104
- Syncs database from the local develoment environment to the selected mutli_stage environement.
105
- The database credentials will be read from your local config/database.yml file and a copy of the
106
- dump will be kept within the shared sync directory. The amount of backups that will be kept is
107
- declared in the sync_backups variable and defaults to 5.
108
- DESC
109
- task :db, :roles => :db, :only => { :primary => true } do
112
+ filename = "database.#{stage}.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2"
110
113
 
111
- filename = "database.#{stage}.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2"
114
+ on_rollback do
115
+ delete "#{shared_path}/sync/#{filename}"
116
+ system "rm -f #{filename}"
117
+ end
118
+
119
+ # Make a backup before importing
120
+ username, password, database = database_config(stage)
121
+ run "mysqldump -u #{username} --password='#{password}' #{database} | bzip2 -9 > #{shared_path}/sync/#{filename}" do |channel, stream, data|
122
+ puts data
123
+ end
112
124
 
113
- on_rollback do
114
- delete "#{shared_path}/sync/#{filename}"
125
+ # Local DB export
126
+ filename = "dump.local.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2"
127
+ username, password, database = database_config('development')
128
+ system "mysqldump -u #{username} --password='#{password}' #{database} | bzip2 -9 > #{filename}"
129
+ upload filename, "#{shared_path}/sync/#{filename}"
115
130
  system "rm -f #{filename}"
116
- end
117
131
 
118
- # Make a backup before importing
119
- username, password, database = database_config(stage)
120
- run "mysqldump -u #{username} --password='#{password}' #{database} | bzip2 -9 > #{shared_path}/sync/#{filename}" do |channel, stream, data|
121
- puts data
132
+ # Remote DB import
133
+ username, password, database = database_config(stage)
134
+ run "bzip2 -d -c #{shared_path}/sync/#{filename} | mysql -u #{username} --password='#{password}' #{database}; rm -f #{shared_path}/sync/#{filename}"
135
+ purge_old_backups "database"
136
+
137
+ logger.important "sync database from local to the stage '#{stage}' finished"
122
138
  end
123
139
 
124
- # Local DB export
125
- filename = "dump.local.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2"
126
- username, password, database = database_config('development')
127
- system "mysqldump -u #{username} --password='#{password}' #{database} | bzip2 -9 > #{filename}"
128
- upload filename, "#{shared_path}/sync/#{filename}"
129
- system "rm -f #{filename}"
140
+ desc <<-DESC
141
+ Sync declared directories from the local development environement to the selected multi_stage
142
+ environment. The synced directories must be declared as an array of Strings with the sync_directories
143
+ variable. The path is relative to the rails root.
144
+ DESC
145
+ task :fs, :roles => :web, :once => true do
146
+
147
+ server, port = host_and_port
148
+ Array(fetch(:sync_directories, [])).each do |syncdir|
149
+ destination, base = Pathname.new(syncdir).split
150
+ if File.directory? "#{syncdir}"
151
+ # Make a backup
152
+ logger.info "backup #{syncdir}"
153
+ run "tar cjf #{shared_path}/sync/#{base}.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.tar.bz2 #{shared_path}/#{syncdir}"
154
+ purge_old_backups "#{base}"
155
+ else
156
+ logger.info "Create '#{syncdir}' directory"
157
+ run "mkdir #{current_path}/#{syncdir}"
158
+ end
159
+
160
+ # Sync directory up
161
+ logger.info "sync #{syncdir} to #{server}:#{port} from local"
162
+ system "rsync --verbose --archive --compress --keep-dirlinks --delete --stats --rsh='ssh -p #{port}' #{syncdir} #{user}@#{server}:#{shared_path}/#{destination.to_s}"
163
+ end
164
+ logger.important "sync filesystem from local to the stage '#{stage}' finished"
165
+ end
130
166
 
131
- # Remote DB import
132
- username, password, database = database_config(stage)
133
- run "bzip2 -d -c #{shared_path}/sync/#{filename} | mysql -u #{username} --password='#{password}' #{database}; rm -f #{shared_path}/sync/#{filename}"
134
- purge_old_backups "database"
167
+ end
135
168
 
136
- logger.important "sync database from local to the stage '#{stage}' finished"
169
+ #
170
+ # Reads the database credentials from the local config/database.yml file
171
+ # +db+ the name of the environment to get the credentials for
172
+ # Returns username, password, database
173
+ #
174
+ def database_config(db)
175
+ database = YAML::load_file('config/database.yml')
176
+ return database["#{db}"]['username'], database["#{db}"]['password'], database["#{db}"]['database']
137
177
  end
138
178
 
139
- desc <<-DESC
140
- Sync declared directories from the local development environement to the selected multi_stage
141
- environment. The synced directories must be declared as an array of Strings with the sync_directories
142
- variable. The path is relative to the rails root.
143
- DESC
144
- task :fs, :roles => :web, :once => true do
145
-
146
- server, port = host_and_port
147
- Array(fetch(:sync_directories, [])).each do |syncdir|
148
- destination, base = Pathname.new(syncdir).split
149
- if File.directory? "#{syncdir}"
150
- # Make a backup
151
- logger.info "backup #{syncdir}"
152
- run "tar cjf #{shared_path}/sync/#{base}.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.tar.bz2 #{shared_path}/#{syncdir}"
153
- purge_old_backups "#{base}"
154
- else
155
- logger.info "Create '#{syncdir}' directory"
156
- run "mkdir #{current_path}/#{syncdir}"
157
- end
179
+ #
180
+ # Returns the actual host name to sync and port
181
+ #
182
+ def host_and_port
183
+ return roles[:web].servers.first.host, ssh_options[:port] || roles[:web].servers.first.port || 22
184
+ end
158
185
 
159
- # Sync directory up
160
- logger.info "sync #{syncdir} to #{server}:#{port} from local"
161
- system "rsync --verbose --archive --compress --keep-dirlinks --delete --stats --rsh='ssh -p #{port}' #{syncdir} #{user}@#{server}:#{shared_path}/#{destination.to_s}"
186
+ #
187
+ # Purge old backups within the shared sync directory
188
+ #
189
+ def purge_old_backups(base)
190
+ count = fetch(:sync_backups, 5).to_i
191
+ backup_files = capture("ls -xt #{shared_path}/sync/#{base}*").split.reverse
192
+ if count >= backup_files.length
193
+ logger.important "no old backups to clean up"
194
+ else
195
+ logger.info "keeping #{count} of #{backup_files.length} sync backups"
196
+ delete_backups = (backup_files - backup_files.last(count)).join(" ")
197
+ try_sudo "rm -rf #{delete_backups}"
162
198
  end
163
- logger.important "sync filesystem from local to the stage '#{stage}' finished"
164
199
  end
165
200
 
166
201
  end
167
-
168
- #
169
- # Reads the database credentials from the local config/database.yml file
170
- # +db+ the name of the environment to get the credentials for
171
- # Returns username, password, database
172
- #
173
- def database_config(db)
174
- database = YAML::load_file('config/database.yml')
175
- return database["#{db}"]['username'], database["#{db}"]['password'], database["#{db}"]['database']
176
- end
177
-
178
- #
179
- # Returns the actual host name to sync and port
180
- #
181
- def host_and_port
182
- return roles[:web].servers.first.host, ssh_options[:port] || roles[:web].servers.first.port || 22
183
- end
184
-
185
- #
186
- # Purge old backups within the shared sync directory
187
- #
188
- def purge_old_backups(base)
189
- count = fetch(:sync_backups, 5).to_i
190
- backup_files = capture("ls -xt #{shared_path}/sync/#{base}*").split.reverse
191
- if count >= backup_files.length
192
- logger.important "no old backups to clean up"
193
- else
194
- logger.info "keeping #{count} of #{backup_files.length} sync backups"
195
- delete_backups = (backup_files - backup_files.last(count)).join(" ")
196
- try_sudo "rm -rf #{delete_backups}"
197
- end
198
- end
199
-
200
202
  end
@@ -1,3 +1,3 @@
1
1
  module Screcipes
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: screcipes
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors: []
13
13
 
@@ -49,7 +49,6 @@ files:
49
49
  - Rakefile
50
50
  - lib/screcipes.rb
51
51
  - lib/screcipes/capistrano.rb
52
- - lib/screcipes/capistrano/assets.rb
53
52
  - lib/screcipes/capistrano/defaults.rb
54
53
  - lib/screcipes/capistrano/deploy.rb
55
54
  - lib/screcipes/capistrano/kickstart.rb
@@ -1,8 +0,0 @@
1
- namespace :assets do
2
- desc "Symlink assets"
3
- task :symlink do
4
- run "ln -s #{shared_path}/public/assets #{current_path}/public/assets"
5
- end
6
- end
7
-
8
- after "deploy:symlink", "assets:symlink"