fpauser-vlad 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,43 @@
1
+ == Converting from Capistrano
2
+
3
+ * 'set scm' is removed. Vlad.load :scm => :something if you don't use subversion.
4
+ * 'task' blocks are renamed to 'remote_task'.
5
+ * Most variables are the same. See variables.txt for details.
6
+ * No +with_command+ / +sudo+ / +via+ wonkiness
7
+ * Uses real ssh so env vars and the like are not a problem
8
+ - no +with_env+ as a result.
9
+ * Vlad doesn't use ':no_release' or ':primary'.
10
+ - If you have a task that needs to run on only one host from a role,
11
+ you should declare a new role for that host:
12
+
13
+ role :master_db, "master.example.com"
14
+
15
+ ..and then override the role for the task you want to limit:
16
+
17
+ Rake::Task["mytask"].options[:roles] = :master_db
18
+
19
+ * The 'host' method can be used to consolidate multiple 'role' calls.
20
+ - host "www.example.com", :app, :web, :db
21
+ specifies a host with three roles.
22
+ * migrate_env is now migrate_args.
23
+ * Vlad doesn't have before/after magic add-on tasks.
24
+
25
+ == BEFORE:
26
+
27
+ set :application, "rubyholic"
28
+ set :domain, "zenspider.textdriven.com"
29
+ set :repository, "svn://svn.example.com/rubyholic/branches/stable"
30
+ set :deploy_to, "/users/home/zenspider/domains/new.rubyholic.com"
31
+
32
+ set :user, "zenspider"
33
+ set :use_sudo, false
34
+
35
+ role :web, domain
36
+ role :app, domain
37
+ role :db, domain, :primary => true
38
+
39
+ == AFTER:
40
+
41
+ set :domain, "zenspider.textdriven.com"
42
+ set :repository, "svn://svn.example.com/rubyholic/branches/stable"
43
+ set :deploy_to, "/users/home/zenspider/domains/new.rubyholic.com"
data/doco/perforce.txt ADDED
@@ -0,0 +1,5 @@
1
+ # Using Perforce
2
+
3
+ TODO: write real doco.
4
+
5
+ Set up a .p4config file and put it in the client's scm directories.
@@ -0,0 +1,79 @@
1
+
2
+ == Core Variables
3
+
4
+ repository:: REQUIRED: Repository path: e.g. http://repo.example.com/svn
5
+ deploy_to:: REQUIRED: Deploy path on target machines. e.g. /var/www/app
6
+ domain:: REQUIRED: Used for the common case of a single target
7
+ server. e.g. example.com
8
+ current_path:: The full path on the remote host that will be symlinked
9
+ as 'current'. Defaults to "#{deploy_to}/current".
10
+ current_release:: The full path to the current release's actual location.
11
+ Defaults to "#{releases_path}/#{releases.last}".
12
+ deploy_timestamped:: Create timestamped release directories instead of using
13
+ revision numbers. Defaults to true.
14
+ deploy_via:: Which SCM command should be used when deploying the app.
15
+ Defaults to "export".
16
+ latest_release:: The most recent release, which may not yet have been
17
+ symlinked. Defaults to release_path.
18
+ migrate_args:: Set this to change the RAILS_ENV that 'rake db:migrate'
19
+ will run under. Defaults to "".
20
+ migrate_target:: Set this if you need to specify a particular migration
21
+ 'VERSION' number. Defaults to "latest".
22
+ rails_env:: Specifies the RAILS_ENV environment variable that will
23
+ be used. Defaults to "production".
24
+ rake_cmd:: Set this if you need to specify an alternate path to
25
+ 'rake'. Defaults to "rake".
26
+ release_name:: Name of the release directory, if deploy_timestamped is
27
+ true. Defaults to timestamp: "YYYYMMDDHHMMSS".
28
+ release_path:: Path to this release, which may not have been created
29
+ yet. Defaults to "#{releases_path}/#{release_name}".
30
+ releases:: An array of all existing releases, oldest first.
31
+ Defaults to latest release directory name.
32
+ releases_path:: Full path to the 'releases' directory on the remote host.
33
+ Defaults to "#{deploy_to}/releases".
34
+ revision:: Revision to use for release. Defaults to 'head'.
35
+ rsync_cmd:: Path to rsync command. Defaults to "rsync".
36
+ rsync_flags:: Flags for rsync. Defaults to ['-azP', '--delete'].
37
+ scm_path:: Path on the remote host that will be used as 'working
38
+ space' for SCM tasks. Defaults to "#{deploy_to}/scm".
39
+ shared_path:: Full path to remote 'shared' directory, symlinked into
40
+ your app by default. Defaults to "#{deploy_to}/shared".
41
+ ssh_cmd:: Path to ssh. Defaults to "ssh".
42
+ ssh_flags:: Flags for ssh. Defaults to [].
43
+ sudo_cmd:: Path to sudo command. Defaults to "sudo".
44
+ sudo_flags:: Flogs for sudo. Defaults to ["-p Password:"].
45
+ sudo_prompt:: Regexp for sudo password prompt. Defaults to /^Password:/.
46
+ sudo_password:: Asks for password when referenced.
47
+ umask:: Sets your umask value. Defaults to "02".
48
+
49
+ == Apache Web Variables:
50
+
51
+ web_command:: Command to execute when controlling the web server.
52
+ Defaults to "apachectl".
53
+
54
+ == Mongrel App Variables:
55
+
56
+ mongrel_address:: Defaults to "127.0.0.1"
57
+ mongrel_clean:: Defaults to false
58
+ mongrel_command:: Defaults to 'mongrel_rails'
59
+ mongrel_conf:: Defaults to "#{shared_path}/mongrel_cluster.conf"
60
+ mongrel_config_script:: Defaults to nil
61
+ mongrel_environment:: Defaults to "production"
62
+ mongrel_group:: Defaults to nil
63
+ mongrel_log_file:: Defaults to nil
64
+ mongrel_pid_file:: Defaults to nil
65
+ mongrel_port:: Defaults to 8000
66
+ mongrel_prefix:: Defaults to nil
67
+ mongrel_servers:: Defaults to 2
68
+ mongrel_user:: Defaults to nil
69
+
70
+ == Perforce SCM Variables:
71
+
72
+ p4_cmd:: The perforce command to use. Defaults to "p4"
73
+ source:: A perforce SCM worker instance.
74
+
75
+ == Subversion SCM Variables:
76
+
77
+ source:: A subversion SCM worker instance.
78
+ svn_cmd:: The subversion command to use. Defaults to "svn"
79
+
data/lib/vlad.rb ADDED
@@ -0,0 +1,78 @@
1
+ require 'rubygems'
2
+ require 'thread'
3
+ require 'rake/remote_task'
4
+
5
+ $TESTING ||= false
6
+
7
+ ##
8
+ # Vlad the Deployer - Pragmatic application deployment automation,
9
+ # without mercy.
10
+ #
11
+ # Please read doco/getting_started.txt or http://rubyhitsquad.com/
12
+ #
13
+ # === Basic scenario:
14
+ #
15
+ # 1. rake vlad:setup (first time only)
16
+ # 2. rake vlad:update
17
+ # 3. rake vlad:migrate (optional)
18
+ # 4. rake vlad:start
19
+
20
+ module Vlad
21
+
22
+ ##
23
+ # This is the version of Vlad you are running.
24
+ VERSION = '2.2.0'
25
+
26
+ ##
27
+ # Loads tasks file +tasks_file+ and various recipe styles as a hash
28
+ # of category/style pairs. Recipes default to:
29
+ #
30
+ # :app => :passenger
31
+ # :config => 'config/deploy.rb'
32
+ # :core => :core
33
+ # :scm => :subversion
34
+ # :web => :apache
35
+ #
36
+ # You can override individual values and/or set to nil to
37
+ # deactivate. :config will get loaded last to ensure that user
38
+ # variables override default values.
39
+ #
40
+ # And by all means, feel free to skip this entirely if it doesn't
41
+ # fit for you. All it does is a fancy-pants require. Require
42
+ # whatever files you need as you see fit straight from your
43
+ # Rakefile. YAY for simple and clean!
44
+
45
+ def self.load options = {}
46
+ options = {:config => options} if String === options
47
+ order = [:core, :type, :app, :config, :scm, :web]
48
+ order += options.keys - order
49
+
50
+ recipes = {
51
+ :app => :passenger,
52
+ :type => :rails,
53
+ :config => 'config/deploy.rb',
54
+ :core => :core,
55
+ :scm => :subversion,
56
+ :web => :apache,
57
+ }.merge(options)
58
+
59
+ order.each do |flavor|
60
+ recipe = recipes[flavor]
61
+ next if recipe.nil? or flavor == :config
62
+ require "vlad/#{recipe}"
63
+ end
64
+
65
+ Kernel.load recipes[:config]
66
+ Kernel.load "config/deploy_#{ENV['to']}.rb" if ENV['to']
67
+ end
68
+ end
69
+
70
+ class String #:nodoc:
71
+ def cleanup
72
+ if ENV['FULL'] then
73
+ gsub(/\s+/, ' ').strip
74
+ else
75
+ self[/\A.*?\./]
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,37 @@
1
+ require 'vlad'
2
+
3
+ namespace :vlad do
4
+ ##
5
+ # Apache web server
6
+
7
+ set :web_command, "apachectl"
8
+
9
+ desc "(Re)Start the web servers"
10
+
11
+ remote_task :start_web, :roles => :web do
12
+ run "#{web_command} restart"
13
+ end
14
+
15
+ desc "Stop the web servers"
16
+
17
+ remote_task :stop_web, :roles => :web do
18
+ run "#{web_command} stop"
19
+ end
20
+
21
+ ##
22
+ # Everything HTTP.
23
+
24
+ desc "(Re)Start the web and app servers"
25
+
26
+ remote_task :start do
27
+ Rake::Task['vlad:start_app'].invoke
28
+ Rake::Task['vlad:start_web'].invoke
29
+ end
30
+
31
+ desc "Stop the web and app servers"
32
+
33
+ remote_task :stop do
34
+ Rake::Task['vlad:stop_app'].invoke
35
+ Rake::Task['vlad:stop_web'].invoke
36
+ end
37
+ end
data/lib/vlad/core.rb ADDED
@@ -0,0 +1,195 @@
1
+ require 'vlad'
2
+
3
+ ##
4
+ # used by update, out here so we can ensure all threads have the same value
5
+ def now
6
+ @now ||= Time.now.utc.strftime("%Y%m%d%H%M.%S")
7
+ end
8
+
9
+ namespace :vlad do
10
+ desc "Show the vlad setup. This is all the default variables for vlad
11
+ tasks.".cleanup
12
+
13
+ task :debug do
14
+ require 'yaml'
15
+
16
+ # force them into values
17
+ Rake::RemoteTask.env.keys.each do |key|
18
+ next if key =~ /_release|releases|sudo_password/
19
+ Rake::RemoteTask.fetch key
20
+ end
21
+
22
+ puts "# Environment:"
23
+ puts
24
+ y Rake::RemoteTask.env
25
+ puts "# Roles:"
26
+ y Rake::RemoteTask.roles
27
+ end
28
+
29
+ desc "Setup your servers. Before you can use any of the deployment
30
+ tasks with your project, you will need to make sure all of your
31
+ servers have been prepared with 'rake vlad:setup'. It is safe to
32
+ run this task on servers that have already been set up; it will
33
+ not destroy any deployed revisions or data.".cleanup
34
+
35
+ task :setup do
36
+ Rake::Task['vlad:setup_app'].invoke
37
+ end
38
+
39
+ desc "Prepares application servers for deployment.".cleanup
40
+
41
+ remote_task :setup_app, :roles => :app do
42
+ dirs = [deploy_to, releases_path, scm_path, shared_path]
43
+ dirs += shared_paths.keys.map { |d| File.join(shared_path, d) }
44
+ dirs = dirs.join(' ')
45
+
46
+ commands = [
47
+ "umask #{umask}",
48
+ "mkdir -p #{dirs}"
49
+ ]
50
+ commands << "chown #{perm_owner} #{dirs}" if perm_owner
51
+ commands << "chgrp #{perm_group} #{dirs}" if perm_group
52
+
53
+ run commands.join(' && ')
54
+ end
55
+
56
+ desc "Updates your application server to the latest revision. Syncs
57
+ a copy of the repository, exports it as the latest release, fixes
58
+ up your symlinks, symlinks the latest revision to current and logs
59
+ the update.".cleanup
60
+
61
+ remote_task :update, :roles => :app do
62
+ symlink = false
63
+ begin
64
+ commands = [
65
+ "umask #{umask}",
66
+ "cd #{scm_path}",
67
+ "#{source.checkout revision, scm_path}",
68
+ "#{source.export revision, release_path}",
69
+ "chmod -R g+w #{latest_release}",
70
+ ]
71
+ unless shared_paths.empty?
72
+ commands << "rm -rf #{shared_paths.values.map { |p| File.join(latest_release, p) }.join(' ')}"
73
+ end
74
+ unless mkdirs.empty?
75
+ dirs = mkdirs.map { |d| File.join(latest_release, d) }.join(' ')
76
+ commands << "mkdir -p #{dirs}"
77
+ commands << "chown -R #{perm_owner} #{dirs}" if perm_owner
78
+ commands << "chgrp -R #{perm_group} #{dirs}" if perm_group
79
+ end
80
+
81
+ commands << "chown -R #{perm_owner} #{latest_release}" if perm_owner
82
+ commands << "chgrp -R #{perm_group} #{latest_release}" if perm_group
83
+
84
+ run commands.join(" && ")
85
+ Rake::Task['vlad:update_symlinks'].invoke
86
+
87
+ symlink = true
88
+ commands = [
89
+ "umask #{umask}",
90
+ "rm -f #{current_path}",
91
+ "ln -s #{latest_release} #{current_path}",
92
+ "echo #{now} $USER #{revision} #{File.basename(release_path)} >> #{deploy_to}/revisions.log"
93
+ ]
94
+ commands << "chown #{perm_owner} #{deploy_to}/revisions.log" if perm_owner
95
+ commands << "chgrp #{perm_group} #{deploy_to}/revisions.log" if perm_group
96
+
97
+ run commands.join(' && ')
98
+ rescue => e
99
+ run "rm -f #{current_path} && ln -s #{previous_release} #{current_path}" if
100
+ symlink
101
+ run "rm -rf #{release_path}"
102
+ raise e
103
+ end
104
+ end
105
+
106
+ desc "Updates the symlinks for shared paths".cleanup
107
+
108
+ remote_task :update_symlinks, :roles => :app do
109
+ unless shared_paths.empty?
110
+ ops = shared_paths.map do |sp, rp|
111
+ "ln -s #{shared_path}/#{sp} #{latest_release}/#{rp}"
112
+ end
113
+ run ops.join(' && ') unless ops.empty?
114
+ end
115
+ end
116
+
117
+ desc "Invoke a single command on every remote server. This is useful for
118
+ performing one-off commands that may not require a full task to be written
119
+ for them. Simply specify the command to execute via the COMMAND
120
+ environment variable. To execute the command only on certain roles,
121
+ specify the ROLES environment variable as a comma-delimited list of role
122
+ names.
123
+
124
+ $ rake vlad:invoke COMMAND='uptime'".cleanup
125
+
126
+ remote_task :invoke do
127
+ command = ENV["COMMAND"]
128
+ abort "Please specify a command to execute on the remote servers (via the COMMAND environment variable)" unless command
129
+ run(command)
130
+ end
131
+
132
+ desc "Copy arbitrary files to the currently deployed version using
133
+ FILES=a,b,c. This is useful for updating files piecemeal when you
134
+ need to quickly deploy only a single file.
135
+
136
+ To use this task, specify the files and directories you want to copy as a
137
+ comma-delimited list in the FILES environment variable. All directories
138
+ will be processed recursively, with all files being pushed to the
139
+ deployment servers. Any file or directory starting with a '.' character
140
+ will be ignored.
141
+
142
+ $ rake vlad:upload FILES=templates,controller.rb".cleanup
143
+
144
+ remote_task :upload do
145
+ file_list = (ENV["FILES"] || "").split(",")
146
+
147
+ files = file_list.map do |f|
148
+ f = f.strip
149
+ File.directory?(f) ? Dir["#{f}/**/*"] : f
150
+ end.flatten
151
+
152
+ files = files.reject { |f| File.directory?(f) || File.basename(f)[0] == ?. }
153
+
154
+ abort "Please specify at least one file to update (via the FILES environment variable)" if files.empty?
155
+
156
+ files.each do |file|
157
+ rsync file, File.join(current_path, file)
158
+ end
159
+ end
160
+
161
+ desc "Rolls back to a previous version and restarts. This is handy if you
162
+ ever discover that you've deployed a lemon; 'rake vlad:rollback' and
163
+ you're right back where you were, on the previously deployed
164
+ version.".cleanup
165
+
166
+ remote_task :rollback do
167
+ if releases.length < 2 then
168
+ abort "could not rollback the code because there is no prior release"
169
+ else
170
+ run "rm -f #{current_path}; ln -s #{previous_release} #{current_path} && rm -rf #{current_release}"
171
+ end
172
+
173
+ Rake::Task['vlad:start'].invoke
174
+ end
175
+
176
+ desc "Clean up old releases. By default, the last 5 releases are kept on
177
+ each server (though you can change this with the keep_releases variable).
178
+ All other deployed revisions are removed from the servers.".cleanup
179
+
180
+ remote_task :cleanup do
181
+ max = keep_releases
182
+ if releases.length <= max then
183
+ puts "no old releases to clean up #{releases.length} <= #{max}"
184
+ else
185
+ puts "keeping #{max} of #{releases.length} deployed releases"
186
+
187
+ directories = (releases - releases.last(max)).map { |release|
188
+ File.join(releases_path, release)
189
+ }.join(" ")
190
+
191
+ run "rm -rf #{directories}"
192
+ end
193
+ end
194
+
195
+ end # namespace vlad
@@ -0,0 +1,20 @@
1
+ require 'vlad'
2
+
3
+ ##
4
+ # See the following documents for recipes:
5
+ #
6
+ # * http://clarkware.com/cgi/blosxom/2007/01/05/CustomMaintenancePages
7
+ # * http://blog.nodeta.fi/2009/03/11/stopping-your-rails-application-with-phusion-passenger/
8
+ #
9
+
10
+ namespace :vlad do
11
+ namespace :maintenance do
12
+ remote_task :on, :roles => [:web] do
13
+ run "cp -f #{shared_path}/config/maintenance.html #{shared_path}/system/"
14
+ end
15
+
16
+ remote_task :off, :roles => [:web] do
17
+ run "rm -f #{shared_path}/system/maintenance.html"
18
+ end
19
+ end
20
+ end