Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilja Bobkevic committed Jul 8, 2015
1 parent 1c54c0c commit 5f78a24
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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'
```
23 changes: 23 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions kitchen-transport-rsync.gemspec
Original file line number Diff line number Diff line change
@@ -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 = '[email protected]'
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
23 changes: 23 additions & 0 deletions lib/kitchen-transport-rsync/version.rb
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions lib/kitchen/transport/rsync.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# Author:: Ilja Bobkevic <[email protected]>
#
# 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

0 comments on commit 5f78a24

Please sign in to comment.