diff options
author | Tim Smith <tsmith@chef.io> | 2018-01-18 16:16:55 -0800 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-01-20 11:12:44 -0800 |
commit | 4db12430ba0c6c021b114c143aaea94f1f754d66 (patch) | |
tree | 56d4ba781ddec52dde6961c1c003405278f60d49 /lib/chef | |
parent | 083ab943462e5b14503a67cfecd6b16e6d6be0ef (diff) | |
download | chef-4db12430ba0c6c021b114c143aaea94f1f754d66.tar.gz |
Remove erl_call and deploy resourcesdeprecated_resources
We deprecated these for removal in Chef 14.
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/provider/deploy.rb | 470 | ||||
-rw-r--r-- | lib/chef/provider/deploy/revision.rb | 107 | ||||
-rw-r--r-- | lib/chef/provider/deploy/timestamped.rb | 34 | ||||
-rw-r--r-- | lib/chef/provider/erl_call.rb | 76 | ||||
-rw-r--r-- | lib/chef/providers.rb | 5 | ||||
-rw-r--r-- | lib/chef/resource/deploy.rb | 449 | ||||
-rw-r--r-- | lib/chef/resource/deploy_revision.rb | 31 | ||||
-rw-r--r-- | lib/chef/resource/erl_call.rb | 90 | ||||
-rw-r--r-- | lib/chef/resource/timestamped_deploy.rb | 26 | ||||
-rw-r--r-- | lib/chef/resources.rb | 4 |
10 files changed, 0 insertions, 1292 deletions
diff --git a/lib/chef/provider/deploy.rb b/lib/chef/provider/deploy.rb deleted file mode 100644 index c4229d2441..0000000000 --- a/lib/chef/provider/deploy.rb +++ /dev/null @@ -1,470 +0,0 @@ -# -# Author:: Daniel DeLeo (<dan@kallistec.com>) -# Copyright:: Copyright 2008-2017, Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef/mixin/from_file" -require "chef/provider/git" -require "chef/provider/subversion" -require "chef/dsl/recipe" -require "chef/util/path_helper" - -class Chef - class Provider - class Deploy < Chef::Provider - - include Chef::DSL::Recipe - include Chef::Mixin::FromFile - - attr_reader :scm_provider, :release_path, :shared_path, :previous_release_path - - def initialize(new_resource, run_context) - super(new_resource, run_context) - - # will resolve to either git or svn based on resource attributes, - # and will create a resource corresponding to that provider - @scm_provider = new_resource.scm_provider.new(new_resource, run_context) - - # @configuration is not used by Deploy, it is only for backwards compat with - # chef-deploy or capistrano hooks that might use it to get environment information - @configuration = new_resource.to_hash - @configuration[:environment] = @configuration[:environment] && @configuration[:environment]["RAILS_ENV"] - end - - def load_current_resource - @scm_provider.load_current_resource - @release_path = new_resource.deploy_to + "/releases/#{release_slug}" - @shared_path = new_resource.shared_path - end - - def sudo(command, &block) - execute(command, &block) - end - - def run(command, &block) - exec = execute(command, &block) - exec.user(new_resource.user) if new_resource.user - exec.group(new_resource.group) if new_resource.group - exec.cwd(release_path) unless exec.cwd - exec.environment(new_resource.environment) unless exec.environment - converge_by("execute #{command}") do - exec - end - end - - def define_resource_requirements - requirements.assert(:rollback) do |a| - a.assertion { all_releases[-2] } - a.failure_message(RuntimeError, "There is no release to rollback to!") - #There is no reason to assume 2 deployments in a single chef run, hence fails in whyrun. - end - - [ new_resource.before_migrate, new_resource.before_symlink, - new_resource.before_restart, new_resource.after_restart ].each do |script| - requirements.assert(:deploy, :force_deploy) do |a| - callback_file = "#{release_path}/#{script}" - a.assertion do - if script && script.class == String - ::File.exist?(callback_file) - else - true - end - end - a.failure_message(RuntimeError, "Can't find your callback file #{callback_file}") - a.whyrun("Would assume callback file #{callback_file} included in release") - end - end - end - - def action_deploy - save_release_state - if deployed?(release_path ) - if current_release?(release_path ) - Chef::Log.debug("#{new_resource} is the latest version") - else - rollback_to release_path - end - else - - with_rollback_on_error do - deploy - end - end - end - - def action_force_deploy - if deployed?(release_path) - converge_by("delete deployed app at #{release_path} prior to force-deploy") do - Chef::Log.info("Already deployed app at #{release_path}, forcing.") - FileUtils.rm_rf(release_path) - Chef::Log.info("#{new_resource} forcing deploy of already deployed app at #{release_path}") - end - end - - # Alternatives: - # * Move release_path directory before deploy and move it back when error occurs - # * Rollback to previous commit - # * Do nothing - because deploy is force, it will be retried in short time - # Because last is simplest, keep it - deploy - end - - def action_rollback - rollback_to all_releases[-2] - end - - def rollback_to(target_release_path) - @release_path = target_release_path - - rp_index = all_releases.index(release_path) - releases_to_nuke = all_releases[(rp_index + 1)..-1] - - rollback - - releases_to_nuke.each do |i| - converge_by("roll back by removing release #{i}") do - Chef::Log.info "#{new_resource} removing release: #{i}" - FileUtils.rm_rf i - end - release_deleted(i) - end - end - - def deploy - verify_directories_exist - update_cached_repo # no converge-by - scm provider will dothis - enforce_ownership - copy_cached_repo - install_gems - enforce_ownership - callback(:before_migrate, new_resource.before_migrate) - migrate - callback(:before_symlink, new_resource.before_symlink) - symlink - callback(:before_restart, new_resource.before_restart) - restart - callback(:after_restart, new_resource.after_restart) - cleanup! - Chef::Log.info "#{new_resource} deployed to #{new_resource.deploy_to}" - end - - def rollback - Chef::Log.info "#{new_resource} rolling back to previous release #{release_path}" - symlink - Chef::Log.info "#{new_resource} restarting with previous release" - restart - end - - def callback(what, callback_code = nil) - @collection = Chef::ResourceCollection.new - case callback_code - when Proc - Chef::Log.info "#{new_resource} running callback #{what}" - recipe_eval(&callback_code) - when String - run_callback_from_file("#{release_path}/#{callback_code}") - when nil - run_callback_from_file("#{release_path}/deploy/#{what}.rb") - end - end - - def migrate - run_symlinks_before_migrate - - if new_resource.migrate - enforce_ownership - - environment = new_resource.environment - env_info = environment && environment.map do |key_and_val| - "#{key_and_val.first}='#{key_and_val.last}'" - end.join(" ") - - converge_by("execute migration command #{new_resource.migration_command}") do - Chef::Log.info "#{new_resource} migrating #{new_resource.user} with environment #{env_info}" - shell_out!(new_resource.migration_command, run_options(:cwd => release_path, :log_level => :info)) - end - end - end - - def symlink - purge_tempfiles_from_current_release - link_tempfiles_to_current_release - link_current_release_to_production - Chef::Log.info "#{new_resource} updated symlinks" - end - - def restart - if restart_cmd = new_resource.restart_command - if restart_cmd.kind_of?(Proc) - Chef::Log.info("#{new_resource} restarting app with embedded recipe") - recipe_eval(&restart_cmd) - else - converge_by("restart app using command #{new_resource.restart_command}") do - Chef::Log.info("#{new_resource} restarting app") - shell_out!(new_resource.restart_command, run_options(:cwd => new_resource.current_path)) - end - end - end - end - - def cleanup! - converge_by("update release history data") do - release_created(release_path) - end - - chop = -1 - new_resource.keep_releases - all_releases[0..chop].each do |old_release| - converge_by("remove old release #{old_release}") do - Chef::Log.info "#{new_resource} removing old release #{old_release}" - FileUtils.rm_rf(old_release) - end - release_deleted(old_release) - end - end - - def all_releases - Dir.glob(Chef::Util::PathHelper.escape_glob_dir(new_resource.deploy_to) + "/releases/*").sort - end - - def update_cached_repo - if new_resource.svn_force_export - # TODO assertion, non-recoverable - @scm_provider must be svn if force_export? - svn_force_export - else - run_scm_sync - end - end - - def run_scm_sync - @scm_provider.run_action(:sync) - end - - def svn_force_export - Chef::Log.info "#{new_resource} exporting source repository" - @scm_provider.run_action(:force_export) - end - - def copy_cached_repo - target_dir_path = new_resource.deploy_to + "/releases" - converge_by("deploy from repo to #{target_dir_path} ") do - FileUtils.rm_rf(release_path) if ::File.exist?(release_path) - FileUtils.mkdir_p(target_dir_path) - FileUtils.cp_r(::File.join(new_resource.destination, "."), release_path, :preserve => true) - Chef::Log.info "#{new_resource} copied the cached checkout to #{release_path}" - end - end - - def enforce_ownership - converge_by("force ownership of #{new_resource.deploy_to} to #{new_resource.group}:#{new_resource.user}") do - FileUtils.chown_R(new_resource.user, new_resource.group, new_resource.deploy_to, :force => true) - Chef::Log.info("#{new_resource} set user to #{new_resource.user}") if new_resource.user - Chef::Log.info("#{new_resource} set group to #{new_resource.group}") if new_resource.group - end - end - - def verify_directories_exist - create_dir_unless_exists(new_resource.deploy_to) - create_dir_unless_exists(new_resource.shared_path) - end - - def link_current_release_to_production - converge_by(["remove existing link at #{new_resource.current_path}", - "link release #{release_path} into production at #{new_resource.current_path}"]) do - FileUtils.rm_f(new_resource.current_path) - begin - FileUtils.ln_sf(release_path, new_resource.current_path) - rescue => e - raise Chef::Exceptions::FileNotFound.new("Cannot symlink current release to production: #{e.message}") - end - Chef::Log.info "#{new_resource} linked release #{release_path} into production at #{new_resource.current_path}" - end - enforce_ownership - end - - def run_symlinks_before_migrate - links_info = new_resource.symlink_before_migrate.map { |src, dst| "#{src} => #{dst}" }.join(", ") - converge_by("make pre-migration symlinks: #{links_info}") do - new_resource.symlink_before_migrate.each do |src, dest| - begin - FileUtils.ln_sf(new_resource.shared_path + "/#{src}", release_path + "/#{dest}") - rescue => e - raise Chef::Exceptions::FileNotFound.new("Cannot symlink #{new_resource.shared_path}/#{src} to #{release_path}/#{dest} before migrate: #{e.message}") - end - end - Chef::Log.info "#{new_resource} made pre-migration symlinks" - end - end - - def link_tempfiles_to_current_release - dirs_info = new_resource.create_dirs_before_symlink.join(",") - new_resource.create_dirs_before_symlink.each do |dir| - create_dir_unless_exists(release_path + "/#{dir}") - end - Chef::Log.info("#{new_resource} created directories before symlinking: #{dirs_info}") - - links_info = new_resource.symlinks.map { |src, dst| "#{src} => #{dst}" }.join(", ") - converge_by("link shared paths into current release: #{links_info}") do - new_resource.symlinks.each do |src, dest| - begin - FileUtils.ln_sf(::File.join(new_resource.shared_path, src), ::File.join(release_path, dest)) - rescue => e - raise Chef::Exceptions::FileNotFound.new("Cannot symlink shared data #{::File.join(new_resource.shared_path, src)} to #{::File.join(release_path, dest)}: #{e.message}") - end - end - Chef::Log.info("#{new_resource} linked shared paths into current release: #{links_info}") - end - run_symlinks_before_migrate - enforce_ownership - end - - def create_dirs_before_symlink - end - - def purge_tempfiles_from_current_release - log_info = new_resource.purge_before_symlink.join(", ") - converge_by("purge directories in checkout #{log_info}") do - new_resource.purge_before_symlink.each { |dir| FileUtils.rm_rf(release_path + "/#{dir}") } - Chef::Log.info("#{new_resource} purged directories in checkout #{log_info}") - end - end - - protected - - # Internal callback, called after copy_cached_repo. - # Override if you need to keep state externally. - # Note that YOU are responsible for implementing whyrun-friendly behavior - # in any actions you take in this callback. - def release_created(release_path) - end - - # Note that YOU are responsible for using appropriate whyrun nomenclature - # Override if you need to keep state externally. - # Note that YOU are responsible for implementing whyrun-friendly behavior - # in any actions you take in this callback. - def release_deleted(release_path) - end - - def release_slug - raise Chef::Exceptions::Override, "You must override release_slug in #{self}" - end - - def install_gems - gem_resource_collection_runner.converge - end - - def gem_resource_collection_runner - child_context = run_context.create_child - gem_packages.each { |rbgem| child_context.resource_collection.insert(rbgem) } - Chef::Runner.new(child_context) - end - - def gem_packages - return [] unless ::File.exist?("#{release_path}/gems.yml") - gems = YAML.load(IO.read("#{release_path}/gems.yml")) - - gems.map do |g| - r = Chef::Resource::GemPackage.new(g[:name], run_context) - r.version g[:version] - r.action :install - r.source "http://gems.github.com" - r - end - end - - def run_options(run_opts = {}) - run_opts[:user] = new_resource.user if new_resource.user - run_opts[:group] = new_resource.group if new_resource.group - run_opts[:environment] = new_resource.environment if new_resource.environment - run_opts[:log_tag] = new_resource.to_s - run_opts[:log_level] ||= :debug - if run_opts[:log_level] == :info - if STDOUT.tty? && !Chef::Config[:daemon] && Chef::Log.info? - run_opts[:live_stream] = STDOUT - end - end - run_opts - end - - def run_callback_from_file(callback_file) - Chef::Log.info "#{new_resource} queueing checkdeploy hook #{callback_file}" - recipe_eval do - Dir.chdir(release_path) do - from_file(callback_file) if ::File.exist?(callback_file) - end - end - end - - def create_dir_unless_exists(dir) - if ::File.directory?(dir) - Chef::Log.debug "#{new_resource} not creating #{dir} because it already exists" - return false - end - converge_by("create new directory #{dir}") do - begin - FileUtils.mkdir_p(dir) - Chef::Log.debug "#{new_resource} created directory #{dir}" - if new_resource.user - FileUtils.chown(new_resource.user, nil, dir) - Chef::Log.debug("#{new_resource} set user to #{new_resource.user} for #{dir}") - end - if new_resource.group - FileUtils.chown(nil, new_resource.group, dir) - Chef::Log.debug("#{new_resource} set group to #{new_resource.group} for #{dir}") - end - rescue => e - raise Chef::Exceptions::FileNotFound.new("Cannot create directory #{dir}: #{e.message}") - end - end - end - - def with_rollback_on_error - yield - rescue ::Exception => e - if new_resource.rollback_on_error - Chef::Log.warn "Error on deploying #{release_path}: #{e.message}" - failed_release = release_path - - if previous_release_path - @release_path = previous_release_path - rollback - end - converge_by("remove failed deploy #{failed_release}") do - Chef::Log.info "Removing failed deploy #{failed_release}" - FileUtils.rm_rf failed_release - end - release_deleted(failed_release) - end - - raise - end - - def save_release_state - if ::File.exists?(new_resource.current_path) - release = ::File.readlink(new_resource.current_path) - @previous_release_path = release if ::File.exists?(release) - end - end - - def deployed?(release) - all_releases.include?(release) - end - - def current_release?(release) - @previous_release_path == release - end - end - end -end diff --git a/lib/chef/provider/deploy/revision.rb b/lib/chef/provider/deploy/revision.rb deleted file mode 100644 index 06138e4f05..0000000000 --- a/lib/chef/provider/deploy/revision.rb +++ /dev/null @@ -1,107 +0,0 @@ -# -# Author:: Daniel DeLeo (<dan@kallistec.com>) -# Author:: Tim Hinderliter (<tim@chef.io>) -# Author:: Seth Falcon (<seth@chef.io>) -# Copyright:: Copyright 2009-2016, Daniel DeLeo -# Copyright:: Copyright 2010-2016, Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef/provider" -require "chef/provider/deploy" -require "chef/json_compat" - -class Chef - class Provider - class Deploy - class Revision < Chef::Provider::Deploy - provides :deploy_revision - provides :deploy_branch - - def all_releases - sorted_releases - end - - def action_deploy - validate_release_history! - super - end - - def cleanup! - super - - known_releases = sorted_releases - - Dir["#{Chef::Util::PathHelper.escape_glob_dir(new_resource.deploy_to)}/releases/*"].each do |release_dir| - unless known_releases.include?(release_dir) - converge_by("Remove unknown release in #{release_dir}") do - FileUtils.rm_rf(release_dir) - end - end - end - end - - protected - - def release_created(release) - sorted_releases { |r| r.delete(release); r << release } - end - - def release_deleted(release) - sorted_releases { |r| r.delete(release) } - end - - def release_slug - scm_provider.revision_slug - end - - private - - def sorted_releases - cache = load_cache - if block_given? - yield cache - save_cache(cache) - end - cache - end - - def validate_release_history! - sorted_releases do |release_list| - release_list.each do |path| - release_list.delete(path) unless ::File.exist?(path) - end - end - end - - def sorted_releases_from_filesystem - Dir.glob(Chef::Util::PathHelper.escape_glob_dir(new_resource.deploy_to) + "/releases/*").sort_by { |d| ::File.ctime(d) } - end - - def load_cache - Chef::JSONCompat.parse(Chef::FileCache.load("revision-deploys/#{new_resource.name}")) - rescue Chef::Exceptions::FileNotFound - sorted_releases_from_filesystem - end - - def save_cache(cache) - Chef::FileCache.store("revision-deploys/#{new_resource.name}", Chef::JSONCompat.to_json(cache)) - cache - end - - end - end - end -end diff --git a/lib/chef/provider/deploy/timestamped.rb b/lib/chef/provider/deploy/timestamped.rb deleted file mode 100644 index 5486b092d3..0000000000 --- a/lib/chef/provider/deploy/timestamped.rb +++ /dev/null @@ -1,34 +0,0 @@ -# -# Author:: Daniel DeLeo (<dan@kallistec.com>) -# Copyright:: Copyright 2009-2016, Daniel DeLeo -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class Chef - class Provider - class Deploy - class Timestamped < Chef::Provider::Deploy - provides :timestamped_deploy - provides :deploy - - protected - - def release_slug - Time.now.utc.strftime("%Y%m%d%H%M%S") - end - end - end - end -end diff --git a/lib/chef/provider/erl_call.rb b/lib/chef/provider/erl_call.rb deleted file mode 100644 index b73341bb16..0000000000 --- a/lib/chef/provider/erl_call.rb +++ /dev/null @@ -1,76 +0,0 @@ -# -# Author:: Joe Williams (<joe@joetify.com>) -# Copyright:: Copyright 2009-2016, Joe Williams -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef/log" -require "chef/provider" - -class Chef - class Provider - class ErlCall < Chef::Provider - - provides :erl_call - - def initialize(node, new_resource) - super(node, new_resource) - end - - def load_current_resource - true - end - - def action_run - case new_resource.name_type - when "sname" - node = "-sname #{new_resource.node_name}" - when "name" - node = "-name #{new_resource.node_name}" - end - - if new_resource.cookie - cookie = "-c #{new_resource.cookie}" - else - cookie = "" - end - - if new_resource.distributed - distributed = "-s" - else - distributed = "" - end - - command = "erl_call -e #{distributed} #{node} #{cookie}" - - converge_by("run erlang block") do - so = shell_out!(command, input: new_resource.code) - - # fail if stderr contains anything - if so.stderr.length > 0 - raise Chef::Exceptions::ErlCall, so.stderr - end - - # fail if the first 4 characters aren't "{ok," - unless so.stdout[0..3].include?("{ok,") - raise Chef::Exceptions::ErlCall, so.stdout - end - - end - end - - end - end -end diff --git a/lib/chef/providers.rb b/lib/chef/providers.rb index a3332477e7..507203fd28 100644 --- a/lib/chef/providers.rb +++ b/lib/chef/providers.rb @@ -24,12 +24,10 @@ require "chef/provider/cookbook_file" require "chef/provider/cron" require "chef/provider/cron/solaris" require "chef/provider/cron/aix" -require "chef/provider/deploy" require "chef/provider/directory" require "chef/provider/dsc_script" require "chef/provider/dsc_resource" require "chef/provider/env" -require "chef/provider/erl_call" require "chef/provider/execute" require "chef/provider/file" require "chef/provider/git" @@ -131,9 +129,6 @@ require "chef/provider/mount/aix" require "chef/provider/mount/solaris" require "chef/provider/mount/windows" -require "chef/provider/deploy/revision" -require "chef/provider/deploy/timestamped" - require "chef/provider/remote_file/ftp" require "chef/provider/remote_file/sftp" require "chef/provider/remote_file/http" diff --git a/lib/chef/resource/deploy.rb b/lib/chef/resource/deploy.rb deleted file mode 100644 index f74fe86c12..0000000000 --- a/lib/chef/resource/deploy.rb +++ /dev/null @@ -1,449 +0,0 @@ -# -# Author:: Daniel DeLeo (<dan@kallistec.com>) -# Author:: Tyler Cloke (<tyler@chef.io>) -# Copyright:: Copyright 2008-2016, Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# EX: -# deploy "/my/deploy/dir" do -# repo "git@github.com/whoami/project" -# revision "abc123" # or "HEAD" or "TAG_for_1.0" or (subversion) "1234" -# user "deploy_ninja" -# enable_submodules true -# migrate true -# migration_command "rake db:migrate" -# environment "RAILS_ENV" => "production", "OTHER_ENV" => "foo" -# shallow_clone true -# depth 1 -# action :deploy # or :rollback -# restart_command "touch tmp/restart.txt" -# git_ssh_wrapper "wrap-ssh4git.sh" -# scm_provider Chef::Provider::Git # is the default, for svn: Chef::Provider::Subversion -# svn_username "whoami" -# svn_password "supersecret" -# end - -require "chef/resource/scm" - -class Chef - class Resource - - # 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.) - # - class Deploy < Chef::Resource - - identity_attr :repository - - state_attrs :deploy_to, :revision - - default_action :deploy - allowed_actions :force_deploy, :deploy, :rollback - - 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 - - # This resource is deprecated. - def after_created - Chef.deprecated(:deploy_resource, "The #{resource_name} resource (#{source_line}) is deprecated and will be removed from Chef core in 14.0 (April 2018). " \ - "A migration cookbook will be available in the future, see the deprecation documentation for more information.") - end - - # where the checked out/cloned code goes - def destination - @destination ||= shared_path + "/#{@repository_cache}" - end - - # where shared stuff goes, i.e., logs, tmp, etc. goes here - def shared_path - @shared_path ||= @deploy_to + "/shared" - end - - # where the deployed version of your code goes - def current_path - @current_path ||= @deploy_to + "/current" - end - - def depth(arg = @shallow_clone ? 5 : nil) - set_or_return( - :depth, - arg, - :kind_of => [ Integer ] - ) - end - - # note: deploy_to is your application "meta-root." - def deploy_to(arg = nil) - set_or_return( - :deploy_to, - arg, - :kind_of => [ String ] - ) - end - - def repo(arg = nil) - set_or_return( - :repo, - arg, - :kind_of => [ String ] - ) - end - alias :repository :repo - - def remote(arg = nil) - set_or_return( - :remote, - arg, - :kind_of => [ String ] - ) - end - - def role(arg = nil) - set_or_return( - :role, - arg, - :kind_of => [ String ] - ) - end - - def restart_command(arg = nil, &block) - arg ||= block - set_or_return( - :restart_command, - arg, - :kind_of => [ String, Proc ] - ) - end - alias :restart :restart_command - - def migrate(arg = nil) - set_or_return( - :migrate, - arg, - :kind_of => [ TrueClass, FalseClass ] - ) - end - - def migration_command(arg = nil) - set_or_return( - :migration_command, - arg, - :kind_of => [ String ] - ) - end - - def rollback_on_error(arg = nil) - set_or_return( - :rollback_on_error, - arg, - :kind_of => [ TrueClass, FalseClass ] - ) - end - - def user(arg = nil) - set_or_return( - :user, - arg, - :kind_of => [ String ] - ) - end - - def group(arg = nil) - set_or_return( - :group, - arg, - :kind_of => [ String ] - ) - end - - def enable_submodules(arg = nil) - set_or_return( - :enable_submodules, - arg, - :kind_of => [ TrueClass, FalseClass ] - ) - end - - def shallow_clone(arg = nil) - set_or_return( - :shallow_clone, - arg, - :kind_of => [ TrueClass, FalseClass ] - ) - end - - def repository_cache(arg = nil) - set_or_return( - :repository_cache, - arg, - :kind_of => [ String ] - ) - end - - def copy_exclude(arg = nil) - set_or_return( - :copy_exclude, - arg, - :kind_of => [ String ] - ) - end - - def revision(arg = nil) - set_or_return( - :revision, - arg, - :kind_of => [ String ] - ) - end - alias :branch :revision - - def git_ssh_wrapper(arg = nil) - set_or_return( - :git_ssh_wrapper, - arg, - :kind_of => [ String ] - ) - end - alias :ssh_wrapper :git_ssh_wrapper - - def svn_username(arg = nil) - set_or_return( - :svn_username, - arg, - :kind_of => [ String ] - ) - end - - def svn_password(arg = nil) - set_or_return( - :svn_password, - arg, - :kind_of => [ String ] - ) - end - - def svn_arguments(arg = nil) - set_or_return( - :svn_arguments, - arg, - :kind_of => [ String ] - ) - end - - def svn_info_args(arg = nil) - set_or_return( - :svn_arguments, - arg, - :kind_of => [ String ]) - end - - 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 - - # This is to support "provider :revision" without deprecation warnings. - # Do NOT copy this. - def self.provider_base - Chef::Provider::Deploy - end - - def svn_force_export(arg = nil) - set_or_return( - :svn_force_export, - arg, - :kind_of => [ TrueClass, FalseClass ] - ) - end - - 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 - - # The number of old release directories to keep around after cleanup - def keep_releases(arg = nil) - [set_or_return( - :keep_releases, - arg, - :kind_of => [ Integer ]), 1].max - 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"] - 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 - # 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"] - 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 - # 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 {"system" => "public/system", "pids" => "tmp/pids", "log" => "log"} - 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 - # 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" => "config/database.yml"} - 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 = nil, &block) - arg ||= block - set_or_return(:before_migrate, arg, :kind_of => [Proc, String]) - end - - # Callback fires before symlinking - 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 = nil, &block) - arg ||= block - set_or_return(:before_restart, arg, :kind_of => [Proc, String]) - end - - # Callback fires after restart - def after_restart(arg = nil, &block) - arg ||= block - set_or_return(:after_restart, arg, :kind_of => [Proc, String]) - end - - def additional_remotes(arg = nil) - set_or_return( - :additional_remotes, - arg, - :kind_of => Hash - ) - end - - def enable_checkout(arg = nil) - set_or_return( - :enable_checkout, - arg, - :kind_of => [TrueClass, FalseClass] - ) - end - - 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. - def timeout(arg = nil) - set_or_return( - :timeout, - arg, - :kind_of => Integer - ) - end - - end - end -end diff --git a/lib/chef/resource/deploy_revision.rb b/lib/chef/resource/deploy_revision.rb deleted file mode 100644 index 41046ec288..0000000000 --- a/lib/chef/resource/deploy_revision.rb +++ /dev/null @@ -1,31 +0,0 @@ -# -# Author:: Daniel DeLeo (<dan@kallistec.com>) -# Copyright:: Copyright 2009-2016, Daniel DeLeo -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class Chef - class Resource - - # Convenience class for using the deploy resource with the revision - # deployment strategy (provider) - class DeployRevision < Chef::Resource::Deploy - end - - class DeployBranch < Chef::Resource::DeployRevision - end - - end -end diff --git a/lib/chef/resource/erl_call.rb b/lib/chef/resource/erl_call.rb deleted file mode 100644 index 6bc71e75e6..0000000000 --- a/lib/chef/resource/erl_call.rb +++ /dev/null @@ -1,90 +0,0 @@ -# -# Author:: Joe Williams (<joe@joetify.com>) -# Author:: Tyler Cloke (<tyler@chef.io>) -# Copyright:: Copyright 2009-2016, Joe Williams -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef/resource" -require "chef/provider/erl_call" - -class Chef - class Resource - class ErlCall < Chef::Resource - - # erl_call : http://erlang.org/doc/man/erl_call.html - - identity_attr :code - - default_action :run - - def initialize(name, run_context = nil) - super - - @code = "q()." # your erlang code goes here - @cookie = nil # cookie of the erlang node - @distributed = false # if you want to have a distributed erlang node - @name_type = "sname" # type of erlang hostname name or sname - @node_name = "chef@localhost" # the erlang node hostname - end - - def code(arg = nil) - set_or_return( - :code, - arg, - :kind_of => [ String ] - ) - end - - def cookie(arg = nil) - set_or_return( - :cookie, - arg, - :kind_of => [ String ] - ) - end - - def distributed(arg = nil) - set_or_return( - :distributed, - arg, - :kind_of => [ TrueClass, FalseClass ] - ) - end - - def name_type(arg = nil) - set_or_return( - :name_type, - arg, - :kind_of => [ String ] - ) - end - - def node_name(arg = nil) - set_or_return( - :node_name, - arg, - :kind_of => [ String ] - ) - end - - # This resource is deprecated. - def after_created - Chef.deprecated(:erl_resource, "The #{resource_name} resource (#{source_line}) is deprecated and will be removed from Chef core in 14.0 (April 2018).") - end - - end - end -end diff --git a/lib/chef/resource/timestamped_deploy.rb b/lib/chef/resource/timestamped_deploy.rb deleted file mode 100644 index 1d6b07a719..0000000000 --- a/lib/chef/resource/timestamped_deploy.rb +++ /dev/null @@ -1,26 +0,0 @@ -# -# Author:: Daniel DeLeo (<dan@kallistec.com>) -# Copyright:: Copyright 2009-2016, Daniel DeLeo -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class Chef - class Resource - # Convenience class for using the deploy resource with the timestamped - # deployment strategy (provider) - class TimestampedDeploy < Chef::Resource::Deploy - end - end -end diff --git a/lib/chef/resources.rb b/lib/chef/resources.rb index 54d21fd53c..0723f1b45a 100644 --- a/lib/chef/resources.rb +++ b/lib/chef/resources.rb @@ -28,15 +28,12 @@ require "chef/resource/chef_gem" require "chef/resource/chocolatey_package" require "chef/resource/cron" require "chef/resource/csh" -require "chef/resource/deploy" -require "chef/resource/deploy_revision" require "chef/resource/directory" require "chef/resource/dpkg_package" require "chef/resource/dnf_package" require "chef/resource/dsc_script" require "chef/resource/dsc_resource" require "chef/resource/env" -require "chef/resource/erl_call" require "chef/resource/execute" require "chef/resource/file" require "chef/resource/freebsd_package" @@ -81,7 +78,6 @@ require "chef/resource/windows_service" require "chef/resource/subversion" require "chef/resource/smartos_package" require "chef/resource/template" -require "chef/resource/timestamped_deploy" require "chef/resource/user" require "chef/resource/user/aix_user" require "chef/resource/user/dscl_user" |