Last active
December 31, 2015 05:59
-
-
Save pschultz/7944955 to your computer and use it in GitHub Desktop.
Running kitchen converge is part of your normal workflow when developing cookbooks? VMs are always local and Chef is run in solo mode? Annoyed by the unnecessary cookbook upload every time you run kitchen that takes longer than actually converging the node? Here is a hack for you, that makes kitchen use rsync instead of scp. The diff is based on…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/kitchen/provisioner/chef_base.rb b/lib/kitchen/provisioner/chef_base.rb | |
index 79235d4..bb4fccf 100644 | |
--- a/lib/kitchen/provisioner/chef_base.rb | |
+++ b/lib/kitchen/provisioner/chef_base.rb | |
@@ -102,9 +102,7 @@ module Kitchen | |
end | |
def init_command | |
- dirs = %w{cookbooks data data_bags environments roles}. | |
- map { |dir| File.join(config[:root_path], dir) }.join(" ") | |
- "#{sudo('rm')} -rf #{dirs} ; mkdir -p #{config[:root_path]}" | |
+ "mkdir -p #{config[:root_path]}" | |
end | |
def cleanup_sandbox | |
diff --git a/lib/kitchen/ssh.rb b/lib/kitchen/ssh.rb | |
index 95320e4..c1af10a 100644 | |
--- a/lib/kitchen/ssh.rb | |
+++ b/lib/kitchen/ssh.rb | |
@@ -59,15 +59,20 @@ module Kitchen | |
end | |
def upload!(local, remote, options = {}, &progress) | |
- if progress.nil? | |
- progress = lambda { |ch, name, sent, total| | |
- if sent == total | |
- logger.debug("Uploaded #{name} (#{total} bytes)") | |
- end | |
- } | |
+ ssh_opts = session.options | |
+ | |
+ additional_rsync_flags = "--delete-before --rsync-path='sudo rsync'" | |
+ | |
+ if ::File.directory?(local) | |
+ local = "#{local}/" | |
+ remote = "#{remote}/#{::File.basename(local)}/" | |
+ if ::File.basename(local) == "cache" | |
+ additional_rsync_flags = "" | |
+ end | |
end | |
- session.scp.upload!(local, remote, options, &progress) | |
+ logger.info("Synchronizing #{local} -> #{remote}") | |
+ system("rsync #{additional_rsync_flags} -ire 'ssh -l #{ssh_opts[:user]} -o StrictHostKeyChecking=no -o UserKnownHostsfile=#{ssh_opts[:user_known_hosts_file]} -i #{ssh_opts[:keys].first} -p #{ssh_opts[:port]}' '#{local}' localhost:'#{remote}' >&2") | |
end | |
def upload_path!(local, remote, options = {}, &progress) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment