runa-chef 0.8.0.1
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.
- data/LICENSE +201 -0
- data/README.rdoc +136 -0
- data/bin/chef-client +26 -0
- data/bin/chef-solo +26 -0
- data/bin/knife +27 -0
- data/bin/shef +45 -0
- data/distro/README +2 -0
- data/distro/common/man/man1/chef-indexer.1 +42 -0
- data/distro/common/man/man1/chef-server.1 +108 -0
- data/distro/common/man/man8/chef-client.8 +61 -0
- data/distro/common/man/man8/chef-solo.8 +58 -0
- data/distro/common/man/man8/knife.8 +359 -0
- data/distro/debian/etc/init.d/chef-client +175 -0
- data/distro/debian/etc/init.d/chef-indexer +175 -0
- data/distro/debian/etc/init.d/chef-server +120 -0
- data/distro/redhat/etc/init.d/chef-client +78 -0
- data/distro/redhat/etc/init.d/chef-indexer +76 -0
- data/distro/redhat/etc/init.d/chef-server +78 -0
- data/distro/redhat/etc/sysconfig/chef-client +10 -0
- data/distro/redhat/etc/sysconfig/chef-indexer +8 -0
- data/distro/redhat/etc/sysconfig/chef-server +10 -0
- data/distro/suse/etc/init.d/chef-client +121 -0
- data/lib/chef.rb +49 -0
- data/lib/chef/api_client.rb +269 -0
- data/lib/chef/application.rb +98 -0
- data/lib/chef/application/agent.rb +18 -0
- data/lib/chef/application/client.rb +214 -0
- data/lib/chef/application/knife.rb +138 -0
- data/lib/chef/application/server.rb +19 -0
- data/lib/chef/application/solo.rb +214 -0
- data/lib/chef/cache.rb +61 -0
- data/lib/chef/cache/checksum.rb +70 -0
- data/lib/chef/certificate.rb +154 -0
- data/lib/chef/client.rb +323 -0
- data/lib/chef/compile.rb +158 -0
- data/lib/chef/config.rb +195 -0
- data/lib/chef/cookbook.rb +198 -0
- data/lib/chef/cookbook/metadata.rb +487 -0
- data/lib/chef/cookbook/metadata/version.rb +87 -0
- data/lib/chef/cookbook_loader.rb +180 -0
- data/lib/chef/couchdb.rb +273 -0
- data/lib/chef/daemon.rb +170 -0
- data/lib/chef/data_bag.rb +216 -0
- data/lib/chef/data_bag_item.rb +227 -0
- data/lib/chef/exceptions.rb +39 -0
- data/lib/chef/file_cache.rb +205 -0
- data/lib/chef/knife.rb +300 -0
- data/lib/chef/knife/client_bulk_delete.rb +41 -0
- data/lib/chef/knife/client_create.rb +55 -0
- data/lib/chef/knife/client_delete.rb +37 -0
- data/lib/chef/knife/client_edit.rb +37 -0
- data/lib/chef/knife/client_list.rb +40 -0
- data/lib/chef/knife/client_reregister.rb +48 -0
- data/lib/chef/knife/client_show.rb +42 -0
- data/lib/chef/knife/configure.rb +84 -0
- data/lib/chef/knife/cookbook_bulk_delete.rb +47 -0
- data/lib/chef/knife/cookbook_delete.rb +41 -0
- data/lib/chef/knife/cookbook_download.rb +57 -0
- data/lib/chef/knife/cookbook_list.rb +41 -0
- data/lib/chef/knife/cookbook_metadata.rb +87 -0
- data/lib/chef/knife/cookbook_show.rb +75 -0
- data/lib/chef/knife/cookbook_upload.rb +173 -0
- data/lib/chef/knife/data_bag_create.rb +43 -0
- data/lib/chef/knife/data_bag_delete.rb +43 -0
- data/lib/chef/knife/data_bag_edit.rb +49 -0
- data/lib/chef/knife/data_bag_list.rb +42 -0
- data/lib/chef/knife/data_bag_show.rb +40 -0
- data/lib/chef/knife/ec2_instance_data.rb +46 -0
- data/lib/chef/knife/node_bulk_delete.rb +44 -0
- data/lib/chef/knife/node_create.rb +39 -0
- data/lib/chef/knife/node_delete.rb +36 -0
- data/lib/chef/knife/node_edit.rb +36 -0
- data/lib/chef/knife/node_from_file.rb +42 -0
- data/lib/chef/knife/node_list.rb +41 -0
- data/lib/chef/knife/node_run_list_add.rb +64 -0
- data/lib/chef/knife/node_run_list_remove.rb +45 -0
- data/lib/chef/knife/node_show.rb +46 -0
- data/lib/chef/knife/role_bulk_delete.rb +45 -0
- data/lib/chef/knife/role_create.rb +44 -0
- data/lib/chef/knife/role_delete.rb +36 -0
- data/lib/chef/knife/role_edit.rb +37 -0
- data/lib/chef/knife/role_from_file.rb +46 -0
- data/lib/chef/knife/role_list.rb +40 -0
- data/lib/chef/knife/role_show.rb +43 -0
- data/lib/chef/knife/search.rb +94 -0
- data/lib/chef/log.rb +39 -0
- data/lib/chef/mixin/check_helper.rb +31 -0
- data/lib/chef/mixin/checksum.rb +32 -0
- data/lib/chef/mixin/command.rb +390 -0
- data/lib/chef/mixin/convert_to_class_name.rb +57 -0
- data/lib/chef/mixin/create_path.rb +56 -0
- data/lib/chef/mixin/deep_merge.rb +33 -0
- data/lib/chef/mixin/find_preferred_file.rb +92 -0
- data/lib/chef/mixin/from_file.rb +50 -0
- data/lib/chef/mixin/generate_url.rb +58 -0
- data/lib/chef/mixin/language.rb +107 -0
- data/lib/chef/mixin/language_include_attribute.rb +56 -0
- data/lib/chef/mixin/language_include_recipe.rb +53 -0
- data/lib/chef/mixin/params_validate.rb +197 -0
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +79 -0
- data/lib/chef/mixin/template.rb +94 -0
- data/lib/chef/nanite.rb +100 -0
- data/lib/chef/node.rb +463 -0
- data/lib/chef/node/attribute.rb +412 -0
- data/lib/chef/openid_registration.rb +181 -0
- data/lib/chef/platform.rb +268 -0
- data/lib/chef/provider.rb +101 -0
- data/lib/chef/provider/breakpoint.rb +36 -0
- data/lib/chef/provider/cron.rb +184 -0
- data/lib/chef/provider/deploy.rb +314 -0
- data/lib/chef/provider/deploy/revision.rb +70 -0
- data/lib/chef/provider/deploy/timestamped.rb +33 -0
- data/lib/chef/provider/directory.rb +72 -0
- data/lib/chef/provider/erl_call.rb +72 -0
- data/lib/chef/provider/execute.rb +58 -0
- data/lib/chef/provider/file.rb +195 -0
- data/lib/chef/provider/git.rb +203 -0
- data/lib/chef/provider/group.rb +120 -0
- data/lib/chef/provider/group/dscl.rb +128 -0
- data/lib/chef/provider/group/gpasswd.rb +50 -0
- data/lib/chef/provider/group/groupadd.rb +78 -0
- data/lib/chef/provider/group/pw.rb +88 -0
- data/lib/chef/provider/group/usermod.rb +57 -0
- data/lib/chef/provider/http_request.rb +106 -0
- data/lib/chef/provider/ifconfig.rb +131 -0
- data/lib/chef/provider/link.rb +157 -0
- data/lib/chef/provider/mdadm.rb +88 -0
- data/lib/chef/provider/mount.rb +117 -0
- data/lib/chef/provider/mount/mount.rb +208 -0
- data/lib/chef/provider/package.rb +160 -0
- data/lib/chef/provider/package/apt.rb +110 -0
- data/lib/chef/provider/package/dpkg.rb +109 -0
- data/lib/chef/provider/package/easy_install.rb +106 -0
- data/lib/chef/provider/package/freebsd.rb +153 -0
- data/lib/chef/provider/package/macports.rb +105 -0
- data/lib/chef/provider/package/portage.rb +124 -0
- data/lib/chef/provider/package/rpm.rb +99 -0
- data/lib/chef/provider/package/rubygems.rb +136 -0
- data/lib/chef/provider/package/yum-dump.py +125 -0
- data/lib/chef/provider/package/yum.rb +175 -0
- data/lib/chef/provider/package/zypper.rb +132 -0
- data/lib/chef/provider/remote_directory.rb +126 -0
- data/lib/chef/provider/remote_file.rb +141 -0
- data/lib/chef/provider/route.rb +118 -0
- data/lib/chef/provider/ruby_block.rb +33 -0
- data/lib/chef/provider/script.rb +42 -0
- data/lib/chef/provider/service.rb +135 -0
- data/lib/chef/provider/service/debian.rb +64 -0
- data/lib/chef/provider/service/freebsd.rb +156 -0
- data/lib/chef/provider/service/gentoo.rb +54 -0
- data/lib/chef/provider/service/init.rb +71 -0
- data/lib/chef/provider/service/redhat.rb +62 -0
- data/lib/chef/provider/service/simple.rb +114 -0
- data/lib/chef/provider/subversion.rb +156 -0
- data/lib/chef/provider/template.rb +175 -0
- data/lib/chef/provider/user.rb +170 -0
- data/lib/chef/provider/user/dscl.rb +280 -0
- data/lib/chef/provider/user/pw.rb +113 -0
- data/lib/chef/provider/user/useradd.rb +108 -0
- data/lib/chef/recipe.rb +105 -0
- data/lib/chef/resource.rb +380 -0
- data/lib/chef/resource/apt_package.rb +34 -0
- data/lib/chef/resource/bash.rb +33 -0
- data/lib/chef/resource/breakpoint.rb +35 -0
- data/lib/chef/resource/cron.rb +179 -0
- data/lib/chef/resource/csh.rb +33 -0
- data/lib/chef/resource/deploy.rb +359 -0
- data/lib/chef/resource/deploy_revision.rb +35 -0
- data/lib/chef/resource/directory.rb +76 -0
- data/lib/chef/resource/dpkg_package.rb +34 -0
- data/lib/chef/resource/easy_install_package.rb +41 -0
- data/lib/chef/resource/erl_call.rb +83 -0
- data/lib/chef/resource/execute.rb +127 -0
- data/lib/chef/resource/file.rb +84 -0
- data/lib/chef/resource/gem_package.rb +41 -0
- data/lib/chef/resource/git.rb +36 -0
- data/lib/chef/resource/group.rb +70 -0
- data/lib/chef/resource/http_request.rb +52 -0
- data/lib/chef/resource/ifconfig.rb +134 -0
- data/lib/chef/resource/link.rb +78 -0
- data/lib/chef/resource/macports_package.rb +29 -0
- data/lib/chef/resource/mdadm.rb +82 -0
- data/lib/chef/resource/mount.rb +135 -0
- data/lib/chef/resource/package.rb +80 -0
- data/lib/chef/resource/perl.rb +33 -0
- data/lib/chef/resource/portage_package.rb +33 -0
- data/lib/chef/resource/python.rb +33 -0
- data/lib/chef/resource/remote_directory.rb +91 -0
- data/lib/chef/resource/remote_file.rb +60 -0
- data/lib/chef/resource/route.rb +135 -0
- data/lib/chef/resource/ruby.rb +33 -0
- data/lib/chef/resource/ruby_block.rb +39 -0
- data/lib/chef/resource/scm.rb +137 -0
- data/lib/chef/resource/script.rb +51 -0
- data/lib/chef/resource/service.rb +134 -0
- data/lib/chef/resource/subversion.rb +34 -0
- data/lib/chef/resource/template.rb +60 -0
- data/lib/chef/resource/timestamped_deploy.rb +31 -0
- data/lib/chef/resource/user.rb +101 -0
- data/lib/chef/resource_collection.rb +212 -0
- data/lib/chef/resource_collection/stepable_iterator.rb +124 -0
- data/lib/chef/resource_definition.rb +67 -0
- data/lib/chef/rest.rb +298 -0
- data/lib/chef/role.rb +301 -0
- data/lib/chef/run_list.rb +164 -0
- data/lib/chef/runner.rb +130 -0
- data/lib/chef/search/query.rb +71 -0
- data/lib/chef/shef.rb +220 -0
- data/lib/chef/shef/ext.rb +297 -0
- data/lib/chef/shef/shef_session.rb +175 -0
- data/lib/chef/streaming_cookbook_uploader.rb +185 -0
- data/lib/chef/tasks/chef_repo.rake +245 -0
- data/lib/chef/util/file_edit.rb +125 -0
- data/lib/chef/util/fileedit.rb +121 -0
- data/lib/chef/webui_user.rb +231 -0
- metadata +398 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Daniel DeLeo (<dan@kallistec.com>)
|
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
|
4
|
+
# License:: Apache License, Version 2.0
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
require "chef/mixin/command"
|
|
20
|
+
require "chef/mixin/from_file"
|
|
21
|
+
require "chef/provider/git"
|
|
22
|
+
require "chef/provider/subversion"
|
|
23
|
+
|
|
24
|
+
class Chef
|
|
25
|
+
class Provider
|
|
26
|
+
class Deploy < Chef::Provider
|
|
27
|
+
|
|
28
|
+
include Chef::Mixin::FromFile
|
|
29
|
+
include Chef::Mixin::Command
|
|
30
|
+
|
|
31
|
+
attr_reader :scm_provider, :release_path
|
|
32
|
+
|
|
33
|
+
def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
|
|
34
|
+
super(node, new_resource, collection, definitions, cookbook_loader)
|
|
35
|
+
|
|
36
|
+
# NOTE: workaround for CHEF-577
|
|
37
|
+
@definitions ||= Hash.new
|
|
38
|
+
@collection = Chef::ResourceCollection.new
|
|
39
|
+
|
|
40
|
+
@scm_provider = @new_resource.scm_provider.new(@node, @new_resource)
|
|
41
|
+
|
|
42
|
+
# @configuration is not used by Deploy, it is only for backwards compat with
|
|
43
|
+
# chef-deploy or capistrano hooks that might use it to get environment information
|
|
44
|
+
@configuration = @new_resource.to_hash
|
|
45
|
+
@configuration[:environment] = @configuration[:environment] && @configuration[:environment]["RAILS_ENV"]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def load_current_resource
|
|
49
|
+
@release_path = @new_resource.deploy_to + "/releases/#{release_slug}"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def sudo(command,&block)
|
|
53
|
+
execute(command, &block)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def run(command, &block)
|
|
57
|
+
exec = execute(command, &block)
|
|
58
|
+
exec.user(@new_resource.user)
|
|
59
|
+
exec
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def action_deploy
|
|
63
|
+
if all_releases.include?(release_path)
|
|
64
|
+
if all_releases[-1] == release_path
|
|
65
|
+
Chef::Log.debug("Already deployed app at #{release_path}, and it is the latest revision. Use action :force_deploy to re-deploy this revision.")
|
|
66
|
+
else
|
|
67
|
+
Chef::Log.info("Already deployed app at #{release_path}. Rolling back to it - use action :force_deploy to re-checkout this revision.")
|
|
68
|
+
action_rollback
|
|
69
|
+
end
|
|
70
|
+
else
|
|
71
|
+
deploy
|
|
72
|
+
@new_resource.updated = true
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def action_force_deploy
|
|
77
|
+
if all_releases.include?(release_path)
|
|
78
|
+
Chef::Log.info("Already deployed app at #{release_path}, forcing.")
|
|
79
|
+
FileUtils.rm_rf(release_path)
|
|
80
|
+
end
|
|
81
|
+
deploy
|
|
82
|
+
@new_resource.updated = true
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def action_rollback
|
|
86
|
+
if release_path
|
|
87
|
+
rp_index = all_releases.index(release_path)
|
|
88
|
+
raise RuntimeError, "There is no release to rollback to!" unless rp_index
|
|
89
|
+
rp_index += 1
|
|
90
|
+
releases_to_nuke = all_releases[rp_index..-1]
|
|
91
|
+
else
|
|
92
|
+
@release_path = all_releases[-2]
|
|
93
|
+
raise RuntimeError, "There is no release to rollback to!" unless @release_path
|
|
94
|
+
releases_to_nuke = [ all_releases.last ]
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
Chef::Log.info "rolling back to previous release: #{release_path}"
|
|
98
|
+
symlink
|
|
99
|
+
Chef::Log.info "restarting with previous release"
|
|
100
|
+
restart
|
|
101
|
+
releases_to_nuke.each do |i|
|
|
102
|
+
Chef::Log.info "Removing release: #{i}"
|
|
103
|
+
FileUtils.rm_rf i
|
|
104
|
+
release_deleted(i)
|
|
105
|
+
end
|
|
106
|
+
@new_resource.updated = true
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def deploy
|
|
110
|
+
Chef::Log.info "deploying branch: #{@new_resource.branch}"
|
|
111
|
+
enforce_ownership
|
|
112
|
+
update_cached_repo
|
|
113
|
+
copy_cached_repo
|
|
114
|
+
install_gems
|
|
115
|
+
enforce_ownership
|
|
116
|
+
callback(:before_migrate, @new_resource.before_migrate)
|
|
117
|
+
migrate
|
|
118
|
+
callback(:before_symlink, @new_resource.before_symlink)
|
|
119
|
+
symlink
|
|
120
|
+
callback(:before_restart, @new_resource.before_restart)
|
|
121
|
+
restart
|
|
122
|
+
callback(:after_restart, @new_resource.after_restart)
|
|
123
|
+
cleanup!
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def callback(what, callback_code=nil)
|
|
127
|
+
@collection = Chef::ResourceCollection.new
|
|
128
|
+
case callback_code
|
|
129
|
+
when Proc
|
|
130
|
+
Chef::Log.info "Running callback #{what} code block"
|
|
131
|
+
recipe_eval(&callback_code)
|
|
132
|
+
when String
|
|
133
|
+
callback_file = "#{release_path}/#{callback_code}"
|
|
134
|
+
unless ::File.exist?(callback_file)
|
|
135
|
+
raise RuntimeError, "Can't find your callback file #{callback_file}"
|
|
136
|
+
end
|
|
137
|
+
run_callback_from_file(callback_file)
|
|
138
|
+
when nil
|
|
139
|
+
run_callback_from_file("#{release_path}/deploy/#{what}.rb")
|
|
140
|
+
else
|
|
141
|
+
raise RuntimeError, "You gave me a callback I don't know what to do with: #{callback_code.inspect}"
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def migrate
|
|
146
|
+
run_symlinks_before_migrate
|
|
147
|
+
|
|
148
|
+
if @new_resource.migrate
|
|
149
|
+
enforce_ownership
|
|
150
|
+
|
|
151
|
+
environment = @new_resource.environment
|
|
152
|
+
env_info = environment && environment.map do |key_and_val|
|
|
153
|
+
"#{key_and_val.first}='#{key_and_val.last}'"
|
|
154
|
+
end.join(" ")
|
|
155
|
+
|
|
156
|
+
Chef::Log.info "Migrating: running #{@new_resource.migration_command} as #{@new_resource.user} " +
|
|
157
|
+
"with environment #{env_info}"
|
|
158
|
+
run_command(run_options(:command => @new_resource.migration_command, :cwd=>release_path))
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def symlink
|
|
163
|
+
Chef::Log.info "Symlinking"
|
|
164
|
+
purge_tempfiles_from_current_release
|
|
165
|
+
link_tempfiles_to_current_release
|
|
166
|
+
link_current_release_to_production
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def restart
|
|
170
|
+
if restart_cmd = @new_resource.restart_command
|
|
171
|
+
if restart_cmd.kind_of?(Proc)
|
|
172
|
+
Chef::Log.info("Restarting app with embedded recipe")
|
|
173
|
+
recipe_eval(&restart_cmd)
|
|
174
|
+
else
|
|
175
|
+
Chef::Log.info("Restarting app with #{@new_resource.restart_command} in #{@new_resource.current_path}")
|
|
176
|
+
run_command(run_options(:command => @new_resource.restart_command, :cwd => @new_resource.current_path))
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def cleanup!
|
|
182
|
+
all_releases[0..-6].each do |old_release|
|
|
183
|
+
Chef::Log.info "Removing old release #{old_release}"
|
|
184
|
+
FileUtils.rm_rf(old_release)
|
|
185
|
+
release_deleted(old_release)
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def all_releases
|
|
190
|
+
Dir.glob(@new_resource.deploy_to + "/releases/*").sort
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def update_cached_repo
|
|
194
|
+
if @new_resource.svn_force_export
|
|
195
|
+
svn_force_export
|
|
196
|
+
else
|
|
197
|
+
run_scm_sync
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def run_scm_sync
|
|
202
|
+
Chef::Log.info "updating the cached checkout"
|
|
203
|
+
@scm_provider.action_sync
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def svn_force_export
|
|
207
|
+
Chef::Log.info "exporting source repository to #{@new_resource.destination}"
|
|
208
|
+
@scm_provider.action_force_export
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def copy_cached_repo
|
|
212
|
+
Chef::Log.info "copying the cached checkout to #{release_path}"
|
|
213
|
+
FileUtils.mkdir_p(@new_resource.deploy_to + "/releases")
|
|
214
|
+
FileUtils.cp_r("#{@new_resource.destination}.", release_path, :preserve => true)
|
|
215
|
+
release_created(release_path)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def enforce_ownership
|
|
219
|
+
Chef::Log.info "ensuring proper ownership"
|
|
220
|
+
FileUtils.chown_R(@new_resource.user, @new_resource.group, @new_resource.deploy_to)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def link_current_release_to_production
|
|
224
|
+
Chef::Log.info "Linking release #{release_path} into production at #{@new_resource.current_path}"
|
|
225
|
+
FileUtils.rm_f(@new_resource.current_path)
|
|
226
|
+
FileUtils.ln_sf(release_path, @new_resource.current_path)
|
|
227
|
+
enforce_ownership
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def run_symlinks_before_migrate
|
|
231
|
+
links_info = @new_resource.symlink_before_migrate.map { |src, dst| "#{src} => #{dst}" }.join(", ")
|
|
232
|
+
Chef::Log.info "Making pre-migration symlinks: #{links_info}"
|
|
233
|
+
@new_resource.symlink_before_migrate.each do |src, dest|
|
|
234
|
+
FileUtils.ln_sf(@new_resource.shared_path + "/#{src}", release_path + "/#{dest}")
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def link_tempfiles_to_current_release
|
|
239
|
+
dirs_info = @new_resource.create_dirs_before_symlink.join(",")
|
|
240
|
+
Chef::Log.info("creating directories before symlink: #{dirs_info}")
|
|
241
|
+
@new_resource.create_dirs_before_symlink.each { |dir| FileUtils.mkdir_p(release_path + "/#{dir}") }
|
|
242
|
+
|
|
243
|
+
links_info = @new_resource.symlinks.map { |src, dst| "#{src} => #{dst}" }.join(", ")
|
|
244
|
+
Chef::Log.info("Linking shared paths into current release: #{links_info}")
|
|
245
|
+
@new_resource.symlinks.each do |src, dest|
|
|
246
|
+
FileUtils.ln_sf(@new_resource.shared_path + "/#{src}", release_path + "/#{dest}")
|
|
247
|
+
end
|
|
248
|
+
run_symlinks_before_migrate
|
|
249
|
+
enforce_ownership
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def create_dirs_before_symlink
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
def purge_tempfiles_from_current_release
|
|
256
|
+
log_info = @new_resource.purge_before_symlink.join(", ")
|
|
257
|
+
Chef::Log.info("Purging directories in checkout #{log_info}")
|
|
258
|
+
@new_resource.purge_before_symlink.each { |dir| FileUtils.rm_rf(release_path + "/#{dir}") }
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
protected
|
|
262
|
+
|
|
263
|
+
# Internal callback, called after copy_cached_repo.
|
|
264
|
+
# Override if you need to keep state externally.
|
|
265
|
+
def release_created(release_path)
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
# Internal callback, called during cleanup! for each old release removed.
|
|
269
|
+
# Override if you need to keep state externally.
|
|
270
|
+
def release_deleted(release_path)
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
def release_slug
|
|
274
|
+
raise Chef::Exceptions::Override, "You must override release_slug in #{self.to_s}"
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def install_gems
|
|
278
|
+
gems_collection = Chef::ResourceCollection.new
|
|
279
|
+
gem_packages.each { |rbgem| gems_collection << rbgem }
|
|
280
|
+
Chef::Runner.new(@node, gems_collection).converge
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
def gem_packages
|
|
284
|
+
return [] unless ::File.exist?("#{release_path}/gems.yml")
|
|
285
|
+
gems = YAML.load(IO.read("#{release_path}/gems.yml"))
|
|
286
|
+
|
|
287
|
+
gems.map do |g|
|
|
288
|
+
r = Chef::Resource::GemPackage.new(g[:name], nil, node)
|
|
289
|
+
r.version g[:version]
|
|
290
|
+
r.action :install
|
|
291
|
+
r.source "http://gems.github.com"
|
|
292
|
+
r
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def run_options(run_opts={})
|
|
297
|
+
run_opts[:user] = @new_resource.user if @new_resource.user
|
|
298
|
+
run_opts[:group] = @new_resource.group if @new_resource.group
|
|
299
|
+
run_opts[:environment] = @new_resource.environment if @new_resource.environment
|
|
300
|
+
run_opts
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
def run_callback_from_file(callback_file)
|
|
304
|
+
if ::File.exist?(callback_file)
|
|
305
|
+
Dir.chdir(release_path) do
|
|
306
|
+
Chef::Log.info "running deploy hook: #{callback_file}"
|
|
307
|
+
recipe_eval { from_file(callback_file) }
|
|
308
|
+
end
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
end
|
|
313
|
+
end
|
|
314
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Daniel DeLeo (<dan@kallistec.com>)
|
|
3
|
+
# Copyright:: Copyright (c) 2009 Daniel DeLeo
|
|
4
|
+
# License:: Apache License, Version 2.0
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
class Chef
|
|
20
|
+
class Provider
|
|
21
|
+
class Deploy
|
|
22
|
+
class Revision < Chef::Provider::Deploy
|
|
23
|
+
|
|
24
|
+
def all_releases
|
|
25
|
+
sorted_releases
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
protected
|
|
29
|
+
|
|
30
|
+
def release_created(release)
|
|
31
|
+
sorted_releases { |r| r << release }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def release_deleted(release)
|
|
35
|
+
sorted_releases { |r| r.delete(release)}
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def release_slug
|
|
39
|
+
scm_provider.revision_slug
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def sorted_releases
|
|
45
|
+
cache = load_cache
|
|
46
|
+
if block_given?
|
|
47
|
+
yield cache
|
|
48
|
+
save_cache(cache)
|
|
49
|
+
end
|
|
50
|
+
cache
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def load_cache
|
|
54
|
+
begin
|
|
55
|
+
JSON.parse(Chef::FileCache.load("revision-deploys/#{new_resource.name}"))
|
|
56
|
+
rescue
|
|
57
|
+
Chef::Exceptions::FileNotFound
|
|
58
|
+
save_cache([])
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def save_cache(cache)
|
|
63
|
+
Chef::FileCache.store("revision-deploys/#{new_resource.name}", cache.to_json)
|
|
64
|
+
cache
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Daniel DeLeo (<dan@kallistec.com>)
|
|
3
|
+
# Copyright:: Copyright (c) 2009 Daniel DeLeo
|
|
4
|
+
# License:: Apache License, Version 2.0
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
class Chef
|
|
20
|
+
class Provider
|
|
21
|
+
class Deploy
|
|
22
|
+
class Timestamped < Chef::Provider::Deploy
|
|
23
|
+
|
|
24
|
+
protected
|
|
25
|
+
|
|
26
|
+
def release_slug
|
|
27
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
|
4
|
+
# License:: Apache License, Version 2.0
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
require 'chef/config'
|
|
20
|
+
require 'chef/log'
|
|
21
|
+
require 'chef/resource/directory'
|
|
22
|
+
require 'chef/provider'
|
|
23
|
+
require 'chef/provider/file'
|
|
24
|
+
require 'fileutils'
|
|
25
|
+
|
|
26
|
+
class Chef
|
|
27
|
+
class Provider
|
|
28
|
+
class Directory < Chef::Provider::File
|
|
29
|
+
def load_current_resource
|
|
30
|
+
@current_resource = Chef::Resource::Directory.new(@new_resource.name)
|
|
31
|
+
@current_resource.path(@new_resource.path)
|
|
32
|
+
if ::File.exist?(@current_resource.path) && ::File.directory?(@current_resource.path)
|
|
33
|
+
cstats = ::File.stat(@current_resource.path)
|
|
34
|
+
@current_resource.owner(cstats.uid)
|
|
35
|
+
@current_resource.group(cstats.gid)
|
|
36
|
+
@current_resource.mode("%o" % (cstats.mode & 007777))
|
|
37
|
+
end
|
|
38
|
+
@current_resource
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def action_create
|
|
42
|
+
unless ::File.exists?(@new_resource.path)
|
|
43
|
+
Chef::Log.info("Creating #{@new_resource} at #{@new_resource.path}")
|
|
44
|
+
if @new_resource.recursive == true
|
|
45
|
+
::FileUtils.mkdir_p(@new_resource.path)
|
|
46
|
+
else
|
|
47
|
+
::Dir.mkdir(@new_resource.path)
|
|
48
|
+
end
|
|
49
|
+
@new_resource.updated = true
|
|
50
|
+
end
|
|
51
|
+
set_owner if @new_resource.owner != nil
|
|
52
|
+
set_group if @new_resource.group != nil
|
|
53
|
+
set_mode if @new_resource.mode != nil
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def action_delete
|
|
57
|
+
if ::File.directory?(@new_resource.path) && ::File.writable?(@new_resource.path)
|
|
58
|
+
if @new_resource.recursive == true
|
|
59
|
+
Chef::Log.info("Deleting #{@new_resource} recursively at #{@new_resource.path}")
|
|
60
|
+
FileUtils.rm_rf(@new_resource.path)
|
|
61
|
+
else
|
|
62
|
+
Chef::Log.info("Deleting #{@new_resource} at #{@new_resource.path}")
|
|
63
|
+
::Dir.delete(@new_resource.path)
|
|
64
|
+
end
|
|
65
|
+
@new_resource.updated = true
|
|
66
|
+
else
|
|
67
|
+
raise RuntimeError, "Cannot delete #{@new_resource} at #{@new_resource_path}!" if ::File.exists?(@new_resource.path)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|