SSHKit::Custom::DSL
Exchanges original sshkit dsl against a custom dsl. This DSL does not change the scope of the blocks.
Furthor more it uses Rake::Threadpool
, to handle parallel requests. Keep in mind Runner::Parallel
and Runner::Group
execute all blocks in parallel threads, so do it thread save.
Installation
Add this line to your application's Gemfile:
gem 'sshkit-custom-dsl'
And then execute:
$ bundle
Or install it yourself as:
$ gem install sshkit-custom-dsl
Usage
require 'sshkit/custom/dsl'
extend SSHKit::Custom::DSL
require 'delegate'
# require 'sshkit/dsl' <= switch to see the different
SSHKit.configure do |sshkit|
sshkit.format = :pretty
sshkit.output_verbosity = :debug
sshkit.default_env = {}
sshkit.backend = SSHKit::Backend::Netssh
sshkit.backend.configure do |backend|
backend.pty =false
backend.connection_timeout = 5
backend.ssh_options = {user: 'deploy'}
end
end
class TestScope < SimpleDelegator
def data
{msg: "12345"}
end
def call_it
on %w{localhost 127.0.0.1}, in: :sequence, wait: 0 do
within "/tmp" do
with rails_env: :production do
execute "echo", data.fetch(:msg)
end
end
end
end
end
# new dsl not included in sshkit
default_runner_opts {in: :groups, limit: 9999}
data = {msg: "ABCD"}
TestScope.new(self).call_it
on %w{localhost 127.0.0.1}, in: :sequence, wait: 0 do
within "/tmp" do
with rails_env: :production do
execute "echo", data.fetch(:msg)
end
end
end
# thread_count is a new config option for parallel runner
# is used for Rake::ThreadPool
on %w{localhost 127.0.0.1}, thread_count: 10 do
within "/tmp" do
with rails_env: :production do
execute "env", "|sort"
end
end
end
on %w{localhost 127.0.0.1} do
within "/tmp" do
with rails_env: :production do
execute do |backend|
puts backend.inspect
["env", "|sort"]
end
end
end
end
It should work like the original one, I hope.
Contributing
- Fork it ( https://github.com/faber-lotto/sshkit-custom-dsl/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request