Class: Chef::Resource::Deploy

Inherits:
Chef::Resource show all
Defined in:
lib/chef/resource/deploy.rb

Overview

Deploy: Deploy apps from a source control repository.

Callbacks: Callbacks can be a block or a string. If given a block, the code is evaluated as an embedded recipe, and run at the specified point in the deploy process. If given a string, the string is taken as a path to a callback file/recipe. Paths are evaluated relative to the release directory. Callback files can contain chef code (resources, etc.)

Direct Known Subclasses

DeployRevision, TimestampedDeploy

Constant Summary

Constants inherited from Chef::Resource

FORBIDDEN_IVARS, HIDDEN_IVARS

Constants included from Mixin::ShellOut

Mixin::ShellOut::DEPRECATED_OPTIONS

Instance Attribute Summary

Attributes inherited from Chef::Resource

#allowed_actions, #cookbook_name, #declared_type, #default_guard_interpreter, #elapsed_time, #enclosing_provider, #ignore_failure, #not_if_args, #only_if_args, #params, #recipe_name, #resource_initializing, #retries, #retry_delay, #run_context, #sensitive, #source_line, #updated

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Chef::Resource

action, #action, #action=, action_class, #after_created, allowed_actions, allowed_actions=, #as_json, #before_notifications, #cookbook_version, #current_value, #current_value_does_not_exist!, #custom_exception_message, #customize_exception, declare_action_class, #declared_key, default_action, default_action=, #defined_at, #delayed_notifications, dsl_name, #events, #guard_interpreter, #identity, identity_attr, identity_property, #immediate_notifications, inherited, #inspect, #is, json_create, load_current_value, #load_from, #lookup_provider_constant, #method_missing, #name, #node, #noop, #not_if, #notifies, #notifies_before, #notifies_delayed, #notifies_immediately, #only_if, #provider, #provider=, #provider_for_action, provides, provides?, #resolve_notification_references, resource_for_node, resource_matching_short_name, resource_name, #resource_name, resource_name=, #resources, #run_action, #should_skip?, sorted_descendants, #source_line_file, #source_line_number, state_attrs, #state_for_resource_reporter, #subscribes, #supports, #supports=, #to_hash, #to_json, #to_s, #to_text, #updated?, #updated_by_last_action, #updated_by_last_action?, use_automatic_resource_name, #validate_action, #validate_resource_spec!

Methods included from Mixin::Provides

#provided_as, #provides, #provides?

Methods included from Mixin::DescendantsTracker

#descendants, descendants, direct_descendants, #direct_descendants, find_descendants_by_name, #find_descendants_by_name, #inherited, store_inherited

Methods included from Mixin::ConvertToClassName

#constantize, #convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #normalize_snake_case_name, #snake_case_basename

Methods included from DeprecatedLWRPClass

#deprecated_constants, #register_deprecated_lwrp_class

Methods included from Mixin::Deprecation

#deprecated_attr, #deprecated_attr_reader, #deprecated_attr_writer, #deprecated_ivar

Methods included from Mixin::Properties

included, #property_is_set?, #reset_property

Methods included from Mixin::ParamsValidate

#lazy, #set_or_return, #validate

Methods included from Mixin::ShellOut

#run_command_compatible_options, #shell_out, #shell_out!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!

Methods included from Mixin::PowershellOut

#powershell_out, #powershell_out!

Methods included from Mixin::WindowsArchitectureHelper

#assert_valid_windows_architecture!, #disable_wow64_file_redirection, #forced_32bit_override_required?, #is_i386_process_on_x86_64_windows?, #node_supports_windows_architecture?, #node_windows_architecture, #restore_wow64_file_redirection, #valid_windows_architecture?, #with_os_architecture, #wow64_architecture_override_required?, #wow64_directory

Methods included from DSL::PlatformIntrospection

#docker?, #platform?, #platform_family?, #value_for_platform, #value_for_platform_family

Methods included from DSL::RebootPending

#reboot_pending?

Methods included from DSL::RegistryHelper

#registry_data_exists?, #registry_get_subkeys, #registry_get_values, #registry_has_subkeys?, #registry_key_exists?, #registry_value_exists?

Methods included from DSL::DataQuery

#data_bag, #data_bag_item, #search

Methods included from EncryptedDataBagItem::CheckEncrypted

#encrypted?

Constructor Details

#initialize(name, run_context = nil) ⇒ Deploy

Returns a new instance of Deploy.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/chef/resource/deploy.rb', line 62

def initialize(name, run_context = nil)
  super
  @deploy_to = name
  @environment = nil
  @repository_cache = "cached-copy"
  @copy_exclude = []
  @purge_before_symlink = %w{log tmp/pids public/system}
  @create_dirs_before_symlink = %w{tmp public config}
  @symlink_before_migrate = { "config/database.yml" => "config/database.yml" }
  @symlinks = { "system" => "public/system", "pids" => "tmp/pids", "log" => "log" }
  @revision = "HEAD"
  @migrate = false
  @rollback_on_error = false
  @remote = "origin"
  @enable_submodules = false
  @shallow_clone = false
  @depth = nil
  @scm_provider = Chef::Provider::Git
  @svn_force_export = false
  @additional_remotes = Hash[]
  @keep_releases = 5
  @enable_checkout = true
  @checkout_branch = "deploy"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::Resource

Class Method Details

.provider_baseObject

This is to support “provider :revision” without deprecation warnings. Do NOT copy this.



290
291
292
# File 'lib/chef/resource/deploy.rb', line 290

def self.provider_base
  Chef::Provider::Deploy
end

Instance Method Details

#additional_remotes(arg = nil) ⇒ Object



404
405
406
407
408
409
410
# File 'lib/chef/resource/deploy.rb', line 404

def additional_remotes(arg = nil)
  set_or_return(
    :additional_remotes,
    arg,
    :kind_of => Hash
  )
end

#after_restart(arg = nil, &block) ⇒ Object

Callback fires after restart



399
400
401
402
# File 'lib/chef/resource/deploy.rb', line 399

def after_restart(arg = nil, &block)
  arg ||= block
  set_or_return(:after_restart, arg, :kind_of => [Proc, String])
end

#before_migrate(arg = nil, &block) ⇒ Object

Callback fires before migration is run.



381
382
383
384
# File 'lib/chef/resource/deploy.rb', line 381

def before_migrate(arg = nil, &block)
  arg ||= block
  set_or_return(:before_migrate, arg, :kind_of => [Proc, String])
end

#before_restart(arg = nil, &block) ⇒ Object

Callback fires before restart



393
394
395
396
# File 'lib/chef/resource/deploy.rb', line 393

def before_restart(arg = nil, &block)
  arg ||= block
  set_or_return(:before_restart, arg, :kind_of => [Proc, String])
end

Callback fires before symlinking



387
388
389
390
# File 'lib/chef/resource/deploy.rb', line 387

def before_symlink(arg = nil, &block)
  arg ||= block
  set_or_return(:before_symlink, arg, :kind_of => [Proc, String])
end

#checkout_branch(arg = nil) ⇒ Object



420
421
422
423
424
425
426
# File 'lib/chef/resource/deploy.rb', line 420

def checkout_branch(arg = nil)
  set_or_return(
    :checkout_branch,
    arg,
    :kind_of => String
  )
end

#copy_exclude(arg = nil) ⇒ Object



218
219
220
221
222
223
224
# File 'lib/chef/resource/deploy.rb', line 218

def copy_exclude(arg = nil)
  set_or_return(
    :copy_exclude,
    arg,
    :kind_of => [ String ]
  )
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 can use this to recreate dirs that you had previously purged. For example, if you plan to use a shared directory for pids, and you want it to be located in $APP_ROOT/tmp/pids, you could purge tmp, 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”]



343
344
345
346
347
348
349
# File 'lib/chef/resource/deploy.rb', line 343

def create_dirs_before_symlink(arg = nil)
  set_or_return(
    :create_dirs_before_symlink,
    arg,
    :kind_of => Array
  )
end

#current_pathObject

where the deployed version of your code goes



98
99
100
# File 'lib/chef/resource/deploy.rb', line 98

def current_path
  @current_path ||= @deploy_to + "/current"
end

#deploy_to(arg = nil) ⇒ Object

note: deploy_to is your application “meta-root.”



111
112
113
114
115
116
117
# File 'lib/chef/resource/deploy.rb', line 111

def deploy_to(arg = nil)
  set_or_return(
    :deploy_to,
    arg,
    :kind_of => [ String ]
  )
end

#depth(arg = @shallow_clone ? 5 : nil) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/chef/resource/deploy.rb', line 102

def depth(arg = @shallow_clone ? 5 : nil)
  set_or_return(
    :depth,
    arg,
    :kind_of => [ Integer ]
  )
end

#destinationObject

where the checked out/cloned code goes



88
89
90
# File 'lib/chef/resource/deploy.rb', line 88

def destination
  @destination ||= shared_path + "/#{@repository_cache}"
end

#enable_checkout(arg = nil) ⇒ Object



412
413
414
415
416
417
418
# File 'lib/chef/resource/deploy.rb', line 412

def enable_checkout(arg = nil)
  set_or_return(
    :enable_checkout,
    arg,
    :kind_of => [TrueClass, FalseClass]
  )
end

#enable_submodules(arg = nil) ⇒ Object



194
195
196
197
198
199
200
# File 'lib/chef/resource/deploy.rb', line 194

def enable_submodules(arg = nil)
  set_or_return(
    :enable_submodules,
    arg,
    :kind_of => [ TrueClass, FalseClass ]
  )
end

#environment(arg = nil) ⇒ Object



302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/chef/resource/deploy.rb', line 302

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
  set_or_return(
    :environment,
    arg,
    :kind_of => [ Hash ]
  )
end

#git_ssh_wrapper(arg = nil) ⇒ Object Also known as: ssh_wrapper



235
236
237
238
239
240
241
# File 'lib/chef/resource/deploy.rb', line 235

def git_ssh_wrapper(arg = nil)
  set_or_return(
    :git_ssh_wrapper,
    arg,
    :kind_of => [ String ]
  )
end

#group(arg = nil) ⇒ Object



186
187
188
189
190
191
192
# File 'lib/chef/resource/deploy.rb', line 186

def group(arg = nil)
  set_or_return(
    :group,
    arg,
    :kind_of => [ String ]
  )
end

#keep_releases(arg = nil) ⇒ Object

The number of old release directories to keep around after cleanup



316
317
318
319
320
321
# File 'lib/chef/resource/deploy.rb', line 316

def keep_releases(arg = nil)
  [set_or_return(
    :keep_releases,
    arg,
    :kind_of => [ Integer ]), 1].max
end

#migrate(arg = nil) ⇒ Object



154
155
156
157
158
159
160
# File 'lib/chef/resource/deploy.rb', line 154

def migrate(arg = nil)
  set_or_return(
    :migrate,
    arg,
    :kind_of => [ TrueClass, FalseClass ]
  )
end

#migration_command(arg = nil) ⇒ Object



162
163
164
165
166
167
168
# File 'lib/chef/resource/deploy.rb', line 162

def migration_command(arg = nil)
  set_or_return(
    :migration_command,
    arg,
    :kind_of => [ String ]
  )
end

An array of paths, relative to your app’s root, to be purged from a 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”]



327
328
329
330
331
332
333
# File 'lib/chef/resource/deploy.rb', line 327

def purge_before_symlink(arg = nil)
  set_or_return(
    :purge_before_symlink,
    arg,
    :kind_of => Array
  )
end

#remote(arg = nil) ⇒ Object



128
129
130
131
132
133
134
# File 'lib/chef/resource/deploy.rb', line 128

def remote(arg = nil)
  set_or_return(
    :remote,
    arg,
    :kind_of => [ String ]
  )
end

#repo(arg = nil) ⇒ Object Also known as: repository



119
120
121
122
123
124
125
# File 'lib/chef/resource/deploy.rb', line 119

def repo(arg = nil)
  set_or_return(
    :repo,
    arg,
    :kind_of => [ String ]
  )
end

#repository_cache(arg = nil) ⇒ Object



210
211
212
213
214
215
216
# File 'lib/chef/resource/deploy.rb', line 210

def repository_cache(arg = nil)
  set_or_return(
    :repository_cache,
    arg,
    :kind_of => [ String ]
  )
end

#restart_command(arg = nil, &block) ⇒ Object Also known as: restart



144
145
146
147
148
149
150
151
# File 'lib/chef/resource/deploy.rb', line 144

def restart_command(arg = nil, &block)
  arg ||= block
  set_or_return(
    :restart_command,
    arg,
    :kind_of => [ String, Proc ]
  )
end

#revision(arg = nil) ⇒ Object Also known as: branch



226
227
228
229
230
231
232
# File 'lib/chef/resource/deploy.rb', line 226

def revision(arg = nil)
  set_or_return(
    :revision,
    arg,
    :kind_of => [ String ]
  )
end

#role(arg = nil) ⇒ Object



136
137
138
139
140
141
142
# File 'lib/chef/resource/deploy.rb', line 136

def role(arg = nil)
  set_or_return(
    :role,
    arg,
    :kind_of => [ String ]
  )
end

#rollback_on_error(arg = nil) ⇒ Object



170
171
172
173
174
175
176
# File 'lib/chef/resource/deploy.rb', line 170

def rollback_on_error(arg = nil)
  set_or_return(
    :rollback_on_error,
    arg,
    :kind_of => [ TrueClass, FalseClass ]
  )
end

#scm_provider(arg = nil) ⇒ Object



275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/chef/resource/deploy.rb', line 275

def scm_provider(arg = nil)
  klass = if arg.kind_of?(String) || arg.kind_of?(Symbol)
            lookup_provider_constant(arg)
          else
            arg
          end
  set_or_return(
    :scm_provider,
    klass,
    :kind_of => [ Class ]
  )
end

#shallow_clone(arg = nil) ⇒ Object



202
203
204
205
206
207
208
# File 'lib/chef/resource/deploy.rb', line 202

def shallow_clone(arg = nil)
  set_or_return(
    :shallow_clone,
    arg,
    :kind_of => [ TrueClass, FalseClass ]
  )
end

#shared_pathObject

where shared stuff goes, i.e., logs, tmp, etc. goes here



93
94
95
# File 'lib/chef/resource/deploy.rb', line 93

def shared_path
  @shared_path ||= @deploy_to + "/shared"
end

#svn_arguments(arg = nil) ⇒ Object



260
261
262
263
264
265
266
# File 'lib/chef/resource/deploy.rb', line 260

def svn_arguments(arg = nil)
  set_or_return(
    :svn_arguments,
    arg,
    :kind_of => [ String ]
  )
end

#svn_force_export(arg = nil) ⇒ Object



294
295
296
297
298
299
300
# File 'lib/chef/resource/deploy.rb', line 294

def svn_force_export(arg = nil)
  set_or_return(
    :svn_force_export,
    arg,
    :kind_of => [ TrueClass, FalseClass ]
  )
end

#svn_info_args(arg = nil) ⇒ Object



268
269
270
271
272
273
# File 'lib/chef/resource/deploy.rb', line 268

def svn_info_args(arg = nil)
  set_or_return(
    :svn_arguments,
    arg,
    :kind_of => [ String ])
end

#svn_password(arg = nil) ⇒ Object



252
253
254
255
256
257
258
# File 'lib/chef/resource/deploy.rb', line 252

def svn_password(arg = nil)
  set_or_return(
    :svn_password,
    arg,
    :kind_of => [ String ]
  )
end

#svn_username(arg = nil) ⇒ Object



244
245
246
247
248
249
250
# File 'lib/chef/resource/deploy.rb', line 244

def svn_username(arg = nil)
  set_or_return(
    :svn_username,
    arg,
    :kind_of => [ String ]
  )
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 directory and where they go. Unlike map_shared_files, these are symlinked before any migration is run. 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”



372
373
374
375
376
377
378
# File 'lib/chef/resource/deploy.rb', line 372

def symlink_before_migrate(arg = nil)
  set_or_return(
    :symlink_before_migrate,
    arg,
    :kind_of => Hash
  )
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 release directory, and where they go. If you have a directory $shared/pids that you would like to symlink as $current_release/tmp/pids you specify it as “pids” => “tmp/pids” Default => “public/system”, “pids” => “tmp/pids”, “log” => “log”



357
358
359
360
361
362
363
# File 'lib/chef/resource/deploy.rb', line 357

def symlinks(arg = nil)
  set_or_return(
    :symlinks,
    arg,
    :kind_of => Hash
  )
end

#timeout(arg = nil) ⇒ Object

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.



433
434
435
436
437
438
439
# File 'lib/chef/resource/deploy.rb', line 433

def timeout(arg = nil)
  set_or_return(
    :timeout,
    arg,
    :kind_of => Integer
  )
end

#user(arg = nil) ⇒ Object



178
179
180
181
182
183
184
# File 'lib/chef/resource/deploy.rb', line 178

def user(arg = nil)
  set_or_return(
    :user,
    arg,
    :kind_of => [ String ]
  )
end