capifony 0.1.0

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 +3 -0
  2. data/LICENSE +22 -0
  3. data/README +88 -0
  4. data/bin/capifony +77 -0
  5. data/lib/capifony.rb +178 -0
  6. metadata +86 -0
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ == 0.1.0 / June 3, 2010
2
+
3
+ First ever working version.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2010 Konstantin Kudryashov <ever.zet@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,88 @@
1
+ Deploying symfony 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 symfony 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 Capifony ###
12
+
13
+ sudo gem install capifony
14
+
15
+ ### Setup your project to use Capifony ###
16
+
17
+ CD to your project directory & run:
18
+
19
+ capifony .
20
+
21
+ This will create `Capfile` in your project root & `deploy.rb` config file in `config` directory
22
+
23
+ Fill up your `config/deploy.rb` with your server connection data
24
+
25
+ ### Server Setup ###
26
+
27
+ Now, you can start the deployment process! To get your server setup with the file structure that Capistrano expects, you can run:
28
+
29
+ cap deploy:setup
30
+
31
+ This command will create the following folder structure on your server:
32
+
33
+ |-- deploy_to_path
34
+ |-- current (symlink)
35
+ |-- releases
36
+ |-- 20100512131539
37
+ |-- 20100509150741
38
+ |-- 20100509145325
39
+ |-- shared
40
+ |-- log
41
+ |-- web
42
+ |-- uploads
43
+
44
+ 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.
45
+
46
+ To deploy your application, simply run:
47
+
48
+ cap deploy
49
+
50
+ To configure database on production environment, run:
51
+
52
+ cap symfony:configure:database
53
+
54
+ To deploy your application for the first time, you can run:
55
+
56
+ cap deploy:cold
57
+
58
+ 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.
59
+
60
+ Now, whenever you need to deploy a new version of your code, just run:
61
+
62
+ cap deploy
63
+
64
+ If you need to deploy and run your migrations you can call:
65
+
66
+ cap deploy:migrations
67
+
68
+ We’ve also added a custom task to run your test suite on the production server. You can invoke this by calling:
69
+
70
+ cap deploy:tests:all
71
+
72
+ This will deploy the application, rebuild the test database, then run all of the tests.
73
+
74
+ Also, you have command to run your custom symfony tasks:
75
+
76
+ cap symfony:run_task
77
+
78
+ If you want to see all of the Capistrano tasks available, you can run:
79
+
80
+ cap -T
81
+
82
+ 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.
83
+
84
+ Contributors
85
+ ============
86
+
87
+ * everzet (owner): [http://github.com/everzet](http://github.com/everzet)
88
+ * Travis Roberts (creator of improved version): [http://blog.centresource.com/author/troberts/](http://blog.centresource.com/author/troberts/)
data/bin/capifony 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 capifony, 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 capifony."
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['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
42
+ load Gem.required_location('capifony', 'capifony.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, "/path/to/www/#{domain}"
49
+
50
+ set :repository, "#{domain}:/reps/#{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] capifonied!"
data/lib/capifony.rb ADDED
@@ -0,0 +1,178 @@
1
+ # Dirs that need to remain the same between deploys (shared dirs)
2
+ set :shared_children, %w(log web/uploads)
3
+
4
+ def prompt_with_default(var, default)
5
+ set(var) do
6
+ Capistrano::CLI.ui.ask "#{var} [#{default}] : "
7
+ end
8
+ set var, default if eval("#{var.to_s}.empty?")
9
+ end
10
+
11
+ namespace :deploy do
12
+ desc "Overwrite the start task to set the permissions on the project."
13
+ task :start do
14
+ symfony.configure.database
15
+ symfony.project.permissions
16
+ doctrine.build_all_and_load
17
+ end
18
+
19
+ desc "Overwrite the restart task because symfony doesn't need it."
20
+ task :restart do ; end
21
+
22
+ desc "Overwrite the stop task because symfony doesn't need it."
23
+ task :stop do ; end
24
+
25
+ desc "Customize migrate task because symfony doesn't need it."
26
+ task :migrate do
27
+ doctrine.migrate
28
+ end
29
+
30
+ desc "Symlink static directories that need to remain between deployments."
31
+ task :create_dirs do
32
+ if shared_children
33
+ shared_children.each do |link|
34
+ run "mkdir -p #{shared_path}/#{link}"
35
+ run "ln -nfs #{shared_path}/#{link} #{release_path}/#{link}"
36
+ end
37
+ end
38
+
39
+ run "touch #{shared_path}/databases.yml"
40
+ end
41
+
42
+ desc "Customize the finalize_update task to work with symfony."
43
+ task :finalize_update, :except => { :no_release => true } do
44
+ run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
45
+ run "mkdir -p #{latest_release}/cache"
46
+ create_dirs
47
+
48
+ if fetch(:normalize_asset_timestamps, true)
49
+ stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
50
+ asset_paths = %w(css images js).map { |p| "#{latest_release}/web/#{p}" }.join(" ")
51
+ run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
52
+ end
53
+ end
54
+
55
+ desc "Need to overwrite the deploy:cold task so it doesn't try to run the migrations."
56
+ task :cold do
57
+ update
58
+ start
59
+ end
60
+
61
+ desc "Deploy the application and run the test suite."
62
+ task :testall do
63
+ update_code
64
+ symlink
65
+ doctrine.build_all_and_load_test
66
+ symfony.tests.all
67
+ end
68
+ end
69
+
70
+ namespace :symlink do
71
+ desc "Symlink the database"
72
+ task :db do
73
+ run "ln -nfs #{shared_path}/databases.yml #{latest_release}/config/databases.yml"
74
+ end
75
+ end
76
+
77
+ namespace :symfony do
78
+ desc "Clears the cache"
79
+ task :cc do
80
+ run "php #{latest_release}/symfony cache:clear"
81
+ end
82
+
83
+ desc "Runs custom symfony task"
84
+ task :run_task do
85
+ prompt_with_default(:task_arguments, "cache:clear")
86
+
87
+ run "php #{latest_release}/symfony #{task_arguments}"
88
+ end
89
+
90
+ namespace :configure do
91
+ desc "Configure database DSN"
92
+ task :database do
93
+ prompt_with_default(:dsn, "mysql:host=localhost;dbname=example_dev")
94
+ prompt_with_default(:user, "root")
95
+ prompt_with_default(:pass, "")
96
+ dbclass = "sfDoctrineDatabase"
97
+
98
+ run "php #{latest_release}/symfony configure:database --class=#{dbclass} '#{dsn}' '#{user}' '#{pass}'"
99
+ end
100
+ end
101
+
102
+ namespace :project do
103
+ desc "Fixes symfony directory permissions"
104
+ task :permissions do
105
+ run "php #{latest_release}/symfony project:permissions"
106
+ end
107
+
108
+ desc "Optimizes a project for better performance"
109
+ task :optimize do
110
+ prompt_with_default(:application, "frontend")
111
+
112
+ run "php #{latest_release}/symfony project:optimize #{application}"
113
+ end
114
+
115
+ desc "Clears all non production environment controllers"
116
+ task :clear_controllers do
117
+ run "php #{latest_release}/symfony project:clear-controllers"
118
+ end
119
+ end
120
+
121
+ namespace :plugin do
122
+ desc "Publishes web assets for all plugins"
123
+ task :publish_assets do
124
+ run "php #{latest_release}/symfony plugin:publish-assets"
125
+ end
126
+ end
127
+
128
+ namespace :log do
129
+ desc "Clears log files"
130
+ task :clear do
131
+ run "php #{latest_release}/symfony log:clear"
132
+ end
133
+
134
+ desc "Rotates an application's log files"
135
+ task :rotate do
136
+ prompt_with_default(:application, "frontend")
137
+ prompt_with_default(:env, "prod")
138
+
139
+ run "php #{latest_release}/symfony log:rotate #{application} #{env}"
140
+ end
141
+ end
142
+
143
+ namespace :tests do
144
+ desc "Task to run all the tests for the application."
145
+ task :all do
146
+ run "php #{latest_release}/symfony test:all"
147
+ end
148
+ end
149
+ end
150
+
151
+ namespace :doctrine do
152
+ desc "Migrates database to current version"
153
+ task :migrate do
154
+ run "php #{latest_release}/symfony doctrine:migrate --env=prod"
155
+ end
156
+
157
+ desc "Generate code & database based on your schema"
158
+ task :build_all do
159
+ run "php #{latest_release}/symfony doctrine:build --all --no-confirmation --env=prod"
160
+ end
161
+
162
+ desc "Generate code & database based on your schema & load fixtures"
163
+ task :build_all_and_load do
164
+ run "php #{latest_release}/symfony doctrine:build --all --and-load --no-confirmation --env=prod"
165
+ end
166
+
167
+ desc "Generate code & database based on your schema & load fixtures for test environment"
168
+ task :build_all_and_load_test do
169
+ run "php #{latest_release}/symfony doctrine:build --all --and-load --no-confirmation --env=test"
170
+ end
171
+ end
172
+
173
+ after "deploy:finalize_update", # After finalizing update:
174
+ "symlink:db", # 1. Symlink database
175
+ "symfony:cc", # 2. Clear cache
176
+ "symfony:plugin:publish_assets", # 3. Publish plugin assets
177
+ "symfony:project:permissions" # 4. Fix project permissions
178
+ "symfony:project:clear_controllers" # 5. Clear controllers
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capifony
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Konstantin Kudryashov
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-03 00:00:00 +03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: capistrano
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 2
32
+ - 5
33
+ - 10
34
+ version: 2.5.10
35
+ type: :runtime
36
+ version_requirements: *id001
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 \xE2\x80\x9Crecipe\xE2\x80\x9D to work with symfony PHP applications.\n"
38
+ email: ever.zet@gmail.com
39
+ executables:
40
+ - capifony
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - bin/capifony
47
+ - lib/capifony.rb
48
+ - README
49
+ - LICENSE
50
+ - CHANGELOG
51
+ has_rdoc: false
52
+ homepage: http://everzet.com/projects/symfony-helpers/capifony
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project: capifony
81
+ rubygems_version: 1.3.7
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Deploying symfony PHP applications with Capistrano.
85
+ test_files: []
86
+