capifony 2.1.6 → 2.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/CHANGELOG +16 -0
  2. data/LICENSE +3 -2
  3. data/README.md +20 -124
  4. data/lib/capifony.rb +18 -0
  5. data/lib/symfony1.rb +25 -13
  6. data/lib/symfony2.rb +246 -116
  7. metadata +18 -10
data/CHANGELOG CHANGED
@@ -1,3 +1,19 @@
1
+ == 2.1.7 / June 21, 2012
2
+
3
+ * added maintenance page feature for Symfony2, use symfony 1.4 tasks
4
+ (project:disable, project:enable) to do the same.
5
+ * added `interactive_mode` variable. Allows to avoid the need to confirm
6
+ task executions, useful for fully automated deployments.
7
+ * fixed propel regression.
8
+ * added new `symfony_version` variable automatically guessed.
9
+ * the `build_bootstrap` script to use is now configurable thanks to the
10
+ `:build_bootstrap` variable.
11
+ * composer can be used with the `update_vendors` parameter, so that you can
12
+ update composer dependencies.
13
+ * composer support updated, it downloads the `phar` if not available in the
14
+ working directory.
15
+ * bugfixes.
16
+
1
17
  == 2.1.6 / April 12, 2012
2
18
 
3
19
  * bugfixes
data/LICENSE CHANGED
@@ -1,4 +1,5 @@
1
- Copyright (c) 2010 Konstantin Kudryashov <ever.zet@gmail.com>
1
+ Copyright (c) 2010-2012 Konstantin Kudryashov <ever.zet@gmail.com>,
2
+ William Durand <william.durand1@gmail.com>
2
3
 
3
4
  Permission is hereby granted, free of charge, to any person
4
5
  obtaining a copy of this software and associated documentation
@@ -19,4 +20,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
20
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
21
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
22
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
- OTHER DEALINGS IN THE SOFTWARE.
23
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,13 +1,21 @@
1
1
  Deploying symfony Applications with Capistrano
2
2
  ==============================================
3
3
 
4
- Capistrano is an open source tool for running scripts on multiple servers. Its 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 symfony applications to make our job a lot easier.
4
+ Capistrano is an open source tool for running scripts on multiple servers.
5
+ Its primary use is for easily deploying applications. While it was built
6
+ specifically for deploying Rails apps, it’s pretty simple to customize it
7
+ to deploy other types of applications. We’ve been working on creating a
8
+ deployment “recipe” to work with symfony applications to make our job a
9
+ lot easier.
10
+
5
11
 
6
12
  ## Prerequisites ##
7
13
 
8
14
  - Symfony 1.4+ OR Symfony2
9
15
  - Must have SSH access to the server you are deploying to.
10
- - Must have Ruby and RubyGems installed on your machine (not required for deployment server)
16
+ - Must have Ruby and RubyGems installed on your machine (not required
17
+ for deployment server)
18
+
11
19
 
12
20
  ## Installing Capifony ##
13
21
 
@@ -22,135 +30,23 @@ Capistrano is an open source tool for running scripts on multiple servers. Its p
22
30
  gem build capifony.gemspec
23
31
  sudo gem install capifony-{version}.gem
24
32
 
25
- ## Setup your project to use Capifony ##
26
-
27
- CD to your project directory & run:
28
-
29
- capifony .
30
-
31
- This will create a `Capfile` in your project root & a `deploy.rb` config file in your `config` (for symfony)
32
- or `app/config` (for Symfony2) directory.
33
-
34
- Fill up your `config/deploy.rb` with your server connection data.
35
-
36
- ## Server Setup ##
37
-
38
- Now, you can start the deployment process! To get your server setup with the directory structure that Capistrano expects, CD to your local project directory and run:
39
-
40
- cap deploy:setup
41
-
42
- Running this command locally will create the following directory structure on your server:
43
-
44
- `-- /var/www/demo.everzet.com
45
- |-- current → /var/www/demo.everzet.com/releases/20100512131539
46
- |-- releases
47
- |-- 20100512131539
48
- |-- 20100509150741
49
- `-- 20100509145325
50
- `-- shared
51
- |-- log
52
- |-- config
53
- `-- databases.yml
54
- `-- web
55
- `-- uploads
56
-
57
- 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.
58
-
59
- ## Deployment ##
60
-
61
- To deploy your application, simply run:
62
-
63
- cap deploy
64
-
65
- To specify the username/password to use over SSH, add the following configuration to your `config/deploy.rb` file:
66
-
67
- set :user, 'username'
68
- set :password, 'password'
69
-
70
- To configure database on production environment, run:
71
-
72
- cap symfony:configure:database
73
-
74
- To deploy your application for the first time, you can run:
75
-
76
- cap deploy:cold
77
-
78
- 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.
79
-
80
- Now, whenever you need to deploy a new version of your code, just run:
81
-
82
- cap deploy
83
-
84
- ## Databases ##
85
-
86
- If you need to dump remote database & download this dump to local `backups/` folder, run:
87
-
88
- cap database:dump:remote
89
-
90
- If you need to dump local database & put this dump to local `backups/` folder, run:
91
33
 
92
- cap database:dump:local
34
+ ## What's next? ##
93
35
 
94
- If you need to dump remote database & populate this dump on local machine, run:
36
+ Read the [capifony documentation](http://everzet.github.com/capifony/)
95
37
 
96
- cap database:move:to_local
97
-
98
- If you need to dump local database & populate this dump on remote server, run:
99
-
100
- cap database:move:to_remote
101
-
102
- ## Shared folders ##
103
-
104
- If you need to download some shared folders from remote server, run:
105
-
106
- cap shared:{databases OR log OR uploads]:to_local
107
-
108
- If you need to upload some shared folders to remote server, run:
109
-
110
- cap shared:{databases OR log OR uploads]:to_remote
111
-
112
- ## Host Permissions ##
113
-
114
- If you are not allowed sudo ability on your host you can add the following configuration to your `config/deploy.rb` file:
115
-
116
- set :use_sudo, false
117
-
118
- If your host complains about the entire project being group-writable you can add the following configuration to your `config/deploy.rb` file:
119
-
120
- set :group_writable, false
121
-
122
- ## Git Specific Options ##
123
-
124
- If you are using Git submoduleis you'll want to add the following to your `config/deploy.rb` file or the submodule files won't be brought down with your project:
125
-
126
- set :git_enable_submodules, 1
127
-
128
- ## Other tasks ##
129
-
130
- If you need to deploy and run your migrations you can call:
131
-
132
- cap deploy:migrations
133
-
134
- We’ve also added a custom task to run your test suite on the production server. You can invoke this by calling:
135
-
136
- cap deploy:tests:all
137
-
138
- This will deploy the application, rebuild the test database, then run all of the tests.
139
-
140
- Also, you have command to run your custom symfony tasks:
141
-
142
- cap symfony
143
-
144
- If you want to see all of the Capistrano tasks available, you can run:
145
-
146
- cap -T
147
-
148
- 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.
149
38
 
150
39
  ## Contributors ##
151
40
 
152
41
  * everzet (owner): [http://github.com/everzet](http://github.com/everzet)
153
- * Arlo (contributor): [http://github.com/arlo](http://github.com/arlo)
42
+ * Arlo Borras (contributor): [http://github.com/arlo](http://github.com/arlo)
154
43
  * Xavier Gorse (contributor): [http://github.com/xgorse](http://github.com/xgorse)
155
44
  * Travis Roberts (creator of improved version): [http://blog.centresource.com/author/troberts/](http://blog.centresource.com/author/troberts/)
156
45
  * Brent Shaffer (contributor): [http://github.com/bshaffer](http://github.com/bshaffer)
46
+ * William Durand (maintainer): [http://github.com/willdurand](http://github.com/willdurand)
47
+ * And, [All contributors](https://github.com/everzet/capifony/contributors)
48
+
49
+
50
+ ## License ##
51
+
52
+ Capifony is released under the MIT License. See the bundled LICENSE file for details.
data/lib/capifony.rb CHANGED
@@ -23,4 +23,22 @@ namespace :deploy do
23
23
 
24
24
  desc "Overwrite the stop task because symfony doesn't need it."
25
25
  task :stop do ; end
26
+
27
+ desc <<-DESC
28
+ Prepares one or more servers for deployment. Before you can use any \
29
+ of the Capistrano deployment tasks with your project, you will need to \
30
+ make sure all of your servers have been prepared with `cap deploy:setup'. When \
31
+ you add a new server to your cluster, you can easily run the setup task \
32
+ on just that server by specifying the HOSTS environment variable:
33
+
34
+ $ cap HOSTS=new.server.com deploy:setup
35
+
36
+ It is safe to run this task on servers that have already been set up; it \
37
+ will not destroy any deployed revisions or data.
38
+ DESC
39
+ task :setup, :except => { :no_release => true } do
40
+ dirs = [deploy_to, releases_path, shared_path]
41
+ run "#{try_sudo} mkdir -p #{dirs.join(' ')}"
42
+ run "#{try_sudo} chmod g+w #{dirs.join(' ')}" if fetch(:group_writable, true)
43
+ end
26
44
  end
data/lib/symfony1.rb CHANGED
@@ -21,7 +21,7 @@ set(:symfony_lib) { guess_symfony_lib }
21
21
 
22
22
  # Shared symfony lib
23
23
  set :use_shared_symfony, false
24
- set :symfony_version, "1.4.11"
24
+ set :symfony_version, "1.4.18"
25
25
 
26
26
  def guess_symfony_orm
27
27
  databases = YAML::load(IO.read('config/databases.yml'))
@@ -111,6 +111,18 @@ namespace :deploy do
111
111
  symfony.orm.build_db_and_load
112
112
  symfony.tests.all
113
113
  end
114
+
115
+ namespace :web do
116
+ desc "Use symfony 1.4 task to disable the application"
117
+ task :disable, :roles => :web, :except => { :no_release => true } do
118
+ symfony.project.disable
119
+ end
120
+
121
+ desc "Use symfony 1.4 task to enable the application"
122
+ task :enable, :roles => :web, :except => { :no_release => true } do
123
+ symfony.project.enable
124
+ end
125
+ end
114
126
  end
115
127
 
116
128
  namespace :symfony do
@@ -137,7 +149,7 @@ namespace :symfony do
137
149
  end
138
150
 
139
151
  desc "Creates symbolic link to symfony lib in shared"
140
- task :create_lib_symlink do
152
+ task :create_lib_symlink do
141
153
  prompt_with_default(:version, symfony_version)
142
154
  symlink_path = "#{latest_release}/lib/vendor/symfony"
143
155
 
@@ -156,7 +168,7 @@ namespace :symfony do
156
168
  current_logger_level = self.logger.level
157
169
  if current_logger_level >= Capistrano::Logger::DEBUG
158
170
  logger.debug %(executing "cd #{latest_release} && #{php_bin} ./symfony configure:database '#{dsn}' '#{db_username}' ***")
159
- self.logger.level = Capistrano::Logger::INFO
171
+ self.logger.level = Capistrano::Logger::INFO
160
172
  end
161
173
 
162
174
  stream "cd #{latest_release} && #{php_bin} ./symfony configure:database '#{dsn}' '#{db_username}' '#{db_password}'"
@@ -201,7 +213,7 @@ namespace :symfony do
201
213
 
202
214
  stream "cd #{latest_release} && #{php_bin} ./symfony project:send-emails --message-limit=#{message_limit} --time-limit=#{time_limit} --env=#{symfony_env_prod}"
203
215
  end
204
-
216
+
205
217
  desc 'Task to set all front controllers to a specific environment'
206
218
  task :set_environment do
207
219
  if (env = fetch(:symfony_env_prod, nil)) && env != 'prod'
@@ -212,12 +224,12 @@ namespace :symfony do
212
224
  if app = apps.shift
213
225
  cmd << "cp #{release_path}/web/#{app}_#{env}.php #{release_path}/web/index.php"
214
226
  end
215
-
227
+
216
228
  # All other apps are copied to their default controllers
217
229
  for app in apps
218
230
  cmd << "cp #{release_path}/web/#{app}_#{env}.php #{release_path}/web/#{app}.php"
219
231
  end
220
-
232
+
221
233
  run cmd.join(';') if cmd.join(';')
222
234
  end
223
235
  end
@@ -268,7 +280,7 @@ namespace :symfony do
268
280
  task :setup do
269
281
  find_and_execute_task("symfony:#{symfony_orm}:setup")
270
282
  end
271
-
283
+
272
284
  desc "Migrates database to current version"
273
285
  task :migrate do
274
286
  find_and_execute_task("symfony:#{symfony_orm}:migrate")
@@ -307,7 +319,7 @@ namespace :symfony do
307
319
  end
308
320
 
309
321
  desc "Ensure Doctrine is correctly configured"
310
- task :setup do
322
+ task :setup do
311
323
  conf_files_exists = capture("if test -s #{shared_path}/config/databases.yml ; then echo 'exists' ; fi").strip
312
324
  if (!conf_files_exists.eql?("exists"))
313
325
  symfony.configure.database
@@ -451,7 +463,7 @@ namespace :database do
451
463
  puts data
452
464
  end
453
465
  when 'pgsql'
454
- run "pg_dump -U #{config['user']} --password='#{config['pass']}' #{config['db']} | gzip -c > #{file}" do |ch, stream, data|
466
+ run "pg_dump -U #{config['user']} #{config['db']} | gzip -c > #{file}" do |ch, stream, data|
455
467
  puts data
456
468
  end
457
469
  end
@@ -481,7 +493,7 @@ namespace :database do
481
493
  when 'mysql'
482
494
  `mysqldump -u#{config['user']} --password=\"#{config['pass']}\" #{config['db']} > #{tmpfile}`
483
495
  when 'pgsql'
484
- `pg_dump -U #{config['user']} --password=\"#{config['pass']}\" #{config['db']} > #{tmpfile}`
496
+ `pg_dump -U #{config['user']} #{config['db']} > #{tmpfile}`
485
497
  end
486
498
  File.open(tmpfile, "r+") do |f|
487
499
  gz = Zlib::GzipWriter.open(file)
@@ -516,7 +528,7 @@ namespace :database do
516
528
  gz = Zlib::GzipReader.new(File.open("backups/#{filename}", "r"))
517
529
  f << gz.read
518
530
  f.close
519
-
531
+
520
532
  case config['type']
521
533
  when 'mysql'
522
534
  `mysql -u#{config['user']} --password=\"#{config['pass']}\" #{config['db']} < backups/#{sqlfile}`
@@ -598,9 +610,9 @@ namespace :shared do
598
610
 
599
611
  namespace :symfony do
600
612
  desc "Downloads symfony framework to shared directory"
601
- task :download do
613
+ task :download do
602
614
  prompt_with_default(:version, symfony_version)
603
-
615
+
604
616
  run <<-CMD
605
617
  if [ ! -d #{shared_path}/symfony-#{version} ]; then
606
618
  wget -q http://www.symfony-project.org/get/symfony-#{version}.tgz -O- | tar -zxf - -C #{shared_path};
data/lib/symfony2.rb CHANGED
@@ -1,53 +1,63 @@
1
1
  load Gem.find_files('capifony.rb').last.to_s
2
2
 
3
3
  # Symfony application path
4
- set :app_path, "app"
4
+ set :app_path, "app"
5
5
 
6
6
  # Symfony web path
7
- set :web_path, "web"
7
+ set :web_path, "web"
8
8
 
9
9
  # Symfony console bin
10
- set :symfony_console, app_path + "/console"
11
-
12
- # Symfony bin vendors
13
- set :symfony_vendors, "bin/vendors"
10
+ set :symfony_console, app_path + "/console"
14
11
 
15
12
  # Symfony log path
16
- set :log_path, app_path + "/logs"
13
+ set :log_path, app_path + "/logs"
17
14
 
18
15
  # Symfony cache path
19
- set :cache_path, app_path + "/cache"
16
+ set :cache_path, app_path + "/cache"
20
17
 
21
- # Use AsseticBundle
22
- set :dump_assetic_assets, false
18
+ # Symfony bin vendors
19
+ set :symfony_vendors, "bin/vendors"
23
20
 
24
- # Whether to run the bin/vendors script to update vendors
25
- set :update_vendors, false
21
+ # Symfony build_bootstrap script
22
+ set :build_bootstrap, "bin/build_bootstrap"
26
23
 
27
- # Whether to use composer to install vendors. This needs :update_vendors to false
28
- set :use_composer, false
24
+ # Whether to use composer to install vendors.
25
+ # If set to false, it will use the bin/vendors script
26
+ set :use_composer, false
27
+
28
+ # Whether to update vendors using the configured dependency manager (composer or bin/vendors)
29
+ set :update_vendors, false
29
30
 
30
31
  # run bin/vendors script in mode (upgrade, install (faster if shared /vendor folder) or reinstall)
31
- set :vendors_mode, "reinstall"
32
+ set :vendors_mode, "reinstall"
32
33
 
33
- # Whether to run cache warmup
34
- set :cache_warmup, true
34
+ # Whether to run cache warmup
35
+ set :cache_warmup, true
35
36
 
36
- # Assets install
37
- set :assets_install, true
37
+ # Use AsseticBundle
38
+ set :dump_assetic_assets, false
38
39
 
39
- # Dirs that need to remain the same between deploys (shared dirs)
40
- set :shared_children, [log_path, web_path + "/uploads"]
40
+ # Assets install
41
+ set :assets_install, true
41
42
 
42
43
  # Files that need to remain the same between deploys
43
- set :shared_files, false
44
+ set :shared_files, false
45
+
46
+ # Dirs that need to remain the same between deploys (shared dirs)
47
+ set :shared_children, [log_path, web_path + "/uploads"]
44
48
 
45
49
  # Asset folders (that need to be timestamped)
46
- set :asset_children, [web_path + "/css", web_path + "/images", web_path + "/js"]
50
+ set :asset_children, [web_path + "/css", web_path + "/images", web_path + "/js"]
47
51
 
48
- set :model_manager, "doctrine"
49
- # Or: `propel`
52
+ # Model manager: (doctrine, propel)
53
+ set :model_manager, "doctrine"
50
54
 
55
+ # Symfony2 version
56
+ set(:symfony_version) { guess_symfony_version }
57
+
58
+ # If set to false, it will never ask for confirmations (migrations task for instance)
59
+ # Use it carefully, really!
60
+ set :interactive_mode, true
51
61
 
52
62
  def load_database_config(data, env)
53
63
  parameters = YAML::load(data)
@@ -55,9 +65,13 @@ def load_database_config(data, env)
55
65
  parameters['parameters']
56
66
  end
57
67
 
68
+ def guess_symfony_version
69
+ capture("cd #{latest_release} && #{php_bin} #{symfony_console} --version |cut -d \" \" -f 3")
70
+ end
71
+
58
72
  namespace :database do
59
73
  namespace :dump do
60
- desc "Dump remote database"
74
+ desc "Dumps remote database"
61
75
  task :remote do
62
76
  filename = "#{application}.remote_dump.#{Time.now.to_i}.sql.gz"
63
77
  file = "/tmp/#{filename}"
@@ -69,12 +83,12 @@ namespace :database do
69
83
  end
70
84
 
71
85
  case config['database_driver']
72
- when 'pdo_mysql'
86
+ when "pdo_mysql", "mysql"
73
87
  run "mysqldump -u#{config['database_user']} --password='#{config['database_password']}' #{config['database_name']} | gzip -c > #{file}" do |ch, stream, data|
74
88
  puts data
75
89
  end
76
- when 'pdo_pgsql'
77
- run "pg_dump -U #{config['database_user']} --password='#{config['database_password']}' #{config['database_name']} | gzip -c > #{file}" do |ch, stream, data|
90
+ when "pdo_pgsql", "pgsql"
91
+ run "pg_dump -U #{config['database_user']} #{config['database_name']} | gzip -c > #{file}" do |ch, stream, data|
78
92
  puts data
79
93
  end
80
94
  end
@@ -90,7 +104,7 @@ namespace :database do
90
104
  run "rm #{file}"
91
105
  end
92
106
 
93
- desc "Dump local database"
107
+ desc "Dumps local database"
94
108
  task :local do
95
109
  filename = "#{application}.local_dump.#{Time.now.to_i}.sql.gz"
96
110
  tmpfile = "backups/#{application}_dump_tmp.sql"
@@ -101,11 +115,12 @@ namespace :database do
101
115
  require "fileutils"
102
116
  FileUtils::mkdir_p("backups")
103
117
  case config['database_driver']
104
- when 'pdo_mysql'
118
+ when "pdo_mysql", "mysql"
105
119
  `mysqldump -u#{config['database_user']} --password=\"#{config['database_password']}\" #{config['database_name']} > #{tmpfile}`
106
- when 'pdo_pgsql'
107
- `pg_dump -U #{config['database_user']} --password=\"#{config['database_password']}\" #{config['database_name']} > #{tmpfile}`
120
+ when "pdo_pgsql", "pgsql"
121
+ `pg_dump -U #{config['database_user']} #{config['database_name']} > #{tmpfile}`
108
122
  end
123
+
109
124
  File.open(tmpfile, "r+") do |f|
110
125
  gz = Zlib::GzipWriter.open(file)
111
126
  while (line = f.gets)
@@ -125,7 +140,7 @@ namespace :database do
125
140
  end
126
141
 
127
142
  namespace :move do
128
- desc "Dump remote database, download it to local & populate here"
143
+ desc "Dumps remote database, downloads it to local, and populates here"
129
144
  task :to_local do
130
145
  filename = "#{application}.remote_dump.latest.sql.gz"
131
146
  config = load_database_config IO.read('app/config/parameters.yml'), symfony_env_local
@@ -141,15 +156,15 @@ namespace :database do
141
156
  f.close
142
157
 
143
158
  case config['database_driver']
144
- when 'pdo_mysql'
159
+ when "pdo_mysql", "mysql"
145
160
  `mysql -u#{config['database_user']} --password=\"#{config['database_password']}\" #{config['database_name']} < backups/#{sqlfile}`
146
- when 'pdo_pgsql'
161
+ when "pdo_pgsql", "pgsql"
147
162
  `psql -U #{config['database_user']} --password=\"#{config['database_password']}\" #{config['database_name']} < backups/#{sqlfile}`
148
163
  end
149
164
  FileUtils.rm("backups/#{sqlfile}")
150
165
  end
151
166
 
152
- desc "Dump local database, load it to remote & populate there"
167
+ desc "Dumps local database, loads it to remote, and populates there"
153
168
  task :to_remote do
154
169
  filename = "#{application}.local_dump.latest.sql.gz"
155
170
  file = "backups/#{filename}"
@@ -166,11 +181,11 @@ namespace :database do
166
181
  end
167
182
 
168
183
  case config['database_driver']
169
- when 'pdo_mysql'
184
+ when "pdo_mysql", "mysql"
170
185
  run "mysql -u#{config['database_user']} --password='#{config['database_password']}' #{config['database_name']} < /tmp/#{sqlfile}" do |ch, stream, data|
171
186
  puts data
172
187
  end
173
- when 'pdo_pgsql'
188
+ when "pdo_pgsql", "pgsql"
174
189
  run "psql -U #{config['database_user']} --password='#{config['database_password']}' #{config['database_name']} < /tmp/#{sqlfile}" do |ch, stream, data|
175
190
  puts data
176
191
  end
@@ -183,7 +198,7 @@ namespace :database do
183
198
  end
184
199
 
185
200
  namespace :deploy do
186
- desc "Symlink static directories and static files that need to remain between deployments."
201
+ desc "Symlinks static directories and static files that need to remain between deployments"
187
202
  task :share_childs do
188
203
  if shared_children
189
204
  shared_children.each do |link|
@@ -202,7 +217,7 @@ namespace :deploy do
202
217
  end
203
218
  end
204
219
 
205
- desc "Update latest release source path."
220
+ desc "Updates latest release source path"
206
221
  task :finalize_update, :except => { :no_release => true } do
207
222
  run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
208
223
  run "if [ -d #{latest_release}/#{cache_path} ] ; then rm -rf #{latest_release}/#{cache_path}; fi"
@@ -214,54 +229,110 @@ namespace :deploy do
214
229
  if fetch(:normalize_asset_timestamps, true)
215
230
  stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
216
231
  asset_paths = asset_children.map { |p| "#{latest_release}/#{p}" }.join(" ")
217
- run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
232
+
233
+ if asset_paths.chomp.empty?
234
+ puts " No asset paths found, skipped"
235
+ else
236
+ run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
237
+ end
218
238
  end
219
239
  end
220
240
 
221
- desc "Deploy the application and start it."
241
+ desc "Deploys the application and starts it"
222
242
  task :cold do
223
243
  update
224
244
  start
225
245
  end
226
246
 
227
- desc "Deploy the application and run the test suite."
247
+ desc "Deploys the application and runs the test suite"
228
248
  task :testall do
229
249
  update_code
230
250
  symlink
231
251
  run "cd #{latest_release} && phpunit -c #{app_path} src"
232
252
  end
233
253
 
234
- desc "Migrate Symfony2 Doctrine ORM database."
254
+ desc "Runs the Symfony2 migrations"
235
255
  task :migrate do
236
- currentVersion = nil
237
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:status --env=#{symfony_env_prod}" do |ch, stream, out|
238
- if stream == :out and out =~ /Current Version:[^$]+\(([\w]+)\)/
239
- currentVersion = Regexp.last_match(1)
240
- end
241
- if stream == :out and out =~ /Current Version:\s*0\s*$/
242
- currentVersion = 0
256
+ if model_manager == "doctrine"
257
+ symfony.doctrine.migrations.migrate
258
+ else
259
+ if model_manager == "propel"
260
+ puts " Propel doesn't have built-in migration for now"
243
261
  end
244
262
  end
263
+ end
245
264
 
246
- if currentVersion == nil
247
- raise "Could not find current database migration version"
265
+ namespace :web do
266
+ desc <<-DESC
267
+ Present a maintenance page to visitors. Disables your application's web \
268
+ interface by writing a "#{maintenance_basename}.html" file to each web server. The \
269
+ servers must be configured to detect the presence of this file, and if \
270
+ it is present, always display it instead of performing the request.
271
+
272
+ By default, the maintenance page will just say the site is down for \
273
+ "maintenance", and will be back "shortly", but you can customize the \
274
+ page by specifying the REASON and UNTIL environment variables:
275
+
276
+ $ cap deploy:web:disable \\
277
+ REASON="hardware upgrade" \\
278
+ UNTIL="12pm Central Time"
279
+
280
+ You can use a different template for the maintenance page by setting the \
281
+ :maintenance_template_path variable in your deploy.rb file. The template file \
282
+ should either be a plaintext or an erb file.
283
+
284
+ Further customization will require that you write your own task.
285
+ DESC
286
+ task :disable, :roles => :web, :except => { :no_release => true } do
287
+ require 'erb'
288
+ on_rollback { run "rm #{latest_release}/#{web_path}/#{maintenance_basename}.html" }
289
+
290
+ warn <<-EOHTACCESS
291
+
292
+ # Please add something like this to your site's Apache htaccess to redirect users to the maintenance page.
293
+ # More Info: http://www.shiftcommathree.com/articles/make-your-rails-maintenance-page-respond-with-a-503
294
+
295
+ ErrorDocument 503 /#{maintenance_basename}.html
296
+ RewriteEngine On
297
+ RewriteCond %{REQUEST_URI} !\.(css|gif|jpg|png)$
298
+ RewriteCond %{DOCUMENT_ROOT}/#{maintenance_basename}.html -f
299
+ RewriteCond %{SCRIPT_FILENAME} !#{maintenance_basename}.html
300
+ RewriteRule ^.*$ - [redirect=503,last]
301
+
302
+ # Or if you are using Nginx add this to your server config:
303
+
304
+ if (-f $document_root/maintenance.html) {
305
+ return 503;
306
+ }
307
+ error_page 503 @maintenance;
308
+ location @maintenance {
309
+ rewrite ^(.*)$ /maintenance.html last;
310
+ break;
311
+ }
312
+ EOHTACCESS
313
+
314
+ reason = ENV['REASON']
315
+ deadline = ENV['UNTIL']
316
+ template = File.read(maintenance_template_path)
317
+ result = ERB.new(template).result(binding)
318
+
319
+ put result, "#{latest_release}/#{web_path}/#{maintenance_basename}.html", :mode => 0644
248
320
  end
249
- puts "Current database version: #{currentVersion}"
250
-
251
- on_rollback {
252
- if Capistrano::CLI.ui.agree("Do you really want to migrate #{symfony_env_prod}'s database back to version #{currentVersion}? (y/N)")
253
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:migrate #{currentVersion} --env=#{symfony_env_prod} --no-interaction"
254
- end
255
- }
256
321
 
257
- if Capistrano::CLI.ui.agree("Do you really want to migrate #{symfony_env_prod}'s database? (y/N)")
258
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:migrate --env=#{symfony_env_prod} --no-interaction"
322
+ desc <<-DESC
323
+ Makes the application web-accessible again. Removes the \
324
+ "#{maintenance_basename}.html" page generated by deploy:web:disable, which (if your \
325
+ web servers are configured correctly) will make your application \
326
+ web-accessible again.
327
+ DESC
328
+ task :enable, :roles => :web, :except => { :no_release => true } do
329
+ run "rm #{latest_release}/#{web_path}/#{maintenance_basename}.html"
259
330
  end
260
331
  end
261
332
  end
262
333
 
263
334
  namespace :symfony do
264
- desc "Runs custom symfony task"
335
+ desc "Runs custom symfony command"
265
336
  task :default do
266
337
  prompt_with_default(:task_arguments, "cache:clear")
267
338
 
@@ -269,7 +340,7 @@ namespace :symfony do
269
340
  end
270
341
 
271
342
  namespace :assets do
272
- desc "Install bundle's assets"
343
+ desc "Installs bundle's assets"
273
344
  task :install do
274
345
  run "cd #{latest_release} && #{php_bin} #{symfony_console} assets:install #{web_path} --env=#{symfony_env_prod}"
275
346
  end
@@ -278,7 +349,7 @@ namespace :symfony do
278
349
  namespace :assetic do
279
350
  desc "Dumps all assets to the filesystem"
280
351
  task :dump do
281
- run "cd #{latest_release} && #{php_bin} #{symfony_console} assetic:dump #{web_path} --env=#{symfony_env_prod} --no-debug"
352
+ run "cd #{latest_release} && #{php_bin} #{symfony_console} assetic:dump --env=#{symfony_env_prod} --no-debug"
282
353
  end
283
354
  end
284
355
 
@@ -298,29 +369,47 @@ namespace :symfony do
298
369
  run "cd #{latest_release} && #{php_bin} #{symfony_vendors} update"
299
370
  end
300
371
  end
301
-
372
+
302
373
  namespace :bootstrap do
303
- desc "Runs the bin/build_bootstrap whithout upgrade the vendors"
374
+ desc "Runs the bin/build_bootstrap script"
304
375
  task :build do
305
- run "cd #{latest_release} && #{php_bin} bin/build_bootstrap"
376
+ run "cd #{latest_release} && test -f #{build_bootstrap} && #{php_bin} #{build_bootstrap} || echo '#{build_bootstrap} not found, skipped'"
306
377
  end
307
378
  end
308
379
 
309
380
  namespace :composer do
310
- desc "Runs composer install to install vendors from composer.lock file"
381
+ desc "Gets composer and installs it"
382
+ task :get do
383
+ run "cd #{latest_release} && curl -s http://getcomposer.org/installer | #{php_bin}"
384
+ end
385
+
386
+ desc "Runs composer to install vendors from composer.lock file"
311
387
  task :install do
388
+ if !File.exist?("#{latest_release}/composer.phar")
389
+ symfony.composer.get
390
+ end
391
+
312
392
  run "cd #{latest_release} && #{php_bin} composer.phar install"
313
393
  end
394
+
395
+ desc "Runs composer to update vendors, and composer.lock file"
396
+ task :update do
397
+ if !File.exist?("#{latest_release}/composer.phar")
398
+ symfony.composer.get
399
+ end
400
+
401
+ run "cd #{latest_release} && #{php_bin} composer.phar update"
402
+ end
314
403
  end
315
404
 
316
405
  namespace :cache do
317
- desc "Clears project cache."
406
+ desc "Clears project cache"
318
407
  task :clear do
319
408
  run "cd #{latest_release} && #{php_bin} #{symfony_console} cache:clear --env=#{symfony_env_prod}"
320
409
  run "chmod -R g+w #{latest_release}/#{cache_path}"
321
410
  end
322
411
 
323
- desc "Warms up an empty cache."
412
+ desc "Warms up an empty cache"
324
413
  task :warmup do
325
414
  run "cd #{latest_release} && #{php_bin} #{symfony_console} cache:warmup --env=#{symfony_env_prod}"
326
415
  run "chmod -R g+w #{latest_release}/#{cache_path}"
@@ -329,67 +418,88 @@ namespace :symfony do
329
418
 
330
419
  namespace :doctrine do
331
420
  namespace :cache do
332
- desc "Clear all metadata cache for a entity manager."
421
+ desc "Clears all metadata cache for a entity manager"
333
422
  task :clear_metadata do
334
423
  run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:cache:clear-metadata --env=#{symfony_env_prod}"
335
424
  end
336
425
 
337
- desc "Clear all query cache for a entity manager."
426
+ desc "Clears all query cache for a entity manager"
338
427
  task :clear_query do
339
428
  run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:cache:clear-query --env=#{symfony_env_prod}"
340
429
  end
341
430
 
342
- desc "Clear result cache for a entity manager."
431
+ desc "Clears result cache for a entity manager"
343
432
  task :clear_result do
344
433
  run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:cache:clear-result --env=#{symfony_env_prod}"
345
434
  end
346
435
  end
347
436
 
348
437
  namespace :database do
349
- desc "Create the configured databases."
438
+ desc "Creates the configured databases"
350
439
  task :create do
351
440
  run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:database:create --env=#{symfony_env_prod}"
352
441
  end
353
442
 
354
- desc "Drop the configured databases."
443
+ desc "Drops the configured databases"
355
444
  task :drop do
356
445
  run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:database:drop --env=#{symfony_env_prod}"
357
446
  end
358
447
  end
359
448
 
360
449
  namespace :generate do
361
- desc "Generates proxy classes for entity classes."
450
+ desc "Generates proxy classes for entity classes"
362
451
  task :hydrators do
363
452
  run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:generate:proxies --env=#{symfony_env_prod}"
364
453
  end
365
454
 
366
- desc "Generate repository classes from your mapping information."
455
+ desc "Generates repository classes from your mapping information"
367
456
  task :hydrators do
368
457
  run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:generate:repositories --env=#{symfony_env_prod}"
369
458
  end
370
459
  end
371
460
 
372
461
  namespace :schema do
373
- desc "Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output."
462
+ desc "Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output"
374
463
  task :create do
375
464
  run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:schema:create --env=#{symfony_env_prod}"
376
465
  end
377
466
 
378
- desc "Drop the complete database schema of EntityManager Storage Connection or generate the corresponding SQL output."
467
+ desc "Drops the complete database schema of EntityManager Storage Connection or generate the corresponding SQL output"
379
468
  task :drop do
380
469
  run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:schema:drop --env=#{symfony_env_prod}"
381
470
  end
382
471
  end
383
472
 
384
473
  namespace :migrations do
385
- desc "Execute a migration to a specified version or the latest available version."
474
+ desc "Executes a migration to a specified version or the latest available version"
386
475
  task :migrate do
387
- if Capistrano::CLI.ui.agree("Do you really want to migrate #{symfony_env_prod}'s database? (y/N)")
476
+ currentVersion = nil
477
+ run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:status --env=#{symfony_env_prod}" do |ch, stream, out|
478
+ if stream == :out and out =~ /Current Version:[^$]+\(([\w]+)\)/
479
+ currentVersion = Regexp.last_match(1)
480
+ end
481
+ if stream == :out and out =~ /Current Version:\s*0\s*$/
482
+ currentVersion = 0
483
+ end
484
+ end
485
+
486
+ if currentVersion == nil
487
+ raise "Could not find current database migration version"
488
+ end
489
+ puts " Current database version: #{currentVersion}"
490
+
491
+ on_rollback {
492
+ if !interactive_mode || Capistrano::CLI.ui.agree("Do you really want to migrate #{symfony_env_prod}'s database back to version #{currentVersion}? (y/N)")
493
+ run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:migrate #{currentVersion} --env=#{symfony_env_prod} --no-interaction"
494
+ end
495
+ }
496
+
497
+ if !interactive_mode || Capistrano::CLI.ui.agree("Do you really want to migrate #{symfony_env_prod}'s database? (y/N)")
388
498
  run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:migrate --env=#{symfony_env_prod} --no-interaction"
389
499
  end
390
500
  end
391
501
 
392
- desc "View the status of a set of migrations."
502
+ desc "Views the status of a set of migrations"
393
503
  task :status do
394
504
  run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:status --env=#{symfony_env_prod}"
395
505
  end
@@ -397,29 +507,29 @@ namespace :symfony do
397
507
 
398
508
  namespace :mongodb do
399
509
  namespace :generate do
400
- desc "Generates hydrator classes for document classes."
510
+ desc "Generates hydrator classes for document classes"
401
511
  task :hydrators do
402
512
  run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:mongodb:generate:hydrators --env=#{symfony_env_prod}"
403
513
  end
404
514
 
405
- desc "Generates proxy classes for document classes."
515
+ desc "Generates proxy classes for document classes"
406
516
  task :hydrators do
407
517
  run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:mongodb:generate:proxies --env=#{symfony_env_prod}"
408
518
  end
409
519
 
410
- desc "Generates repository classes for document classes."
520
+ desc "Generates repository classes for document classes"
411
521
  task :hydrators do
412
522
  run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:mongodb:generate:repositories --env=#{symfony_env_prod}"
413
523
  end
414
524
  end
415
525
 
416
526
  namespace :schema do
417
- desc "Allows you to create databases, collections and indexes for your documents."
527
+ desc "Allows you to create databases, collections and indexes for your documents"
418
528
  task :create do
419
529
  run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:mongodb:schema:create --env=#{symfony_env_prod}"
420
530
  end
421
531
 
422
- desc "Allows you to drop databases, collections and indexes for your documents."
532
+ desc "Allows you to drop databases, collections and indexes for your documents"
423
533
  task :drop do
424
534
  run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:mongodb:schema:drop --env=#{symfony_env_prod}"
425
535
  end
@@ -434,57 +544,81 @@ namespace :symfony do
434
544
  end
435
545
  end
436
546
 
437
-
438
547
  namespace :propel do
439
548
  namespace :database do
440
- desc "Create the configured databases."
549
+ desc "Creates the configured databases"
441
550
  task :create do
442
551
  run "cd #{latest_release} && #{php_bin} #{symfony_console} propel:database:create --env=#{symfony_env_prod}"
443
552
  end
444
553
 
445
- desc "Drop the configured databases."
554
+ desc "Drops the configured databases"
446
555
  task :drop do
447
556
  run "cd #{latest_release} && #{php_bin} #{symfony_console} propel:database:drop --env=#{symfony_env_prod}"
448
557
  end
449
558
  end
450
559
 
451
560
  namespace :build do
452
- desc "Build the Model classes."
561
+ desc "Builds the Model classes"
453
562
  task :model do
454
- run "cd #{latest_release} && #{php_bin} #{symfony_console} propel:build-model --env=#{symfony_env_prod}"
563
+ command = "propel:model:build"
564
+ if /2\.0\.[0-9]+.*/ =~ symfony_version
565
+ command = "propel:build-model"
566
+ end
567
+
568
+ run "cd #{latest_release} && #{php_bin} #{symfony_console} #{command} --env=#{symfony_env_prod}"
455
569
  end
456
570
 
457
- desc "Build SQL statements."
571
+ desc "Builds SQL statements"
458
572
  task :sql do
459
- run "cd #{latest_release} && #{php_bin} #{symfony_console} propel:build-sql --env=#{symfony_env_prod}"
573
+ command = "propel:sql:build"
574
+ if /2\.0\.[0-9]+.*/ =~ symfony_version
575
+ command = "propel:build-sql"
576
+ end
577
+
578
+ run "cd #{latest_release} && #{php_bin} #{symfony_console} #{command} --env=#{symfony_env_prod}"
460
579
  end
461
580
 
462
- desc "Build the Model classes, SQL statements and insert SQL."
581
+ desc "Builds the Model classes, SQL statements and insert SQL"
463
582
  task :all_and_load do
464
583
  run "cd #{latest_release} && #{php_bin} #{symfony_console} propel:build --insert-sql --env=#{symfony_env_prod}"
465
584
  end
585
+
586
+ desc "Generates ACLs models"
587
+ task :acl do
588
+ run "cd #{latest_release} && #{php_bin} #{symfony_console} propel:acl:init --env=#{symfony_env_prod}"
589
+ end
590
+
591
+ desc "Inserts propel ACL tables"
592
+ task :acl_load do
593
+ run "cd #{latest_release} && #{php_bin} #{symfony_console} propel:acl:init --env=#{symfony_env_prod} --force"
594
+ end
466
595
  end
467
596
  end
468
597
  end
469
598
 
470
599
  # After finalizing update:
471
600
  after "deploy:finalize_update" do
472
- if update_vendors
473
- # share the children first (to get the vendor symlink)
474
- deploy.share_childs
475
- vendors_mode.chomp # To remove trailing whiteline
476
- case vendors_mode
477
- when "upgrade" then symfony.vendors.upgrade
478
- when "install" then symfony.vendors.install
479
- when "reinstall" then symfony.vendors.reinstall
480
- end
481
- elsif use_composer
482
- symfony.composer.install
601
+ if use_composer
602
+ if update_vendors
603
+ symfony.composer.update
604
+ else
605
+ symfony.composer.install
606
+ end
483
607
  else
484
- # share the children first (to get the vendor symlink)
485
- deploy.share_childs
486
- vendors_mode.chomp # To remove trailing whiteline
487
- symfony.bootstrap.build
608
+ if update_vendors
609
+ vendors_mode.chomp # To remove trailing whiteline
610
+ case vendors_mode
611
+ when "upgrade" then symfony.vendors.upgrade
612
+ when "install" then symfony.vendors.install
613
+ when "reinstall" then symfony.vendors.reinstall
614
+ end
615
+ else
616
+ symfony.bootstrap.build
617
+ end
618
+ end
619
+
620
+ if model_manager == "propel"
621
+ symfony.propel.build.model
488
622
  end
489
623
 
490
624
  if assets_install
@@ -498,8 +632,4 @@ after "deploy:finalize_update" do
498
632
  if dump_assetic_assets
499
633
  symfony.assetic.dump # 4. Dump assetic assets
500
634
  end
501
-
502
- if model_manager == "propel"
503
- symfony.propel.build.model
504
- end
505
635
  end
metadata CHANGED
@@ -1,29 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capifony
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 5
5
+ prerelease:
5
6
  segments:
6
7
  - 2
7
8
  - 1
8
- - 6
9
- version: 2.1.6
9
+ - 7
10
+ version: 2.1.7
10
11
  platform: ruby
11
12
  authors:
12
13
  - Konstantin Kudryashov
14
+ - William Durand
13
15
  autorequire:
14
16
  bindir: bin
15
17
  cert_chain: []
16
18
 
17
- date: 2012-04-12 00:00:00 +02:00
18
- default_executable:
19
+ date: 2012-06-21 00:00:00 Z
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: capistrano
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 15
27
30
  segments:
28
31
  - 2
29
32
  - 5
@@ -31,8 +34,10 @@ dependencies:
31
34
  version: 2.5.10
32
35
  type: :runtime
33
36
  version_requirements: *id001
34
- 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 symfony (both 1 and 2) applications.\n"
35
- email: ever.zet@gmail.com
37
+ 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 \"recipe\" to work with symfony (both 1 and 2) applications.\n"
38
+ email:
39
+ - ever.zet@gmail.com
40
+ - william.durand1@gmail.com
36
41
  executables:
37
42
  - capifony
38
43
  extensions: []
@@ -47,8 +52,7 @@ files:
47
52
  - README.md
48
53
  - LICENSE
49
54
  - CHANGELOG
50
- has_rdoc: true
51
- homepage: http://capifony.info
55
+ homepage: http://capifony.org
52
56
  licenses: []
53
57
 
54
58
  post_install_message:
@@ -57,23 +61,27 @@ rdoc_options: []
57
61
  require_paths:
58
62
  - lib
59
63
  required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
60
65
  requirements:
61
66
  - - ">="
62
67
  - !ruby/object:Gem::Version
68
+ hash: 3
63
69
  segments:
64
70
  - 0
65
71
  version: "0"
66
72
  required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
67
74
  requirements:
68
75
  - - ">="
69
76
  - !ruby/object:Gem::Version
77
+ hash: 3
70
78
  segments:
71
79
  - 0
72
80
  version: "0"
73
81
  requirements: []
74
82
 
75
83
  rubyforge_project: capifony
76
- rubygems_version: 1.3.6
84
+ rubygems_version: 1.8.24
77
85
  signing_key:
78
86
  specification_version: 3
79
87
  summary: Deploying symfony PHP applications with Capistrano.