diff options
Diffstat (limited to 'lib/chef/resource/deploy.rb')
-rw-r--r-- | lib/chef/resource/deploy.rb | 266 |
1 files changed, 216 insertions, 50 deletions
diff --git a/lib/chef/resource/deploy.rb b/lib/chef/resource/deploy.rb index fade82a972..9beeb02534 100644 --- a/lib/chef/resource/deploy.rb +++ b/lib/chef/resource/deploy.rb @@ -83,7 +83,6 @@ class Chef @keep_releases = 5 @enable_checkout = true @checkout_branch = "deploy" - @timeout = nil end # where the checked out/cloned code goes @@ -106,18 +105,42 @@ class Chef end # note: deploy_to is your application "meta-root." - attribute :deploy_to, :kind_of => [ String ] + def deploy_to(arg=nil) + set_or_return( + :deploy_to, + arg, + :kind_of => [ String ] + ) + end - attribute :repo, :kind_of => [ String ] + def repo(arg=nil) + set_or_return( + :repo, + arg, + :kind_of => [ String ] + ) + end alias :repository :repo - attribute :remote, :kind_of => [ String ] + def remote(arg=nil) + set_or_return( + :remote, + arg, + :kind_of => [ String ] + ) + end - attribute :role, :kind_of => [ String ] + def role(arg=nil) + set_or_return( + :role, + arg, + :kind_of => [ String ] + ) + end - def restart_command(arg=NULL_ARG, &block) - arg = block if block_given? - nillable_set_or_return( + def restart_command(arg=nil, &block) + arg ||= block + set_or_return( :restart_command, arg, :kind_of => [ String, Proc ] @@ -125,60 +148,155 @@ class Chef end alias :restart :restart_command - attribute :migrate, :kind_of => [ TrueClass, FalseClass ] + def migrate(arg=nil) + set_or_return( + :migrate, + arg, + :kind_of => [ TrueClass, FalseClass ] + ) + end - attribute :migration_command, kind_of: String + def migration_command(arg=nil) + set_or_return( + :migration_command, + arg, + :kind_of => [ String ] + ) + end - attribute :rollback_on_error, :kind_of => [ TrueClass, FalseClass ] + def rollback_on_error(arg=nil) + set_or_return( + :rollback_on_error, + arg, + :kind_of => [ TrueClass, FalseClass ] + ) + end - attribute :user, kind_of: String + def user(arg=nil) + set_or_return( + :user, + arg, + :kind_of => [ String ] + ) + end - attribute :group, kind_of: [ String ] + def group(arg=nil) + set_or_return( + :group, + arg, + :kind_of => [ String ] + ) + end - attribute :enable_submodules, kind_of: [ TrueClass, FalseClass ] + def enable_submodules(arg=nil) + set_or_return( + :enable_submodules, + arg, + :kind_of => [ TrueClass, FalseClass ] + ) + end - attribute :shallow_clone, kind_of: [ TrueClass, FalseClass ] + def shallow_clone(arg=nil) + set_or_return( + :shallow_clone, + arg, + :kind_of => [ TrueClass, FalseClass ] + ) + end - attribute :repository_cache, kind_of: String + def repository_cache(arg=nil) + set_or_return( + :repository_cache, + arg, + :kind_of => [ String ] + ) + end - attribute :copy_exclude, kind_of: String + def copy_exclude(arg=nil) + set_or_return( + :copy_exclude, + arg, + :kind_of => [ String ] + ) + end - attribute :revision, kind_of: String + def revision(arg=nil) + set_or_return( + :revision, + arg, + :kind_of => [ String ] + ) + end alias :branch :revision - attribute :git_ssh_wrapper, kind_of: String + def git_ssh_wrapper(arg=nil) + set_or_return( + :git_ssh_wrapper, + arg, + :kind_of => [ String ] + ) + end alias :ssh_wrapper :git_ssh_wrapper - attribute :svn_username, kind_of: String + def svn_username(arg=nil) + set_or_return( + :svn_username, + arg, + :kind_of => [ String ] + ) + end - attribute :svn_password, kind_of: String + def svn_password(arg=nil) + set_or_return( + :svn_password, + arg, + :kind_of => [ String ] + ) + end - attribute :svn_arguments, kind_of: String + def svn_arguments(arg=nil) + set_or_return( + :svn_arguments, + arg, + :kind_of => [ String ] + ) + end - attribute :svn_info_args, kind_of: String + def svn_info_args(arg=nil) + set_or_return( + :svn_arguments, + arg, + :kind_of => [ String ]) + end - def scm_provider(arg=NULL_ARG) + def scm_provider(arg=nil) klass = if arg.kind_of?(String) || arg.kind_of?(Symbol) lookup_provider_constant(arg) else arg end - nillable_set_or_return( + set_or_return( :scm_provider, klass, :kind_of => [ Class ] ) end - attribute :svn_force_export, kind_of: [ TrueClass, FalseClass ] + def svn_force_export(arg=nil) + set_or_return( + :svn_force_export, + arg, + :kind_of => [ TrueClass, FalseClass ] + ) + end - def environment(arg=NULL_ARG) + def environment(arg=nil) if arg.is_a?(String) Chef::Log.debug "Setting RAILS_ENV, RACK_ENV, and MERB_ENV to `#{arg}'" Chef::Log.warn "[DEPRECATED] please modify your deploy recipe or attributes to set the environment using a hash" arg = {"RAILS_ENV"=>arg,"MERB_ENV"=>arg,"RACK_ENV"=>arg} end - nillable_set_or_return( + set_or_return( :environment, arg, :kind_of => [ Hash ] @@ -186,8 +304,8 @@ class Chef end # The number of old release directories to keep around after cleanup - def keep_releases(arg=NULL_ARG) - [nillable_set_or_return( + def keep_releases(arg=nil) + [set_or_return( :keep_releases, arg, :kind_of => [ Integer ]), 1].max @@ -197,7 +315,13 @@ class Chef # SCM clone/checkout before symlinking. Use this to get rid of files and # directories you want to be shared between releases. # Default: ["log", "tmp/pids", "public/system"] - attribute :purge_before_symlink, kind_of: Array + def purge_before_symlink(arg=nil) + set_or_return( + :purge_before_symlink, + arg, + :kind_of => Array + ) + end # An array of paths, relative to your app's root, where you expect dirs to # exist before symlinking. This runs after #purge_before_symlink, so you @@ -207,7 +331,13 @@ class Chef # then specify tmp here so that the tmp directory will exist when you # symlink the pids directory in to the current release. # Default: ["tmp", "public", "config"] - attribute :create_dirs_before_symlink, kind_of: Array + def create_dirs_before_symlink(arg=nil) + set_or_return( + :create_dirs_before_symlink, + arg, + :kind_of => Array + ) + end # A Hash of shared/dir/path => release/dir/path. This attribute determines # which files and dirs in the shared directory get symlinked to the current @@ -215,7 +345,13 @@ class Chef # $shared/pids that you would like to symlink as $current_release/tmp/pids # you specify it as "pids" => "tmp/pids" # Default {"system" => "public/system", "pids" => "tmp/pids", "log" => "log"} - attribute :symlinks, kind_of: Hash + def symlinks(arg=nil) + set_or_return( + :symlinks, + arg, + :kind_of => Hash + ) + end # A Hash of shared/dir/path => release/dir/path. This attribute determines # which files in the shared directory get symlinked to the current release @@ -224,44 +360,74 @@ class Chef # For a rails/merb app, this is used to link in a known good database.yml # (with the production db password) before running migrate. # Default {"config/database.yml" => "config/database.yml"} - attribute :symlink_before_migrate, kind_of: Hash + def symlink_before_migrate(arg=nil) + set_or_return( + :symlink_before_migrate, + arg, + :kind_of => Hash + ) + end # Callback fires before migration is run. - def before_migrate(arg=NULL_ARG, &block) - arg = block if block_given? - nillable_set_or_return(:before_migrate, arg, kind_of: [Proc, String]) + def before_migrate(arg=nil, &block) + arg ||= block + set_or_return(:before_migrate, arg, :kind_of => [Proc, String]) end # Callback fires before symlinking - def before_symlink(arg=NULL_ARG, &block) - arg = block if block_given? - nillable_set_or_return(:before_symlink, arg, kind_of: [Proc, String]) + def before_symlink(arg=nil, &block) + arg ||= block + set_or_return(:before_symlink, arg, :kind_of => [Proc, String]) end # Callback fires before restart - def before_restart(arg=NULL_ARG, &block) - arg = block if block_given? - nillable_set_or_return(:before_restart, arg, kind_of: [Proc, String]) + def before_restart(arg=nil, &block) + arg ||= block + set_or_return(:before_restart, arg, :kind_of => [Proc, String]) end # Callback fires after restart - def after_restart(arg=NULL_ARG, &block) - arg = block if block_given? - nillable_set_or_return(:after_restart, arg, kind_of: [Proc, String]) + def after_restart(arg=nil, &block) + arg ||= block + set_or_return(:after_restart, arg, :kind_of => [Proc, String]) end - attribute :additional_remotes, kind_of: Hash + def additional_remotes(arg=nil) + set_or_return( + :additional_remotes, + arg, + :kind_of => Hash + ) + end - attribute :enable_checkout, kind_of: [ TrueClass, FalseClass ] + def enable_checkout(arg=nil) + set_or_return( + :enable_checkout, + arg, + :kind_of => [TrueClass, FalseClass] + ) + end - attribute :checkout_branch, kind_of: String + def checkout_branch(arg=nil) + set_or_return( + :checkout_branch, + arg, + :kind_of => String + ) + end # FIXME The Deploy resource may be passed to an SCM provider as its # resource. The SCM provider knows that SCM resources can specify a # timeout for SCM operations. The deploy resource must therefore support # a timeout method, but the timeout it describes is for SCM operations, # not the overall deployment. This is potentially confusing. - attribute :timeout, kind_of: Integer + def timeout(arg=nil) + set_or_return( + :timeout, + arg, + :kind_of => Integer + ) + end end end |