Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,22 @@ jobs:
use-verbose-mode: "yes"
check-modified-files-only: "yes"
base-branch: "main"

test:
name: Unit Test with Ruby
runs-on: ubuntu-latest
needs: [yamllint, cookstyle]
strategy:
fail-fast: false
matrix:
ruby: ["3.4"]
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Rake Spec
run: bundle exec rake spec
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--require spec_helper
--color
--format progress
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# Author:: Noah Kantrowitz <noah@coderanger.net>
#
# Copyright 2014, Noah Kantrowitz
# Copyright:: 2014, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,6 @@
# limitations under the License.
#

source 'http://rubygems.org'
source "https://rubygems.org"

gemspec
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ Quick Start

Run `chef gem install kitchen-sync` and then set your transport to `sftp`:

```
```yaml
transport:
name: sftp
```

Available Transfer Methods
--------------------------

### `sftp`
`sftp`
------

The default mode uses SFTP for file transfers, as well as a helper script to
avoid recopying files that are already present on the test host. If SFTP is
Expand All @@ -28,19 +29,21 @@ disabled, this will automatically fall back to the SCP mode.
By default this will use the Chef omnibus Ruby, you can customize the path to
Ruby via `ruby_path`:

```
```yaml
transport:
name: sftp
ruby_path: /usr/bin/ruby
```

### `rsync`
`rsync`
-------

The Rsync mode is based on the work done by [Mikhail Bautin](https://github.com/test-kitchen/test-kitchen/pull/359).
This is the fastest mode, but it does have a few downsides. The biggest is that
you must be using `ssh-agent` and have an identity loaded for it to use. It also
requires that rsync be available on the remote side. Consider this implementation
more experimental than `sftp` at this time.
The Rsync mode is based on the work done by [Mikhail
Bautin](https://github.com/test-kitchen/test-kitchen/pull/359). This is the
fastest mode, but it does have a few downsides. The biggest is that you must be
using `ssh-agent` and have an identity loaded for it to use. It also requires
that rsync be available on the remote side. Consider this implementation more
experimental than `sftp` at this time.

Windows Guests
--------------
Expand All @@ -52,10 +55,10 @@ Upgrading from 1.x
------------------

As of version 2.0, kitchen-sync uses Test Kitchen's modular transport system
rather than monkey patch overrides. To upgrade, remove the `<% require 'kitchen-sync' %>`
from your `.kitchen.yml` and add the transport configuration mentioned above.
The `$KITCHEN_SYNC_MODE` environment variable is no longer needed as configuration
can happen in the normal Yaml file.
rather than monkey patch overrides. To upgrade, remove the `<% require
'kitchen-sync' %>` from your `.kitchen.yml` and add the transport configuration
mentioned above. The `$KITCHEN_SYNC_MODE` environment variable is no longer
needed as configuration can happen in the normal Yaml file.

License
-------
Expand All @@ -66,7 +69,9 @@ 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
```text
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,
Expand Down
28 changes: 20 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Author:: Noah Kantrowitz <noah@coderanger.net>
#
# Copyright 2014, Noah Kantrowitz
# Copyright:: 2014, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,17 +17,29 @@
# limitations under the License.
#

require 'bundler/gem_tasks'
require "bundler/gem_tasks"

begin
require 'cookstyle'
require 'rubocop/rake_task'
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
rescue LoadError
puts "rspec is not available. (sudo) gem install rspec to enable the spec task."
end

begin
require "cookstyle/chefstyle"
require "rubocop/rake_task"
RuboCop::RakeTask.new(:style) do |task|
task.options << '--chefstyle'
task.options << '--display-cop-names'
task.options += ["--display-cop-names", "--no-color"]
end
rescue LoadError
puts 'cookstyle is not available. (sudo) gem install cookstyle to enable the style task.'
puts "cookstyle/chefstyle is not available. (sudo) gem install cookstyle to enable the style task."
end

task default: [:style]
desc "Run all tests (alias for spec)"
task test: [:spec]

desc "Run unit tests (alias for spec)"
task unit: [:spec]

task default: %i{spec style}
34 changes: 17 additions & 17 deletions kitchen-sync.gemspec
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
require "English"
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'kitchen-sync/version'
require "kitchen-sync/version"

Gem::Specification.new do |spec|
spec.name = 'kitchen-sync'
spec.name = "kitchen-sync"
spec.version = KitchenSync::VERSION
spec.authors = ['Noah Kantrowitz']
spec.email = ['noah@coderanger.net']
spec.description = %q{Improved file transfers for for test-kitchen}
spec.authors = ["Noah Kantrowitz"]
spec.email = ["noah@coderanger.net"]
spec.description = "Improved file transfers for for test-kitchen"
spec.summary = spec.description
spec.homepage = 'https://github.com/coderanger/kitchen-sync'
spec.license = 'Apache 2.0'
spec.homepage = "https://github.com/coderanger/kitchen-sync"
spec.license = "Apache 2.0"

spec.files = `git ls-files`.split($/)
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
spec.executables = []
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']
spec.require_paths = ["lib"]

spec.add_dependency 'test-kitchen', '>= 1.0.0'
spec.add_dependency 'net-sftp'
spec.add_dependency "test-kitchen", ">= 1.0.0"
spec.add_dependency "net-sftp"

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'cookstyle'
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "cookstyle"
end
5 changes: 2 additions & 3 deletions lib/kitchen-sync.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2014-2016, Noah Kantrowitz
# Copyright:: 2014-2016, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,6 @@
# limitations under the License.
#


class KitchenSync
autoload :VERSION, 'kitchen-sync/version'
autoload :VERSION, "kitchen-sync/version"
end
11 changes: 5 additions & 6 deletions lib/kitchen-sync/checksums.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# Author:: Noah Kantrowitz <noah@coderanger.net>
#
# Copyright 2014, Noah Kantrowitz
# Copyright:: 2014, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,21 +16,20 @@
# limitations under the License.
#

require 'json'
require 'digest/sha1'
require "json" unless defined?(JSON)
require "digest/sha1" unless defined?(Digest::SHA1)

glob_path = base = ARGV.first
glob_path = File.join(glob_path, '**', '*') if File.directory?(glob_path)
glob_path = File.join(glob_path, "**", "*") if File.directory?(glob_path)
d = Digest::SHA1.new
STDOUT.write(
Dir.glob(glob_path, File::FNM_PATHNAME | File::FNM_DOTMATCH).inject({}) do |memo, path|
Dir.glob(glob_path, File::FNM_PATHNAME | File::FNM_DOTMATCH).each_with_object({}) do |path, memo|
rel_path = path[base.length..-1]
if File.file?(path) && File.readable?(path)
d.reset
memo[rel_path] = d.file(path).hexdigest
elsif File.directory?(path)
memo[rel_path] = true
end
memo
end.to_json
)
10 changes: 4 additions & 6 deletions lib/kitchen-sync/core_ext.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2014-2016, Noah Kantrowitz
# Copyright:: 2014-2016, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -19,18 +19,16 @@ module Kitchen
# Monkey patch to prevent the deletion of everything
module Provisioner
class ChefBase < Base

old_init_command = instance_method(:init_command)

define_method(:init_command) do
if (defined?(Kitchen::Transport::Sftp) && instance.transport.is_a?(Kitchen::Transport::Sftp)) || \
(defined?(Kitchen::Transport::Rsync) && instance.transport.is_a?(Kitchen::Transport::Rsync))
"mkdir -p #{config[:root_path]}"
(defined?(Kitchen::Transport::Rsync) && instance.transport.is_a?(Kitchen::Transport::Rsync))
"mkdir -p #{config[:root_path]}"
else
old_init_command.bind(self).()
old_init_command.bind(self).call
end
end

end
end
end
5 changes: 2 additions & 3 deletions lib/kitchen-sync/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2014-2016, Noah Kantrowitz
# Copyright:: 2014-2016, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,6 @@
# limitations under the License.
#


class KitchenSync
VERSION = '2.2.2.pre'
VERSION = "2.2.2.pre".freeze
end
Loading