capidiem 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/CHANGELOG +27 -0
  2. data/LICENSE +23 -0
  3. data/README.md +133 -0
  4. data/bin/capidiem +77 -0
  5. data/lib/capidiem.rb +568 -0
  6. metadata +71 -0
data/CHANGELOG ADDED
@@ -0,0 +1,27 @@
1
+ == 0.0.1 / June 29, 2010
2
+
3
+ * fork from Konstantin Kudryashov version (http://everzet.com/projects/symfony-helpers/capifony)
4
+
5
+ == 0.0.2 / July 3, 2010
6
+
7
+ * bugfix for dm:clear-cache task name
8
+ * fixed a f**g typo error and removed unused functions
9
+ * fixed syntax errors
10
+ * fixed typo error in gemspec
11
+ * fixed version error in gemspec
12
+ * renamed capifony gemspec
13
+ * some update, normally this is the working version…
14
+ * update finalize update, diem only need the last one
15
+ * some typo updates
16
+ * fixed typo in doc
17
+ * added dmAdmin clear module command in diem namespace
18
+ * added dm namespace
19
+ * renamed false rename of diem tasks to symfony one, removed propel orm part
20
+ * syntax update
21
+ * renamed capifony.rb to capidiem.rb and bin/capifony
22
+ * removed orm guessing, diem only use doctrine
23
+ * readme update
24
+ * license update
25
+ * initial changelog update
26
+ * updated gemspec file
27
+ * renamed all symfony, Symfony, capyfony, Capyfony instances
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2010 Konstantin Kudryashov <ever.zet@gmail.com>
2
+ Copyright (c) 2010 Mickael Kurmann <mickael.kurmann@gmail.com>
3
+
4
+ Permission is hereby granted, free of charge, to any person
5
+ obtaining a copy of this software and associated documentation
6
+ files (the "Software"), to deal in the Software without
7
+ restriction, including without limitation the rights to use,
8
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the
10
+ Software is furnished to do so, subject to the following
11
+ conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,133 @@
1
+ Deploying diem Applications with Capistrano
2
+ ==============================================
3
+
4
+ Capistrano is an open source tool for running scripts on multiple servers. It’s primary use is for easily deploying applications. While it was built specifically for deploying Rails apps, it’s pretty simple to customize it to deploy other types of applications. We’ve been working on creating a deployment “recipe” to work with diem applications to make our job a lot easier.
5
+
6
+ ## Prerequisites ##
7
+
8
+ - Must have SSH access to the server you are deploying to.
9
+ - Must have Ruby and RubyGems installed on your machine (not required for deployment server)’
10
+
11
+ ## Installing Capidiem ##
12
+
13
+ ### Through RubyGems.org ###
14
+
15
+ sudo gem install capidiem
16
+
17
+ ### Through GitHub ###
18
+
19
+ git clone git@github.com:elbouillon/capidiem.git
20
+ cd capidiem
21
+ gem build capidiem.gemspec
22
+ sudo gem install capidiem-{version}.gem
23
+
24
+ ## Setup your project to use Capidiem ##
25
+
26
+ CD to your project directory & run:
27
+
28
+ capidiem .
29
+
30
+ This will create `Capfile` in your project root & `deploy.rb` config file in `config` directory
31
+
32
+ Fill up your `config/deploy.rb` with your server connection data
33
+
34
+ ## Server Setup ##
35
+
36
+ Now, you can start the deployment process! To get your server setup with the file structure that Capistrano expects, you can run:
37
+
38
+ cap deploy:setup
39
+
40
+ This command will create the following folder structure on your server:
41
+
42
+ `-- /var/www/demo.everzet.com
43
+ |-- current → /var/www/demo.everzet.com/releases/20100512131539
44
+ |-- releases
45
+ |-- 20100512131539
46
+ |-- 20100509150741
47
+ `-- 20100509145325
48
+ `-- shared
49
+ |-- log
50
+ |-- config
51
+ `-- databases.yml
52
+ `-- web
53
+ `-- uploads
54
+
55
+ The folders in the releases directory will be the actual deployed code, timestamped. Capistrano symlinks your log & web/uploads directories from your app to the directories in the shared folder so that it doesn’t get erased when you deploy a new version of your code.
56
+
57
+ To deploy your application, simply run:
58
+
59
+ cap deploy
60
+
61
+ ## Deployment ##
62
+
63
+ To configure database on production environment, run:
64
+
65
+ cap symfony:configure:database
66
+
67
+ To deploy your application for the first time, you can run:
68
+
69
+ cap deploy:cold
70
+
71
+ This will deploy your application, configures databases.yml (will ask you about DSN, user, pass), create the db, models, forms, filters, and run all of your migrations.
72
+
73
+ Now, whenever you need to deploy a new version of your code, just run:
74
+
75
+ cap deploy
76
+
77
+ ## Databases ##
78
+
79
+ If you need to dump remote database & download this dump to local `backups/` folder, run:
80
+
81
+ cap database:dump:remote
82
+
83
+ If you need to dump local database & put this dump to local `backups/` folder, run:
84
+
85
+ cap database:dump:local
86
+
87
+ If you need to dump remote database & populate this dump on local machine, run:
88
+
89
+ cap database:move:to_local
90
+
91
+ If you need to dump local database & populate this dump on remote server, run:
92
+
93
+ cap database:move:to_remote
94
+
95
+ ## Shared folders ##
96
+
97
+ If you need to download some shared folders from remote server, run:
98
+
99
+ cap shared:{databases OR log OR uploads]:to_local
100
+
101
+ If you need to upload some shared folders to remote server, run:
102
+
103
+ cap shared:{databases OR log OR uploads]:to_remote
104
+
105
+ ## Other tasks ##
106
+
107
+ If you need to deploy and run your migrations you can call:
108
+
109
+ cap deploy:migrations
110
+
111
+ We’ve also added a custom task to run your test suite on the production server. You can invoke this by calling:
112
+
113
+ cap deploy:tests:all
114
+
115
+ This will deploy the application, rebuild the test database, then run all of the tests.
116
+
117
+ Also, you have command to run your custom diem tasks:
118
+
119
+ cap symfony
120
+
121
+ If you want to see all of the Capistrano tasks available, you can run:
122
+
123
+ cap -T
124
+
125
+ We’ve been using this setup for a little while now, and it’s saved us a ton of time when we need to push changes for a site to the production server.
126
+
127
+ ## Contributors ##
128
+
129
+ * Mickael Kurmann (forker): [git@github.com:elbouillon/capidiem.git](git@github.com:elbouillon/capidiem.git)
130
+ * everzet (owner): [http://github.com/everzet](http://github.com/everzet)
131
+ * Arlo (contributor): [http://github.com/arlo](http://github.com/arlo)
132
+ * Xavier Gorse (contributor): [http://github.com/xgorse](http://github.com/xgorse)
133
+ * Travis Roberts (creator of improved version): [http://blog.centresource.com/author/troberts/](http://blog.centresource.com/author/troberts/)
data/bin/capidiem ADDED
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'fileutils'
5
+
6
+ OptionParser.new do |opts|
7
+ opts.banner = "Usage: #{File.basename($0)} [path]"
8
+
9
+ opts.on("-h", "--help", "Displays this help info") do
10
+ puts opts
11
+ exit 0
12
+ end
13
+
14
+ begin
15
+ opts.parse!(ARGV)
16
+ rescue OptionParser::ParseError => e
17
+ warn e.message
18
+ puts opts
19
+ exit 1
20
+ end
21
+ end
22
+
23
+ if ARGV.empty?
24
+ abort "Please specify the directory to capidiem, e.g. `#{File.basename($0)} .'"
25
+ elsif !File.exists?(ARGV.first)
26
+ abort "`#{ARGV.first}' does not exist."
27
+ elsif !File.directory?(ARGV.first)
28
+ abort "`#{ARGV.first}' is not a directory."
29
+ elsif ARGV.length > 1
30
+ abort "Too many arguments; please specify only the directory to capidiem."
31
+ end
32
+
33
+ def unindent(string)
34
+ indentation = string[/\A\s*/]
35
+ string.strip.gsub(/^#{indentation}/, "")
36
+ end
37
+
38
+ files = {
39
+ "Capfile" => unindent(<<-FILE),
40
+ load 'deploy' if respond_to?(:namespace) # cap2 differentiator
41
+ Dir['plugins/*/lib/recipes/*.rb'].each { |plugin| load(plugin) }
42
+ load Gem.required_location('capidiem', 'capidiem.rb')
43
+ load 'config/deploy' # remove this line to skip loading any of the default tasks
44
+ FILE
45
+
46
+ "config/deploy.rb" => 'set :application, "set your application name here"
47
+ set :domain, "#{application}.com"
48
+ set :deploy_to, "/var/www/#{domain}"
49
+
50
+ set :repository, "#{domain}:/var/repos/#{application}.git"
51
+ set :scm, :git
52
+ # Or: `accurev`, `bzr`, `cvs`, `darcs`, `subversion`, `mercurial`, `perforce`, `subversion` or `none`
53
+
54
+ role :web, domain # Your HTTP server, Apache/etc
55
+ role :app, domain # This may be the same as your `Web` server
56
+ role :db, domain, :primary => true # This is where Rails migrations will run
57
+
58
+ set :keep_releases, 3'}
59
+
60
+ base = ARGV.shift
61
+ files.each do |file, content|
62
+ file = File.join(base, file)
63
+ if File.exists?(file)
64
+ warn "[skip] '#{file}' already exists"
65
+ elsif File.exists?(file.downcase)
66
+ warn "[skip] '#{file.downcase}' exists, which could conflict with `#{file}'"
67
+ else
68
+ unless File.exists?(File.dirname(file))
69
+ puts "[add] making directory '#{File.dirname(file)}'"
70
+ FileUtils.mkdir(File.dirname(file))
71
+ end
72
+ puts "[add] writing '#{file}'"
73
+ File.open(file, "w") { |f| f.write(content) }
74
+ end
75
+ end
76
+
77
+ puts "[done] capidiemied!"
data/lib/capidiem.rb ADDED
@@ -0,0 +1,568 @@
1
+ require 'yaml'
2
+
3
+ # Dirs that need to remain the same between deploys (shared dirs)
4
+ set :shared_children, %w(log web/uploads)
5
+
6
+ # Files that need to remain the same between deploys
7
+ set :shared_files, %w(config/databases.yml)
8
+
9
+ # Asset folders (that need to be timestamped)
10
+ set :asset_children, %w(web/css web/images web/js)
11
+
12
+ # PHP binary to execute
13
+ set :php_bin, "php"
14
+
15
+ # Diem environment on local
16
+ set :diem_env_local, "dev"
17
+
18
+ # Diem environment
19
+ set :diem_env, "prod"
20
+
21
+ # Diem default ORM, only works with doctrine (yet…)
22
+ set :diem_orm, "doctrine"
23
+
24
+ def prompt_with_default(var, default, &block)
25
+ set(var) do
26
+ Capistrano::CLI.ui.ask("#{var} [#{default}] : ", &block)
27
+ end
28
+ set var, default if eval("#{var.to_s}.empty?")
29
+ end
30
+
31
+ def load_database_config(data, env)
32
+ databases = YAML::load(data)
33
+
34
+ if databases[env]
35
+ db_param = databases[env][diem_orm]['param']
36
+ else
37
+ db_param = databases['all'][diem_orm]['param']
38
+ end
39
+
40
+ {
41
+ 'type' => /(\w+)\:/.match(db_param['dsn'])[1],
42
+ 'user' => db_param['username'],
43
+ 'pass' => db_param['password'],
44
+ 'db' => /dbname=([^;$]+)/.match(db_param['dsn'])[1]
45
+ }
46
+ end
47
+
48
+ namespace :deploy do
49
+ desc "Overwrite the start task because diem doesn't need it."
50
+ task :start do ; end
51
+
52
+ desc "Overwrite the restart task because diem doesn't need it."
53
+ task :restart do ; end
54
+
55
+ desc "Overwrite the stop task because diem doesn't need it."
56
+ task :stop do ; end
57
+
58
+ desc "Customize migrate task because diem doesn't need it."
59
+ task :migrate do
60
+ symfony.orm.migrate
61
+ end
62
+
63
+ desc "Symlink static directories and static files that need to remain between deployments."
64
+ task :share_childs do
65
+ if shared_children
66
+ shared_children.each do |link|
67
+ run "mkdir -p #{shared_path}/#{link}"
68
+ run "if [ -d #{release_path}/#{link} ] ; then rm -rf #{release_path}/#{link}; fi"
69
+ run "ln -nfs #{shared_path}/#{link} #{release_path}/#{link}"
70
+ end
71
+ end
72
+ if shared_files
73
+ shared_files.each do |link|
74
+ link_dir = File.dirname("#{shared_path}/#{link}")
75
+ run "mkdir -p #{link_dir}"
76
+ run "touch #{shared_path}/#{link}"
77
+ run "ln -nfs #{shared_path}/#{link} #{release_path}/#{link}"
78
+ end
79
+ end
80
+ end
81
+
82
+ desc "Customize the finalize_update task to work with diem."
83
+ task :finalize_update, :except => { :no_release => true } do
84
+ run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
85
+ run "mkdir -p #{latest_release}/cache"
86
+
87
+ # Share common files & folders
88
+ share_childs
89
+
90
+ if fetch(:normalize_asset_timestamps, true)
91
+ stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
92
+ asset_paths = asset_children.map { |p| "#{latest_release}/#{p}" }.join(" ")
93
+ run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
94
+ end
95
+ end
96
+
97
+ desc "Need to overwrite the deploy:cold task so it doesn't try to run the migrations."
98
+ task :cold do
99
+ update
100
+ symfony.configure.database
101
+ symfony.dm.setup_clear_db
102
+ start
103
+ end
104
+
105
+ desc "Deploy the application and run the test suite."
106
+ task :testall do
107
+ update_code
108
+ symlink
109
+ #TODO: lancer correctement tous les tests symfony.dm.setup_clear_db
110
+ symfony.tests.all
111
+ end
112
+ end
113
+
114
+ namespace :symfony do
115
+ desc "Runs custom symfony task"
116
+ task :default do
117
+ prompt_with_default(:task_arguments, "cache:clear")
118
+
119
+ stream "#{php_bin} #{latest_release}/symfony #{task_arguments}"
120
+ end
121
+
122
+ desc "Downloads & runs check_configuration.php on remote"
123
+ task :check_configuration do
124
+ prompt_with_default(:version, "1.4")
125
+
126
+ run "wget http://sf-to.org/#{version}/check.php -O /tmp/check_configuration.php"
127
+ stream "#{php_bin} /tmp/check_configuration.php"
128
+ run "rm /tmp/check_configuration.php"
129
+ end
130
+
131
+ desc "Clears the cache"
132
+ task :cc do
133
+ run "#{php_bin} #{latest_release}/symfony cache:clear"
134
+ end
135
+
136
+ desc "Shorthand for Diem remove all cache dir content dm:clear-cache"
137
+ task :ccc do
138
+ find_and_execute_task("symfony:dm:clear_cache")
139
+ end
140
+
141
+ namespace :configure do
142
+ desc "Configure database DSN"
143
+ task :database do
144
+ prompt_with_default(:dsn, "mysql:host=localhost;dbname=#{application}")
145
+ prompt_with_default(:db_username, "root")
146
+ db_password = Capistrano::CLI.password_prompt("db_password : ")
147
+
148
+ # surpress debug log output to hide the password
149
+ current_logger_level = self.logger.level
150
+ if current_logger_level >= Capistrano::Logger::DEBUG
151
+ logger.debug %(executing "#{php_bin} #{latest_release}/symfony configure:database '#{dsn}' '#{db_username}' ***")
152
+ self.logger.level = Capistrano::Logger::INFO
153
+ end
154
+
155
+ run "#{php_bin} #{latest_release}/symfony configure:database '#{dsn}' '#{db_username}' '#{db_password}'"
156
+
157
+ # restore logger level
158
+ self.logger.level = current_logger_level
159
+ end
160
+ end
161
+
162
+ namespace :project do
163
+ desc "Disables an application in a given environment"
164
+ task :disable do
165
+ run "#{php_bin} #{latest_release}/symfony project:disable #{diem_env}"
166
+ end
167
+
168
+ desc "Enables an application in a given environment"
169
+ task :enable do
170
+ run "#{php_bin} #{latest_release}/symfony project:enable #{diem_env}"
171
+ end
172
+
173
+ desc "Fixes diem directory permissions"
174
+ task :permissions do
175
+ run "#{php_bin} #{latest_release}/symfony project:permissions"
176
+ end
177
+
178
+ desc "Optimizes a project for better performance"
179
+ task :optimize do
180
+ prompt_with_default(:application, "frontend")
181
+
182
+ run "#{php_bin} #{latest_release}/symfony project:optimize #{application}"
183
+ end
184
+
185
+ desc "Clears all non production environment controllers"
186
+ task :clear_controllers do
187
+ run "#{php_bin} #{latest_release}/symfony project:clear-controllers"
188
+ end
189
+
190
+ desc "Sends emails stored in a queue"
191
+ task :send_emails do
192
+ prompt_with_default(:message_limit, 10)
193
+ prompt_with_default(:time_limit, 10)
194
+
195
+ stream "#{php_bin} #{latest_release}/symfony project:send-emails --message-limit=#{message_limit} --time-limit=#{time_limit} --env=#{diem_env}"
196
+ end
197
+ end
198
+
199
+ namespace :plugin do
200
+ desc "Publishes web assets for all plugins"
201
+ task :publish_assets do
202
+ run "#{php_bin} #{latest_release}/symfony plugin:publish-assets"
203
+ end
204
+ end
205
+
206
+ namespace :log do
207
+ desc "Clears log files"
208
+ task :clear do
209
+ run "#{php_bin} #{latest_release}/symfony log:clear"
210
+ end
211
+
212
+ desc "Rotates an application's log files"
213
+ task :rotate do
214
+ prompt_with_default(:application, "frontend")
215
+
216
+ run "#{php_bin} #{latest_release}/symfony log:rotate #{application} #{diem_env}"
217
+ end
218
+ end
219
+
220
+ namespace :dm do
221
+ desc "Remove all cache dir content"
222
+ task :clear_cache do
223
+ run "#{php_bin} #{latest_release}/symfony dm:clear-cache"
224
+ end
225
+
226
+ desc "Ensure required data"
227
+ task :data do
228
+ run "#{php_bin} #{latest_release}/symfony dm:data"
229
+ end
230
+
231
+ desc "Create random records for a model"
232
+ task :loremize do
233
+ run "#{php_bin} #{latest_release}/symfony dm:loremize"
234
+ end
235
+
236
+ desc "Fixes diem directory permissions"
237
+ task :permissions do
238
+ run "#{php_bin} #{latest_release}/symfony dm:permissions"
239
+ end
240
+
241
+ desc "Publishes web assets for all plugins"
242
+ task :publish_assets do
243
+ run "#{php_bin} #{latest_release}/symfony dm:publish-assets"
244
+ end
245
+
246
+ desc "Update search engine index"
247
+ task :search_update do
248
+ run "#{php_bin} #{latest_release}/symfony dm:search-update"
249
+ end
250
+
251
+ desc "Verify if the server matches both Symfony & Diem requirements"
252
+ task :server_check do
253
+ run "#{php_bin} #{latest_release}/symfony dm:server-check"
254
+ end
255
+
256
+ desc "Safely setup a project. Can be run several times without side effect."
257
+ task :setup do
258
+ run "#{php_bin} #{latest_release}/symfony dm:setup"
259
+ end
260
+
261
+ desc "First time project setup (completly remove DB)"
262
+ task :setup_clear_db do
263
+ if Capistrano::CLI.ui.agree("Do you really want to remove and rebuild your database? All data will be loosed (y/N)")
264
+ run "#{php_bin} #{latest_release}/symfony dm:setup --env=#{diem_env} --clear-db --no-confirmation"
265
+ end
266
+ end
267
+
268
+ desc "Update sitemap"
269
+ task :sitemap_update do
270
+ run "#{php_bin} #{latest_release}/symfony dm:sitemap-update"
271
+ end
272
+
273
+ desc "Creates a sql backup"
274
+ task :sql_backup do
275
+ run "#{php_bin} #{latest_release}/symfony dm:sql-backup"
276
+ end
277
+
278
+ desc "Synchronize pages according to modules and records."
279
+ task :sync_pages do
280
+ run "#{php_bin} #{latest_release}/symfony dm:sync-pages"
281
+ end
282
+
283
+ desc "Safely upgrade a project to the current Diem version. Can be run several times without side effect."
284
+ task :upgrade do
285
+ run "#{php_bin} #{latest_release}/symfony dm:upgrade"
286
+ end
287
+
288
+ desc "reGenerate admin modules"
289
+ task :clear_admin_module do
290
+ prompt_with_default(:admin_module, "")
291
+
292
+ run "#{php_bin} #{latest_release}/symfony dmAdmin:generate --clear=#{admin_module}"
293
+ end
294
+ end
295
+
296
+ namespace :tests do
297
+ desc "Launches all tests"
298
+ task :all do
299
+ run "#{php_bin} #{latest_release}/symfony test:all"
300
+ end
301
+
302
+ desc "Launches functional tests"
303
+ task :functional do
304
+ prompt_with_default(:application, "frontend")
305
+
306
+ run "#{php_bin} #{latest_release}/symfony test:functional #{application}"
307
+ end
308
+
309
+ desc "Launches unit tests"
310
+ task :unit do
311
+ run "#{php_bin} #{latest_release}/symfony test:unit"
312
+ end
313
+ end
314
+
315
+ namespace :orm do
316
+ desc "Ensure diem ORM is properly configured"
317
+ task :setup do
318
+ find_and_execute_task("symfony:#{diem_orm}:setup")
319
+ end
320
+
321
+ desc "Migrates database to current version"
322
+ task :migrate do
323
+ find_and_execute_task("symfony:#{diem_orm}:migrate")
324
+ end
325
+
326
+ desc "Generate model lib form and filters classes based on your schema"
327
+ task :build_classes do
328
+ find_and_execute_task("symfony:#{diem_orm}:build_classes")
329
+ end
330
+
331
+ desc "Generate code & database based on your schema"
332
+ task :build_all do
333
+ find_and_execute_task("symfony:#{diem_orm}:build_all")
334
+ end
335
+
336
+ desc "Generate code & database based on your schema & load fixtures"
337
+ task :build_all_and_load do
338
+ find_and_execute_task("symfony:#{diem_orm}:build_all_and_load")
339
+ end
340
+
341
+ desc "Generate sql & database based on your schema"
342
+ task :build_db do
343
+ find_and_execute_task("symfony:#{diem_orm}:build_db")
344
+ end
345
+
346
+ desc "Generate sql & database based on your schema & load fixtures"
347
+ task :build_db_and_load do
348
+ find_and_execute_task("symfony:#{diem_orm}:build_db_and_load")
349
+ end
350
+ end
351
+
352
+ namespace :doctrine do
353
+ desc "Ensure Doctrine is correctly configured"
354
+ task :setup do
355
+ conf_files_exists = capture("if test -s #{shared_path}/config/databases.yml ; then echo 'exists' ; fi").strip
356
+ if (!conf_files_exists.eql?("exists"))
357
+ symfony.configure.database
358
+ end
359
+ end
360
+
361
+ desc "Execute a DQL query and view the results"
362
+ task :dql do
363
+ prompt_with_default(:query, "")
364
+
365
+ stream "#{php_bin} #{latest_release}/symfony doctrine:dql #{query} --env=#{diem_env}"
366
+ end
367
+
368
+ desc "Dumps data to the fixtures directory"
369
+ task :data_dump do
370
+ run "#{php_bin} #{latest_release}/symfony doctrine:data-dump --env=#{diem_env}"
371
+ end
372
+
373
+ desc "Loads YAML fixture data"
374
+ task :data_load do
375
+ run "#{php_bin} #{latest_release}/symfony doctrine:data-load --env=#{diem_env}"
376
+ end
377
+
378
+ desc "Loads YAML fixture data without remove"
379
+ task :data_load_append do
380
+ run "#{php_bin} #{latest_release}/symfony doctrine:data-load --append --env=#{diem_env}"
381
+ end
382
+
383
+ desc "Migrates database to current version"
384
+ task :migrate do
385
+ run "#{php_bin} #{latest_release}/symfony doctrine:migrate --env=#{diem_env}"
386
+ end
387
+
388
+ desc "Generate model lib form and filters classes based on your schema"
389
+ task :build_classes do
390
+ run "#{php_bin} #{latest_release}/symfony doctrine:build --all-classes --env=#{diem_env}"
391
+ end
392
+
393
+ desc "Generate code & database based on your schema"
394
+ task :build_all do
395
+ if Capistrano::CLI.ui.agree("Do you really want to rebuild #{diem_env}'s database? (y/N)")
396
+ run "#{php_bin} #{latest_release}/symfony doctrine:build --all --no-confirmation --env=#{diem_env}"
397
+ end
398
+ end
399
+
400
+ desc "Generate code & database based on your schema & load fixtures"
401
+ task :build_all_and_load do
402
+ if Capistrano::CLI.ui.agree("Do you really want to rebuild #{diem_env}'s database and load #{diem_env}'s fixtures? (y/N)")
403
+ run "#{php_bin} #{latest_release}/symfony doctrine:build --all --and-load --no-confirmation --env=#{diem_env}"
404
+ end
405
+ end
406
+
407
+ desc "Generate sql & database based on your schema"
408
+ task :build_db do
409
+ if Capistrano::CLI.ui.agree("Do you really want to rebuild #{diem_env}'s database? (y/N)")
410
+ run "#{php_bin} #{latest_release}/symfony doctrine:build --sql --db --no-confirmation --env=#{diem_env}"
411
+ end
412
+ end
413
+
414
+ desc "Generate sql & database based on your schema & load fixtures"
415
+ task :build_db_and_load do
416
+ if Capistrano::CLI.ui.agree("Do you really want to rebuild #{diem_env}'s database and load #{diem_env}'s fixtures? (y/N)")
417
+ run "#{php_bin} #{latest_release}/symfony doctrine:build --sql --db --and-load --no-confirmation --env=#{diem_env}"
418
+ end
419
+ end
420
+ end
421
+ end
422
+
423
+ namespace :database do
424
+ namespace :dump do
425
+ desc "Dump remote database"
426
+ task :remote do
427
+ filename = "#{application}.remote_dump.#{Time.now.to_i}.sql.bz2"
428
+ file = "/tmp/#{filename}"
429
+ sqlfile = "#{application}_dump.sql"
430
+ config = ""
431
+
432
+ run "cat #{shared_path}/config/databases.yml" do |ch, st, data|
433
+ config = load_database_config data, diem_env
434
+ end
435
+
436
+ case config['type']
437
+ when 'mysql'
438
+ run "mysqldump -u#{config['user']} --password='#{config['pass']}' #{config['db']} | bzip2 -c > #{file}" do |ch, stream, data|
439
+ puts data
440
+ end
441
+ when 'pgsql'
442
+ run "pg_dump -U #{config['user']} --password='#{config['pass']}' #{config['db']} | bzip2 -c > #{file}" do |ch, stream, data|
443
+ puts data
444
+ end
445
+ end
446
+
447
+ `mkdir -p backups`
448
+ get file, "backups/#{filename}"
449
+ `cd backups && ln -nfs #{filename} #{application}.remote_dump.latest.sql.bz2`
450
+ run "rm #{file}"
451
+ end
452
+
453
+ desc "Dump local database"
454
+ task :local do
455
+ filename = "#{application}.local_dump.#{Time.now.to_i}.sql.bz2"
456
+ file = "backups/#{filename}"
457
+ config = load_database_config IO.read('config/databases.yml'), diem_env_local
458
+ sqlfile = "#{application}_dump.sql"
459
+
460
+ `mkdir -p backups`
461
+ case config['type']
462
+ when 'mysql'
463
+ `mysqldump -u#{config['user']} --password='#{config['pass']}' #{config['db']} | bzip2 -c > #{file}`
464
+ when 'pgsql'
465
+ `pg_dump -U #{config['user']} --password='#{config['pass']}' #{config['db']} | bzip2 -c > #{file}`
466
+ end
467
+
468
+ `cd backups && ln -nfs #{filename} #{application}.local_dump.latest.sql.bz2`
469
+ end
470
+ end
471
+
472
+ namespace :move do
473
+ desc "Dump remote database, download it to local & populate here"
474
+ task :to_local do
475
+ filename = "#{application}.remote_dump.latest.sql.bz2"
476
+ config = load_database_config IO.read('config/databases.yml'), diem_env_local
477
+ sqlfile = "#{application}_dump.sql"
478
+
479
+ database.dump.remote
480
+
481
+ `bunzip2 -kc backups/#{filename} > backups/#{sqlfile}`
482
+ case config['type']
483
+ when 'mysql'
484
+ `mysql -u#{config['user']} --password='#{config['pass']}' #{config['db']} < backups/#{sqlfile}`
485
+ when 'pgsql'
486
+ `psql -U #{config['user']} --password='#{config['pass']}' #{config['db']} < backups/#{sqlfile}`
487
+ end
488
+ `rm backups/#{sqlfile}`
489
+ end
490
+
491
+ desc "Dump local database, load it to remote & populate there"
492
+ task :to_remote do
493
+ filename = "#{application}.local_dump.latest.sql.bz2"
494
+ file = "backups/#{filename}"
495
+ sqlfile = "#{application}_dump.sql"
496
+ config = ""
497
+
498
+ database.dump.local
499
+
500
+ upload(file, "/tmp/#{filename}", :via => :scp)
501
+ run "bunzip2 -kc /tmp/#{filename} > /tmp/#{sqlfile}"
502
+
503
+ run "cat #{shared_path}/config/databases.yml" do |ch, st, data|
504
+ config = load_database_config data, diem_env
505
+ end
506
+
507
+ case config['type']
508
+ when 'mysql'
509
+ run "mysql -u#{config['user']} --password='#{config['pass']}' #{config['db']} < /tmp/#{sqlfile}" do |ch, stream, data|
510
+ puts data
511
+ end
512
+ when 'pgsql'
513
+ run "psql -U #{config['user']} --password='#{config['pass']}' #{config['db']} < /tmp/#{sqlfile}" do |ch, stream, data|
514
+ puts data
515
+ end
516
+ end
517
+
518
+ run "rm /tmp/#{filename}"
519
+ run "rm /tmp/#{sqlfile}"
520
+ end
521
+ end
522
+ end
523
+
524
+ namespace :shared do
525
+ namespace :databases do
526
+ desc "Download config/databases.yml from remote server"
527
+ task :to_local do
528
+ download("#{shared_path}/config/databases.yml", "config/databases.yml", :via => :scp)
529
+ end
530
+
531
+ desc "Upload config/databases.yml to remote server"
532
+ task :to_remote do
533
+ upload("config/databases.yml", "#{shared_path}/config/databases.yml", :via => :scp)
534
+ end
535
+ end
536
+
537
+ namespace :log do
538
+ desc "Download all logs from remote folder to local one"
539
+ task :to_local do
540
+ download("#{shared_path}/log", "./", :via => :scp, :recursive => true)
541
+ end
542
+
543
+ desc "Upload all logs from local folder to remote one"
544
+ task :to_remote do
545
+ upload("log", "#{shared_path}/", :via => :scp, :recursive => true)
546
+ end
547
+ end
548
+
549
+ namespace :uploads do
550
+ desc "Download all files from remote web/uploads folder to local one"
551
+ task :to_local do
552
+ download("#{shared_path}/web/uploads", "web", :via => :scp, :recursive => true)
553
+ end
554
+
555
+ desc "Upload all files from local web/uploads folder to remote one"
556
+ task :to_remote do
557
+ upload("web/uploads", "#{shared_path}/web", :via => :scp, :recursive => true)
558
+ end
559
+ end
560
+ end
561
+
562
+ # After finalizing update:
563
+ after "deploy:finalize_update" do
564
+ symfony.dm.setup
565
+ if diem_env.eql?("prod")
566
+ symfony.project.clear_controllers # 5. Clear controllers in production environment
567
+ end
568
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capidiem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Konstantin Kudryashov
8
+ - Mickael Kurmann
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-07-03 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: capistrano
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 2.5.10
25
+ version:
26
+ description: " Capistrano is an open source tool for running scripts on multiple servers. It\xE2\x80\x99s primary use is for easily deploying applications. While it was built specifically for deploying Rails apps, it\xE2\x80\x99s pretty simple to customize it to deploy other types of applications. This package is a deployment \xE2\x80\x9Crecipe\xE2\x80\x9D to work with diem PHP applications.\n"
27
+ email:
28
+ - ever.zet@gmail.com
29
+ - mickael.kurmann@gmail.com
30
+ executables:
31
+ - capidiem
32
+ extensions: []
33
+
34
+ extra_rdoc_files: []
35
+
36
+ files:
37
+ - bin/capidiem
38
+ - lib/capidiem.rb
39
+ - README.md
40
+ - LICENSE
41
+ - CHANGELOG
42
+ has_rdoc: true
43
+ homepage: http://github.com/elbouillon/capidiem
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project: capidiem
66
+ rubygems_version: 1.3.5
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Deploying diem PHP applications with Capistrano.
70
+ test_files: []
71
+