provisioners/chef: use synced folder cache instead of counter
This commit is contained in:
parent
52ff661d31
commit
155516fb6c
|
@ -1,11 +1,7 @@
|
||||||
require "vagrant/util/counter"
|
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module Chef
|
module Chef
|
||||||
module Config
|
module Config
|
||||||
class Base < Vagrant.plugin("2", :config)
|
class Base < Vagrant.plugin("2", :config)
|
||||||
extend Vagrant::Util::Counter
|
|
||||||
|
|
||||||
# The path to Chef's bin/ directory.
|
# The path to Chef's bin/ directory.
|
||||||
# @return [String]
|
# @return [String]
|
||||||
attr_accessor :binary_path
|
attr_accessor :binary_path
|
||||||
|
@ -48,11 +44,11 @@ module VagrantPlugins
|
||||||
# @return [String]
|
# @return [String]
|
||||||
attr_accessor :version
|
attr_accessor :version
|
||||||
|
|
||||||
# The path where the Chef installer will be downloaded to. Only valid if
|
# The path where the Chef installer will be downloaded to. Only valid if
|
||||||
# install is true or "force". It defaults to nil, which means that the
|
# install is true or "force". It defaults to nil, which means that the
|
||||||
# omnibus installer will choose the destination and you have no control
|
# omnibus installer will choose the destination and you have no control
|
||||||
# over it.
|
# over it.
|
||||||
#
|
#
|
||||||
# @return [String]
|
# @return [String]
|
||||||
attr_accessor :installer_download_path
|
attr_accessor :installer_download_path
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ module VagrantPlugins
|
||||||
@https_proxy_pass = nil if @https_proxy_pass == UNSET_VALUE
|
@https_proxy_pass = nil if @https_proxy_pass == UNSET_VALUE
|
||||||
@no_proxy = nil if @no_proxy == UNSET_VALUE
|
@no_proxy = nil if @no_proxy == UNSET_VALUE
|
||||||
@node_name = nil if @node_name == UNSET_VALUE
|
@node_name = nil if @node_name == UNSET_VALUE
|
||||||
@provisioning_path = nil if @provisioning_path == UNSET_VALUE
|
@provisioning_path = "/tmp/vagrant-chef" if @provisioning_path == UNSET_VALUE
|
||||||
@file_backup_path = "/var/chef/backup" if @file_backup_path == UNSET_VALUE
|
@file_backup_path = "/var/chef/backup" if @file_backup_path == UNSET_VALUE
|
||||||
@file_cache_path = "/var/chef/cache" if @file_cache_path == UNSET_VALUE
|
@file_cache_path = "/var/chef/cache" if @file_cache_path == UNSET_VALUE
|
||||||
@verbose_logging = false if @verbose_logging == UNSET_VALUE
|
@verbose_logging = false if @verbose_logging == UNSET_VALUE
|
||||||
|
@ -89,12 +89,6 @@ module VagrantPlugins
|
||||||
if @encrypted_data_bag_secret_key_path == UNSET_VALUE
|
if @encrypted_data_bag_secret_key_path == UNSET_VALUE
|
||||||
@encrypted_data_bag_secret_key_path = nil
|
@encrypted_data_bag_secret_key_path = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set the default provisioning path to be a unique path in /tmp
|
|
||||||
if !@provisioning_path
|
|
||||||
counter = self.class.get_and_update_counter(:chef_config)
|
|
||||||
@provisioning_path = "/tmp/vagrant-chef-#{counter}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def merge(other)
|
def merge(other)
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
require "digest/md5"
|
||||||
|
require "securerandom"
|
||||||
|
require "set"
|
||||||
|
|
||||||
require "log4r"
|
require "log4r"
|
||||||
|
|
||||||
require "vagrant/util/counter"
|
require "vagrant/util/counter"
|
||||||
|
@ -11,6 +15,8 @@ module VagrantPlugins
|
||||||
class ChefSolo < Base
|
class ChefSolo < Base
|
||||||
extend Vagrant::Util::Counter
|
extend Vagrant::Util::Counter
|
||||||
include Vagrant::Util::Counter
|
include Vagrant::Util::Counter
|
||||||
|
include Vagrant::Action::Builtin::MixinSyncedFolders
|
||||||
|
|
||||||
attr_reader :environments_folders
|
attr_reader :environments_folders
|
||||||
attr_reader :cookbook_folders
|
attr_reader :cookbook_folders
|
||||||
attr_reader :role_folders
|
attr_reader :role_folders
|
||||||
|
@ -28,10 +34,11 @@ module VagrantPlugins
|
||||||
@data_bags_folders = expanded_folders(@config.data_bags_path, "data_bags")
|
@data_bags_folders = expanded_folders(@config.data_bags_path, "data_bags")
|
||||||
@environments_folders = expanded_folders(@config.environments_path, "environments")
|
@environments_folders = expanded_folders(@config.environments_path, "environments")
|
||||||
|
|
||||||
share_folders(root_config, "csc", @cookbook_folders)
|
existing = synced_folders(@machine, cached: true)
|
||||||
share_folders(root_config, "csr", @role_folders)
|
share_folders(root_config, "csc", @cookbook_folders, existing)
|
||||||
share_folders(root_config, "csdb", @data_bags_folders)
|
share_folders(root_config, "csr", @role_folders, existing)
|
||||||
share_folders(root_config, "cse", @environments_folders)
|
share_folders(root_config, "csdb", @data_bags_folders, existing)
|
||||||
|
share_folders(root_config, "cse", @environments_folders, existing)
|
||||||
end
|
end
|
||||||
|
|
||||||
def provision(mode = :solo)
|
def provision(mode = :solo)
|
||||||
|
@ -72,8 +79,10 @@ module VagrantPlugins
|
||||||
local_path = File.expand_path(path, @machine.env.root_path)
|
local_path = File.expand_path(path, @machine.env.root_path)
|
||||||
|
|
||||||
if File.exist?(local_path)
|
if File.exist?(local_path)
|
||||||
# Path exists on the host, setup the remote path
|
# Path exists on the host, setup the remote path. We use
|
||||||
remote_path = "#{@config.provisioning_path}/chef-solo-#{get_and_update_counter(:cookbooks_path)}"
|
# the MD5 of the local path so that it is predictable.
|
||||||
|
key = Digest::MD5.hexdigest(local_path)
|
||||||
|
remote_path = "#{@config.provisioning_path}/#{key}"
|
||||||
else
|
else
|
||||||
@machine.ui.warn(I18n.t("vagrant.provisioners.chef.cookbook_folder_not_found_warning",
|
@machine.ui.warn(I18n.t("vagrant.provisioners.chef.cookbook_folder_not_found_warning",
|
||||||
path: local_path.to_s))
|
path: local_path.to_s))
|
||||||
|
@ -103,16 +112,31 @@ module VagrantPlugins
|
||||||
|
|
||||||
# Shares the given folders with the given prefix. The folders should
|
# Shares the given folders with the given prefix. The folders should
|
||||||
# be of the structure resulting from the `expanded_folders` function.
|
# be of the structure resulting from the `expanded_folders` function.
|
||||||
def share_folders(root_config, prefix, folders)
|
def share_folders(root_config, prefix, folders, existing=nil)
|
||||||
folders.each do |type, local_path, remote_path|
|
existing_set = Set.new
|
||||||
if type == :host
|
(existing || []).each do |_, fs|
|
||||||
opts = {}
|
fs.each do |id, data|
|
||||||
opts[:id] = "v-#{prefix}-#{self.class.get_and_update_counter(:shared_folder)}"
|
existing_set.add(data[:guestpath])
|
||||||
opts[:type] = @config.synced_folder_type if @config.synced_folder_type
|
|
||||||
|
|
||||||
root_config.vm.synced_folder(local_path, remote_path, opts)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
folders.each do |type, local_path, remote_path|
|
||||||
|
next if type != :host
|
||||||
|
|
||||||
|
# If this folder already exists, then we don't share it, it means
|
||||||
|
# it was already put down on disk.
|
||||||
|
if existing_set.include?(remote_path)
|
||||||
|
@logger.debug("Not sharing #{local_path}, exists as #{remote_path}")
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
opts = {}
|
||||||
|
opts[:id] = "v-#{prefix}-#{self.class.get_and_update_counter(:shared_folder)}"
|
||||||
|
opts[:type] = @config.synced_folder_type if @config.synced_folder_type
|
||||||
|
|
||||||
|
root_config.vm.synced_folder(local_path, remote_path, opts)
|
||||||
|
end
|
||||||
|
|
||||||
@shared_folders += folders
|
@shared_folders += folders
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue