diff --git a/.gitignore b/.gitignore index 28f4849..0a387f8 100644 --- a/.gitignore +++ b/.gitignore @@ -27,9 +27,9 @@ build/ # for a library or gem, you might want to ignore these files since the code is # intended to run in multiple environments; otherwise, check them in: -# Gemfile.lock -# .ruby-version -# .ruby-gemset +*.lock +.ruby-version +.ruby-gemset # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1242cdc --- /dev/null +++ b/.travis.yml @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +# +# Copyright 2015 North Development AB +# +# 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. + +language: ruby +rvm: + - 1.9.3 + - 2.0.0 + +script: + - bundle exec rake \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..2f10b2b --- /dev/null +++ b/Gemfile @@ -0,0 +1,20 @@ +# -*- encoding: utf-8 -*- +# +# Copyright 2015 North Development AB +# +# 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. + + +source 'https://rubygems.org' + +gemspec \ No newline at end of file diff --git a/LICENSE b/LICENSE index 8f71f43..2e5e1d2 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright {yyyy} {name of copyright owner} + Copyright 2015 North Development AB Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 7d2711a..4bba349 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,23 @@ # kitchen-transport-rsync - Test Kitchen transport Rsync + +[![Build Status](https://api.travis-ci.org/unibet/kitchen-transport-rsync.svg)](https://travis-ci.org/unibet/kitchen-transport-rsync) +[![Gem Version](https://badge.fury.io/rb/kitchen-transport-rsync.svg)](http://badge.fury.io/rb/kitchen-transport-rsync) + +This transport is based on rsync over ssh providing dramatic performance improvements. +It will only work with TK 1.4 and rsync has to be available in the PATH on both local and remote end points. + +Only passwordless (using ssh key pair) communication is supported at the moment. + +## Recommended **.kitchen.yml** snippet to activate Rsync transport + +``` +transport: + name: rsync + ssh_key: ~/.vagrant.d/insecure_private_key + username: vagrant +``` + +## Gemfile +``` +gem 'kitchen-transport-rsync' +``` diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..60ca469 --- /dev/null +++ b/Rakefile @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +# +# Copyright 2015 North Development AB +# +# 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. + +task :default => [:syntax_ruby] + +task :syntax_ruby do + Dir['**/*.rb'].each do |f| + system("ruby -Ku -c #{f}") + end +end diff --git a/kitchen-transport-rsync.gemspec b/kitchen-transport-rsync.gemspec new file mode 100644 index 0000000..3e5f091 --- /dev/null +++ b/kitchen-transport-rsync.gemspec @@ -0,0 +1,39 @@ +# -*- encoding: utf-8 -*- +# +# Copyright 2015 North Development AB +# +# 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. + +$:.push File.expand_path('../lib', __FILE__) + +require 'kitchen-transport-rsync/version' + +Gem::Specification.new do |spec| + spec.name = 'kitchen-transport-rsync' + spec.version = Kitchen::Transport::Rsync::VERSION + spec.authors = 'Ilja Bobkevic' + spec.email = 'ilja.bobkevic@unibet.com' + spec.description = 'Additional Test kitchen transport using rsync' + spec.summary = spec.description + spec.homepage = 'https://github.com/unibet/kitchen-transport-rsync' + spec.license = 'Apache 2' + + spec.files = `git ls-files`.split($/) + spec.executables = [] + spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) + spec.require_paths = %w(lib) + + spec.add_dependency 'test-kitchen', '~> 1.4' + spec.add_development_dependency 'rake', '~> 10.4' + spec.add_development_dependency 'rspec', '~> 3.3' +end diff --git a/lib/kitchen-transport-rsync/version.rb b/lib/kitchen-transport-rsync/version.rb new file mode 100644 index 0000000..7e7ea46 --- /dev/null +++ b/lib/kitchen-transport-rsync/version.rb @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +# +# Copyright 2015 North Development AB +# +# 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. + +module Kitchen + module Transport + module Rsync + VERSION = '0.1.0' + end + end +end \ No newline at end of file diff --git a/lib/kitchen/transport/rsync.rb b/lib/kitchen/transport/rsync.rb new file mode 100644 index 0000000..f38e6bc --- /dev/null +++ b/lib/kitchen/transport/rsync.rb @@ -0,0 +1,54 @@ +# +# Author:: Ilja Bobkevic +# +# Copyright 2015, North Development AB +# +# 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 'kitchen/transport/ssh' + +module Kitchen + module Transport + class Rsync < Ssh + + def create_new_connection(options, &block) + if @connection + logger.debug("[SSH] shutting previous connection #{@connection}") + @connection.close + end + + @connection_options = options + @connection = self.class::Connection.new(options, &block) + end + + class Connection < Ssh::Connection + def upload(locals, remote) + Array(locals).each do |local| + full_remote = File.join(remote, File.basename(local)) + recursive = File.directory?(local) + execute("mkdir -p #{full_remote}") if recursive + time = Benchmark.realtime do + ssh_command = [login_command.command, login_command.arguments].flatten.join(' ') + sync_command = "rsync -e '#{ssh_command}' -a#{@logger.debug? ? 'v' : ''}z #{local} #{@session.options[:user]}@#{@session.host}:#{remote}" + @logger.debug("[RSYNC] Running rsync command: #{sync_command}") + system(sync_command) + end + logger.info("[RSYNC] Time taken to upload #{local} to #{self}:#{full_remote}: %.2f sec" % time) + end + end + end + + end + end +end \ No newline at end of file