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

Instance Attribute Summary

Attributes inherited from Chef::Resource

#actions, #allowed_actions, #collection, #cookbook_name, #enclosing_provider, #node, #params, #provider, #recipe_name, #resource_name, #source_line, #updated

Instance Method Summary collapse

Methods inherited from Chef::Resource

#action, attribute, build_from_file, #epic_fail, #ignore_failure, #is, json_create, #load_prior_resource, #method_missing, #name, #noop, #not_if, #notifies, #only_if, provider_base, #resources, #run_action, #subscribes, #supports, #to_hash, #to_json, #to_s

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #filename_to_qualified_string

Methods included from Mixin::Language

#platform?, #value_for_platform

Methods included from Mixin::ParamsValidate

#set_or_return, #validate

Methods included from Mixin::CheckHelper

#set_if_args

Constructor Details

#initialize(name, collection = nil, node = nil) ⇒ Deploy

Returns a new instance of Deploy.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/chef/resource/deploy.rb', line 55

def initialize(name, collection=nil, node=nil)
  super(name, collection, node)
  @resource_name = :deploy
  @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'
  @action = :deploy
  @migrate = false
  @remote = "origin"
  @enable_submodules = false
  @shallow_clone = false
  @scm_provider = Chef::Provider::Git
  @provider = Chef::Provider::Deploy::Timestamped
  @allowed_actions.push(:force_deploy, :deploy, :rollback)
end

Dynamic Method Handling

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

Instance Method Details

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

Callback fires after restart



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

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.



325
326
327
328
# File 'lib/chef/resource/deploy.rb', line 325

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



337
338
339
340
# File 'lib/chef/resource/deploy.rb', line 337

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

Callback fires before symlinking



331
332
333
334
# File 'lib/chef/resource/deploy.rb', line 331

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

#copy_exclude(arg = nil) ⇒ Object



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

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”]



287
288
289
290
291
292
293
# File 'lib/chef/resource/deploy.rb', line 287

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



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

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

#deploy_to(arg = nil) ⇒ Object

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



97
98
99
100
101
102
103
# File 'lib/chef/resource/deploy.rb', line 97

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

#depthObject



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

def depth
  @shallow_clone ? "5" : nil
end

#destinationObject

where the checked out/cloned code goes



78
79
80
# File 'lib/chef/resource/deploy.rb', line 78

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

#enable_submodules(arg = nil) ⇒ Object



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

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

#environment(arg = nil) ⇒ Object



254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/chef/resource/deploy.rb', line 254

def environment(arg=nil)
  if arg.is_a?(String)
    Chef::Log.info "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



213
214
215
216
217
218
219
# File 'lib/chef/resource/deploy.rb', line 213

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

#group(arg = nil) ⇒ Object



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

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

#migrate(arg = nil) ⇒ Object



140
141
142
143
144
145
146
# File 'lib/chef/resource/deploy.rb', line 140

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

#migration_command(arg = nil) ⇒ Object



148
149
150
151
152
153
154
# File 'lib/chef/resource/deploy.rb', line 148

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”]



271
272
273
274
275
276
277
# File 'lib/chef/resource/deploy.rb', line 271

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

#remote(arg = nil) ⇒ Object



114
115
116
117
118
119
120
# File 'lib/chef/resource/deploy.rb', line 114

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

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



105
106
107
108
109
110
111
# File 'lib/chef/resource/deploy.rb', line 105

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

#repository_cache(arg = nil) ⇒ Object



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

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



130
131
132
133
134
135
136
137
# File 'lib/chef/resource/deploy.rb', line 130

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



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

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

#role(arg = nil) ⇒ Object



122
123
124
125
126
127
128
# File 'lib/chef/resource/deploy.rb', line 122

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

#scm_provider(arg = nil) ⇒ Object



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

def scm_provider(arg=nil)
  set_or_return(
    :scm_provider,
    arg,
    :kind_of => [ Class ]
  )
end

#shallow_clone(arg = nil) ⇒ Object



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

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



83
84
85
# File 'lib/chef/resource/deploy.rb', line 83

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

#svn_arguments(arg = nil) ⇒ Object



238
239
240
241
242
243
244
# File 'lib/chef/resource/deploy.rb', line 238

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

#svn_password(arg = nil) ⇒ Object



230
231
232
233
234
235
236
# File 'lib/chef/resource/deploy.rb', line 230

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

#svn_username(arg = nil) ⇒ Object



222
223
224
225
226
227
228
# File 'lib/chef/resource/deploy.rb', line 222

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”



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

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”



301
302
303
304
305
306
307
# File 'lib/chef/resource/deploy.rb', line 301

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

#user(arg = nil) ⇒ Object



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

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