summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2016-05-31 18:30:07 +0100
committerThom May <thom@may.lt>2016-05-31 18:30:07 +0100
commit658faba8396309764cae68800cf89274c1e29489 (patch)
treea62cf30594e785c43ed1bdc82e2cf785061ae47b
parent92df46a80b3bdea55eb4e653c291db459b3b0101 (diff)
parent9f5653610099d8975921eb58d1283e4d7da56ce7 (diff)
downloadchef-658faba8396309764cae68800cf89274c1e29489.tar.gz
Merge pull request #4979 from andrewjamesbrown/master
Fix #4949 and Avoid Errno::EBUSY on docker containers
-rw-r--r--lib/chef/dsl/platform_introspection.rb16
-rw-r--r--lib/chef/resource/file.rb7
2 files changed, 22 insertions, 1 deletions
diff --git a/lib/chef/dsl/platform_introspection.rb b/lib/chef/dsl/platform_introspection.rb
index 276a03af63..a0c2d33967 100644
--- a/lib/chef/dsl/platform_introspection.rb
+++ b/lib/chef/dsl/platform_introspection.rb
@@ -245,6 +245,22 @@ class Chef
end
end
+ # Shamelessly stolen from https://github.com/sethvargo/chef-sugar/blob/master/lib/chef/sugar/docker.rb
+ # Given a node object, returns whether the node is a docker container.
+ #
+ # === Parameters
+ # node:: [Chef::Node] The node to check.
+ #
+ # === Returns
+ # true:: if the current node is a docker container
+ # false:: if the current node is not a docker container
+ def docker?(node = run_context.nil? ? nil : run_context.node)
+ # Using "File.exist?('/.dockerinit') || File.exist?('/.dockerenv')" makes Travis sad,
+ # and that makes us sad too.
+ node && node[:virtualization] && node[:virtualization][:systems] &&
+ node[:virtualization][:systems][:docker] && node[:virtualization][:systems][:docker] == "guest"
+ end
+
end
end
end
diff --git a/lib/chef/resource/file.rb b/lib/chef/resource/file.rb
index ac6dc5fbdb..7088e7613e 100644
--- a/lib/chef/resource/file.rb
+++ b/lib/chef/resource/file.rb
@@ -21,6 +21,7 @@ require "chef/resource"
require "chef/platform/query_helpers"
require "chef/mixin/securable"
require "chef/resource/file/verification"
+require "pathname"
class Chef
class Resource
@@ -49,7 +50,7 @@ class Chef
allowed_actions :create, :delete, :touch, :create_if_missing
property :path, String, name_property: true, identity: true
- property :atomic_update, [ true, false ], desired_state: false, default: lazy { Chef::Config[:file_atomic_update] }
+ property :atomic_update, [ true, false ], desired_state: false, default: lazy { |r| r.docker? && r.special_docker_files?(r.path) ? false : Chef::Config[:file_atomic_update] }
property :backup, [ Integer, false ], desired_state: false, default: 5
property :checksum, [ /^[a-zA-Z0-9]{64}$/, nil ]
property :content, [ String, nil ], desired_state: false
@@ -78,6 +79,10 @@ class Chef
end
state_attrs
end
+
+ def special_docker_files?(file)
+ %w{/etc/hosts /etc/hostname /etc/resolv.conf}.include?(Pathname(file).cleanpath.to_path)
+ end
end
end
end