09.22
ruby
saved
ian
Note
This is version 0.1 of a set of cake deploy tasks. Lots to do including:
1. handling rollback if the transaction fails;
2. deleting the app_for_deletion dir if the transaction succeeds;
3. abstracting out some of the tasks, e.g. detecting if an svn_username or svn_password is set and using the appropriate commands.
This is version 0.1 of a set of cake deploy tasks. Lots to do including:
1. handling rollback if the transaction fails;
2. deleting the app_for_deletion dir if the transaction succeeds;
3. abstracting out some of the tasks, e.g. detecting if an svn_username or svn_password is set and using the appropriate commands.
- # This defines a deployment "recipe" that you can feed to capistrano
- # (http://manuals.rubyonrails.com/read/book/17). It allows you to automate
- # (among other things) the deployment of your application.
- # =============================================================================
- # REQUIRED VARIABLES
- # =============================================================================
- # You must always specify the application and repository for every recipe. The
- # repository must be the URL of the repository you want this recipe to
- # correspond to. The deploy_to path must be the path on each machine that will
- # form the root of the application path.
- set :application, "YOUR APP NAME"
- set :repository, "YORU REPOSITORY PATH"
- # =============================================================================
- # ROLES
- # =============================================================================
- # You can define any number of roles, each of which contains any number of
- # machines. Roles might include such things as :web, or :app, or :db, defining
- # what the purpose of each machine is. You can also specify options that can
- # be used to single out a specific subset of boxes in a particular role, like
- # :primary => true.
- role :web, "" # WHERE TO DEPLOY TO e.g. www.mywebsite.com
- #role :app, "" # not used - if the application code lives separately to apache, the app box is named here
- #role :db, "" # not used - if the database lives separately to apache & app, the database box is named here
- # =============================================================================
- # OPTIONAL VARIABLES
- # =============================================================================
- # set :deploy_to, "/path/to/app" # defaults to "/u/apps/#{application}"
- # set :user, "flippy" # defaults to the currently logged in user
- # set :scm, :darcs # defaults to :subversion
- # set :svn, "/path/to/svn" # defaults to searching the PATH
- # set :darcs, "/path/to/darcs" # defaults to searching the PATH
- # set :cvs, "/path/to/cvs" # defaults to searching the PATH
- # set :gateway, "gate.host.com" # default to no gateway
- set :app_root, "" # the full path to the app directory of your cake installation, e.g. /home/blah/www/app
- set :archive_to, "" # the full path to the archive directory to store tarred backups e.g. /home/blah/archive
- set :tmp_app_dir, "app_for_deletion" # the task temp stores the current app as this dir so rollback is easier
- set :svn_username, "" # if your svn is password protected, the username here
- set :svn_password, "" # if your svn is password protected, the password here
- set :checkout, "export" # I also prefer export, change to checkout if you prefer
- # =============================================================================
- # SSH OPTIONS
- # =============================================================================
- # ssh_options[:keys] = %w(/path/to/my/key /path/to/another/key)
- # ssh_options[:port] = 25
- # ssh_options[:username] = "your ssh username here"
- # =============================================================================
- # TASKS
- # =============================================================================
- # Define tasks that run on all (or only some) of the machines. You can specify
- # a role (or set of roles) that each task should be executed on. You can also
- # narrow the set of servers to a subset of a role by specifying options, which
- # must match the options given for the servers to select (like :primary => true)
- # Tasks may take advantage of several different helper methods to interact
- # with the remote server(s). These are:
- #
- # * run(command, options={}, &block): execute the given command on all servers
- # associated with the current task, in parallel. The block, if given, should
- # accept three parameters: the communication channel, a symbol identifying the
- # type of stream (:err or :out), and the data. The block is invoked for all
- # output from the command, allowing you to inspect output and act
- # accordingly.
- # * sudo(command, options={}, &block): same as run, but it executes the command
- # via sudo.
- # * delete(path, options={}): deletes the given file or directory from all
- # associated servers. If :recursive => true is given in the options, the
- # delete uses "rm -rf" instead of "rm -f".
- # * put(buffer, path, options={}): creates or overwrites a file at "path" on
- # all associated servers, populating it with the contents of "buffer". You
- # can specify :mode as an integer value, which will be used to set the mode
- # on the file.
- # * render(template, options={}) or render(options={}): renders the given
- # template and returns a string. Alternatively, if the :template key is given,
- # it will be treated as the contents of the template to render. Any other keys
- # are treated as local variables, which are made available to the (ERb)
- # template.
- desc "Archive current version to the archives dir as a tarred file"
- task :archive do
- date = Time.now.strftime("%b_%d_%Y_%H_%M_%S")
- run "tar cvzf #{archive_to}/app_#{date}.tar.gz #{app_root}"
- end
- desc "Move current version to a temp dir ready for deletion"
- task :move_for_deletion do
- run "mv #{app_root} #{tmp_app_dir}"
- end
- desc "Export app only from password protected SVN repos to app folder"
- task :update_app do
- run "svn -q #{checkout} #{repository} #{app_root} --username #{svn_username} --password #{svn_password} --no-auth-cache"
- end
- desc "Set permissions correctly on tmp file"
- task :set_perms do
- run "chmod 777 #{app_root}/tmp"
- run "chmod 777 #{app_root}/tmp/cache"
- run "chmod 777 #{app_root}/tmp/cache/models"
- run "chmod 777 #{app_root}/tmp/cache/persistent"
- run "chmod 777 #{app_root}/tmp/cache/views"
- run "chmod -R 777 #{app_root}/tmp/logs"
- #run "chmod 777 #{app_root}/tmp/sessions" not used
- #run "chmod 777 #{app_root}/tmp/tests" not used
- end
- # You can use "transaction" to indicate that if any of the tasks within it fail,
- # all should be rolled back (for each task that specifies an on_rollback
- # handler).
- desc "All deployment tasks wrapped up into a transaction"
- task :deploy do
- transaction do
- archive
- move_for_deletion
- update_app
- set_perms
- end
- end
Parsed in 0.023 seconds, using GeSHi 1.0.7.14