capifony 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/README +19 -26
- data/lib/capifony.rb +68 -33
- metadata +4 -4
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 0.4.1 / June 17, 2010
|
2
|
+
|
3
|
+
* added `symfony_env_local` variable, specifying local symfony environment to work with
|
4
|
+
* added third parameter (blocks) to `prompt_with_default` (as in `ask`)
|
5
|
+
* hided password from input & logs in `symfony:configure:database` task
|
6
|
+
* added confirmation dialogs to destructive ORM tasks
|
7
|
+
* run `project:clear-controllers` only on `prod` environment
|
8
|
+
|
1
9
|
== 0.4.0 / June 16, 2010
|
2
10
|
|
3
11
|
* added propel tasks (thanks to http://github.com/arlo)
|
data/README
CHANGED
@@ -3,14 +3,12 @@ Deploying symfony Applications with Capistrano
|
|
3
3
|
|
4
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 symfony applications to make our job a lot easier.
|
5
5
|
|
6
|
-
Prerequisites
|
7
|
-
-------------
|
6
|
+
## Prerequisites ##
|
8
7
|
|
9
8
|
- Must have SSH access to the server you are deploying to.
|
10
9
|
- Must have Ruby and RubyGems installed on your machine (not required for deployment server)’
|
11
10
|
|
12
|
-
Installing Capifony
|
13
|
-
-------------------
|
11
|
+
## Installing Capifony ##
|
14
12
|
|
15
13
|
### Through RubyGems.org ###
|
16
14
|
|
@@ -23,8 +21,7 @@ Installing Capifony
|
|
23
21
|
gem build capifony.gemspec
|
24
22
|
sudo gem install capifony-{version}.gem
|
25
23
|
|
26
|
-
Setup your project to use Capifony
|
27
|
-
----------------------------------
|
24
|
+
## Setup your project to use Capifony ##
|
28
25
|
|
29
26
|
CD to your project directory & run:
|
30
27
|
|
@@ -34,8 +31,7 @@ This will create `Capfile` in your project root & `deploy.rb` config file in `co
|
|
34
31
|
|
35
32
|
Fill up your `config/deploy.rb` with your server connection data
|
36
33
|
|
37
|
-
Server Setup
|
38
|
-
------------
|
34
|
+
## Server Setup ##
|
39
35
|
|
40
36
|
Now, you can start the deployment process! To get your server setup with the file structure that Capistrano expects, you can run:
|
41
37
|
|
@@ -43,16 +39,18 @@ Now, you can start the deployment process! To get your server setup with the fil
|
|
43
39
|
|
44
40
|
This command will create the following folder structure on your server:
|
45
41
|
|
46
|
-
|
47
|
-
|-- current
|
42
|
+
`-- /var/www/demo.everzet.com
|
43
|
+
|-- current → /var/www/demo.everzet.com/releases/20100512131539
|
48
44
|
|-- releases
|
49
45
|
|-- 20100512131539
|
50
46
|
|-- 20100509150741
|
51
|
-
|
52
|
-
|
47
|
+
`-- 20100509145325
|
48
|
+
`-- shared
|
53
49
|
|-- log
|
54
|
-
|--
|
55
|
-
|
50
|
+
|-- config
|
51
|
+
`-- databases.yml
|
52
|
+
`-- web
|
53
|
+
`-- uploads
|
56
54
|
|
57
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.
|
58
56
|
|
@@ -60,8 +58,7 @@ To deploy your application, simply run:
|
|
60
58
|
|
61
59
|
cap deploy
|
62
60
|
|
63
|
-
Deployment
|
64
|
-
----------
|
61
|
+
## Deployment ##
|
65
62
|
|
66
63
|
To configure database on production environment, run:
|
67
64
|
|
@@ -77,8 +74,7 @@ Now, whenever you need to deploy a new version of your code, just run:
|
|
77
74
|
|
78
75
|
cap deploy
|
79
76
|
|
80
|
-
Databases
|
81
|
-
---------
|
77
|
+
## Databases ##
|
82
78
|
|
83
79
|
If you need to dump remote database & download this dump to local `backups/` folder, run:
|
84
80
|
|
@@ -96,8 +92,7 @@ If you need to dump local database & populate this dump on remote server, run:
|
|
96
92
|
|
97
93
|
cap database:move:to_remote
|
98
94
|
|
99
|
-
Shared folders
|
100
|
-
--------------
|
95
|
+
## Shared folders ##
|
101
96
|
|
102
97
|
If you need to download some shared folders from remote server, run:
|
103
98
|
|
@@ -107,8 +102,7 @@ If you need to upload some shared folders to remote server, run:
|
|
107
102
|
|
108
103
|
cap shared:{databases OR log OR uploads]:to_remote
|
109
104
|
|
110
|
-
Other tasks
|
111
|
-
-----------
|
105
|
+
## Other tasks ##
|
112
106
|
|
113
107
|
If you need to deploy and run your migrations you can call:
|
114
108
|
|
@@ -122,7 +116,7 @@ This will deploy the application, rebuild the test database, then run all of the
|
|
122
116
|
|
123
117
|
Also, you have command to run your custom symfony tasks:
|
124
118
|
|
125
|
-
cap symfony
|
119
|
+
cap symfony
|
126
120
|
|
127
121
|
If you want to see all of the Capistrano tasks available, you can run:
|
128
122
|
|
@@ -130,10 +124,9 @@ If you want to see all of the Capistrano tasks available, you can run:
|
|
130
124
|
|
131
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.
|
132
126
|
|
133
|
-
Contributors
|
134
|
-
============
|
127
|
+
## Contributors ##
|
135
128
|
|
136
129
|
* everzet (owner): [http://github.com/everzet](http://github.com/everzet)
|
137
|
-
* Travis Roberts (creator of improved version): [http://blog.centresource.com/author/troberts/](http://blog.centresource.com/author/troberts/)
|
138
130
|
* Arlo (contributor): [http://github.com/arlo](http://github.com/arlo)
|
139
131
|
* Xavier Gorse (contributor): [http://github.com/xgorse](http://github.com/xgorse)
|
132
|
+
* Travis Roberts (creator of improved version): [http://blog.centresource.com/author/troberts/](http://blog.centresource.com/author/troberts/)
|
data/lib/capifony.rb
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
3
|
# Dirs that need to remain the same between deploys (shared dirs)
|
4
|
-
set :shared_children,
|
4
|
+
set :shared_children, %w(log web/uploads)
|
5
5
|
|
6
6
|
# Files that need to remain the same between deploys
|
7
|
-
set :shared_files,
|
7
|
+
set :shared_files, %w(config/databases.yml)
|
8
8
|
|
9
9
|
# Asset folders (that need to be timestamped)
|
10
|
-
set :asset_children,
|
10
|
+
set :asset_children, %w(web/css web/images web/js)
|
11
11
|
|
12
12
|
# PHP binary to execute
|
13
|
-
set :php_bin,
|
13
|
+
set :php_bin, "php"
|
14
|
+
|
15
|
+
# Symfony environment on local
|
16
|
+
set :symfony_env_local, "dev"
|
14
17
|
|
15
18
|
# Symfony environment
|
16
|
-
set :symfony_env,
|
19
|
+
set :symfony_env, "prod"
|
17
20
|
|
18
21
|
# Symfony default ORM
|
19
22
|
set(:symfony_orm) { guess_symfony_orm }
|
@@ -21,9 +24,9 @@ set(:symfony_orm) { guess_symfony_orm }
|
|
21
24
|
# Symfony lib path
|
22
25
|
set(:symfony_lib) { guess_symfony_lib }
|
23
26
|
|
24
|
-
def prompt_with_default(var, default)
|
27
|
+
def prompt_with_default(var, default, &block)
|
25
28
|
set(var) do
|
26
|
-
Capistrano::CLI.ui.ask
|
29
|
+
Capistrano::CLI.ui.ask("#{var} [#{default}] : ", &block)
|
27
30
|
end
|
28
31
|
set var, default if eval("#{var.to_s}.empty?")
|
29
32
|
end
|
@@ -31,8 +34,8 @@ end
|
|
31
34
|
def guess_symfony_orm
|
32
35
|
databases = YAML::load(IO.read('config/databases.yml'))
|
33
36
|
|
34
|
-
if databases[
|
35
|
-
databases[
|
37
|
+
if databases[symfony_env_local]
|
38
|
+
databases[symfony_env_local].keys[0].to_s
|
36
39
|
else
|
37
40
|
databases['all'].keys[0].to_s
|
38
41
|
end
|
@@ -151,11 +154,21 @@ namespace :symfony do
|
|
151
154
|
namespace :configure do
|
152
155
|
desc "Configure database DSN"
|
153
156
|
task :database do
|
154
|
-
prompt_with_default(:dsn,
|
155
|
-
prompt_with_default(:
|
156
|
-
|
157
|
+
prompt_with_default(:dsn, "mysql:host=localhost;dbname=#{application}")
|
158
|
+
prompt_with_default(:db_username, "root")
|
159
|
+
db_password = Capistrano::CLI.password_prompt("db_password : ")
|
160
|
+
|
161
|
+
# surpress debug log output to hide the password
|
162
|
+
current_logger_level = self.logger.level
|
163
|
+
if current_logger_level >= Capistrano::Logger::DEBUG
|
164
|
+
logger.debug %(executing "#{php_bin} #{latest_release}/symfony configure:database '#{dsn}' '#{db_username}' ***")
|
165
|
+
self.logger.level = Capistrano::Logger::INFO
|
166
|
+
end
|
167
|
+
|
168
|
+
run "#{php_bin} #{latest_release}/symfony configure:database '#{dsn}' '#{db_username}' '#{db_password}'"
|
157
169
|
|
158
|
-
|
170
|
+
# restore logger level
|
171
|
+
self.logger.level = current_logger_level
|
159
172
|
end
|
160
173
|
end
|
161
174
|
|
@@ -316,22 +329,30 @@ namespace :symfony do
|
|
316
329
|
|
317
330
|
desc "Generate code & database based on your schema"
|
318
331
|
task :build_all do
|
319
|
-
|
332
|
+
if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env}'s database? (y/N)")
|
333
|
+
run "#{php_bin} #{latest_release}/symfony doctrine:build --all --no-confirmation --env=#{symfony_env}"
|
334
|
+
end
|
320
335
|
end
|
321
336
|
|
322
337
|
desc "Generate code & database based on your schema & load fixtures"
|
323
338
|
task :build_all_and_load do
|
324
|
-
|
339
|
+
if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env}'s database and load #{symfony_env}'s fixtures? (y/N)")
|
340
|
+
run "#{php_bin} #{latest_release}/symfony doctrine:build --all --and-load --no-confirmation --env=#{symfony_env}"
|
341
|
+
end
|
325
342
|
end
|
326
343
|
|
327
344
|
desc "Generate sql & database based on your schema"
|
328
345
|
task :build_db do
|
329
|
-
|
346
|
+
if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env}'s database? (y/N)")
|
347
|
+
run "#{php_bin} #{latest_release}/symfony doctrine:build --sql --db --no-confirmation --env=#{symfony_env}"
|
348
|
+
end
|
330
349
|
end
|
331
350
|
|
332
351
|
desc "Generate sql & database based on your schema & load fixtures"
|
333
352
|
task :build_db_and_load do
|
334
|
-
|
353
|
+
if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env}'s database and load #{symfony_env}'s fixtures? (y/N)")
|
354
|
+
run "#{php_bin} #{latest_release}/symfony doctrine:build --sql --db --and-load --no-confirmation --env=#{symfony_env}"
|
355
|
+
end
|
335
356
|
end
|
336
357
|
end
|
337
358
|
|
@@ -339,13 +360,15 @@ namespace :symfony do
|
|
339
360
|
desc "Ensure Propel is correctly configured"
|
340
361
|
task :setup do
|
341
362
|
conf_files_exists = capture("if test -s #{shared_path}/config/propel.ini -a -s #{shared_path}/config/databases.yml ; then echo 'exists' ; fi").strip
|
363
|
+
|
364
|
+
# share childs again (for propel.ini file)
|
365
|
+
shared_files << "config/propel.ini"
|
366
|
+
deploy.share_childs
|
367
|
+
|
342
368
|
if (!conf_files_exists.eql?("exists"))
|
343
369
|
run "cp #{symfony_lib}/plugins/sfPropelPlugin/config/skeleton/config/propel.ini #{shared_path}/config/propel.ini"
|
344
370
|
symfony.configure.database
|
345
371
|
end
|
346
|
-
# share childs again (for propel.ini file)
|
347
|
-
shared_files << "config/propel.ini"
|
348
|
-
deploy.share_childs
|
349
372
|
end
|
350
373
|
|
351
374
|
desc "Migrates database to current version"
|
@@ -360,22 +383,30 @@ namespace :symfony do
|
|
360
383
|
|
361
384
|
desc "Generate code & database based on your schema"
|
362
385
|
task :build_all do
|
363
|
-
|
386
|
+
if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env}'s database? (y/N)")
|
387
|
+
run "#{php_bin} #{latest_release}/symfony propel:build --sql --db --no-confirmation --env=#{symfony_env}"
|
388
|
+
end
|
364
389
|
end
|
365
390
|
|
366
391
|
desc "Generate code & database based on your schema & load fixtures"
|
367
392
|
task :build_all_and_load do
|
368
|
-
|
393
|
+
if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env}'s database and load #{symfony_env}'s fixtures? (y/N)")
|
394
|
+
run "#{php_bin} #{latest_release}/symfony propel:build --sql --db --and-load --no-confirmation --env=#{symfony_env}"
|
395
|
+
end
|
369
396
|
end
|
370
397
|
|
371
398
|
desc "Generate sql & database based on your schema"
|
372
399
|
task :build_db do
|
373
|
-
|
400
|
+
if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env}'s database? (y/N)")
|
401
|
+
run "#{php_bin} #{latest_release}/symfony propel:build --sql --db --no-confirmation --env=#{symfony_env}"
|
402
|
+
end
|
374
403
|
end
|
375
404
|
|
376
405
|
desc "Generate sql & database based on your schema & load fixtures"
|
377
406
|
task :build_db_and_load do
|
378
|
-
|
407
|
+
if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env}'s database and load #{symfony_env}'s fixtures? (y/N)")
|
408
|
+
run "#{php_bin} #{latest_release}/symfony propel:build --sql --db --and-load --no-confirmation --env=#{symfony_env}"
|
409
|
+
end
|
379
410
|
end
|
380
411
|
end
|
381
412
|
end
|
@@ -414,7 +445,7 @@ namespace :database do
|
|
414
445
|
task :local do
|
415
446
|
filename = "#{application}.local_dump.#{Time.now.to_i}.sql.bz2"
|
416
447
|
file = "backups/#{filename}"
|
417
|
-
config = load_database_config IO.read('config/databases.yml'),
|
448
|
+
config = load_database_config IO.read('config/databases.yml'), symfony_env_local
|
418
449
|
sqlfile = "#{application}_dump.sql"
|
419
450
|
|
420
451
|
`mkdir -p backups`
|
@@ -433,7 +464,7 @@ namespace :database do
|
|
433
464
|
desc "Dump remote database, download it to local & populate here"
|
434
465
|
task :to_local do
|
435
466
|
filename = "#{application}.remote_dump.latest.sql.bz2"
|
436
|
-
config = load_database_config IO.read('config/databases.yml'),
|
467
|
+
config = load_database_config IO.read('config/databases.yml'), symfony_env_local
|
437
468
|
sqlfile = "#{application}_dump.sql"
|
438
469
|
|
439
470
|
database.dump.remote
|
@@ -519,10 +550,14 @@ namespace :shared do
|
|
519
550
|
end
|
520
551
|
end
|
521
552
|
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
553
|
+
# After finalizing update:
|
554
|
+
after "deploy:finalize_update" do
|
555
|
+
symfony.orm.setup # 0. Ensure that ORM is configured
|
556
|
+
symfony.orm.build_classes # 1. (Re)build the model
|
557
|
+
symfony.cc # 2. Clear cache
|
558
|
+
symfony.plugin.publish_assets # 3. Publish plugin assets
|
559
|
+
symfony.project.permissions # 4. Fix project permissions
|
560
|
+
if symfony_env.eql?("prod")
|
561
|
+
symfony.project.clear_controllers # 5. Clear controllers in production environment
|
562
|
+
end
|
563
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capifony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 1
|
10
|
+
version: 0.4.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Konstantin Kudryashov
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-17 00:00:00 +03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|