remote_ruby 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4723cad8943a76df4ab284d278ca6ffa49f8a10ac869dabf68d8d172f30baf63
4
- data.tar.gz: f80c91b1081e85f463b3b60fbcf58c97c5ad3c2ba93ea81492a08a114ac65cc6
3
+ metadata.gz: acba2fd4c7364a6be5101be3505de18aeb6b566e061bb9eafdc1dbff82347209
4
+ data.tar.gz: 3ce29f9130c169b18b7c9b372e8249ea399229a4f78b28aaed615cdfb98b9c2f
5
5
  SHA512:
6
- metadata.gz: e437b61ff5fb4cfe05bf172e3cac77de4fc7147852bc8938bc3a0116a5613610c9460671da4807eb3beb0df3aa694c09b1879003727d0c2721d119307e738bda
7
- data.tar.gz: 5ba9e01b990eb6f5f2a2ff4f50c9f49a5005b99c03cc5fd3ecbc0127cdbe2ae75fa70aa2b378994e7c5c665e0e1537c013e74899b6fdeb3732ef6be0654c5fab
6
+ metadata.gz: e390a2c17b1738f9aef2776fe0eaec313a2d6aa3bbc83b1be07741fad2c0d2fdeb62471f3bcf38feb3a783dfd8230c24d176ce738d7b31f49e62486c11b567c4
7
+ data.tar.gz: 538d0d9b0b8713b93624e92664075eaffcc06202107e3860ba96d506b3590c645bcaf0b522eda8cfa9f48e212de5e0e25725b8cba658c0a8bd5e9b396276cdda
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.1](https://github.com/Nu-hin/remote_ruby/releases/tag/v1.1)
4
+
5
+ * Added a new option `ruby_executable` to the `ExecutionContext`
6
+ * Fixed a bug when non-zero return code of SSH process was raising an incorrect excepion.
7
+
3
8
  ## [1.0](https://github.com/Nu-hin/remote_ruby/releases/tag/v1.0)
4
9
 
5
10
  ### Major changes
data/README.md CHANGED
@@ -22,7 +22,7 @@ RemoteRuby allows you to execute Ruby code on remote servers via SSH right from
22
22
  * [Parameters](#parameters)
23
23
  * [SSH Parameters](#ssh-parameters)
24
24
  * [Local variables](#local-variables)
25
- * [Return value and remote assignments](#return-value-and-remote-assignements)
25
+ * [Return value and remote assignments](#return-value-and-remote-assignments)
26
26
  * [Error handling](#error-handling)
27
27
  * [Caching](#caching)
28
28
  * [Text mode](#text-mode)
@@ -38,7 +38,7 @@ RemoteRuby requires at least Ruby 2.7 to run.
38
38
 
39
39
  ## Overview
40
40
 
41
- Here is a short example on how you can run your code remotely.
41
+ Here is a short example of how you can run your code remotely.
42
42
 
43
43
  ```ruby
44
44
  # This is test.rb file on the local developer machine
@@ -55,7 +55,7 @@ end
55
55
 
56
56
  When you call `#remotely` or `RemoteRuby::ExecutionContext#execute`, the passed block source is read and is then transformed to a standalone Ruby script, which also includes serialization/deserialization of local variables and return value, and other features (see [compiler.rb](lib/remote_ruby/compiler.rb) for more detail).
57
57
 
58
- After that, RemoteRuby opens an SSH connection to the specified host, copies the script to the host (to a temporary file), and then launches runs this script using the Ruby interpreter on the host. Standard output and standard error streams of SSH client are being captured. Standard input is passed to the remote code as well.
58
+ RemoteRuby then opens an SSH connection to the specified host, copies the script to a temporary file on the host, and launches it remotely using the Ruby interpreter. Standard output and standard error streams of SSH client are being captured. Standard input is passed to the remote code as well.
59
59
 
60
60
  ### Key features
61
61
 
@@ -103,11 +103,11 @@ end
103
103
  ```
104
104
 
105
105
  ### Limitations
106
- * MacOS keychain is not supported. If you are using a private SSH key with a passphrase, and you don't want to enter a passphrase each time a context is executed, the identity must be added to the SSH-agent, e.g. using `ssh-add`.
106
+ * macOS keychain is not supported. If you are using a private SSH key with a passphrase, and you don't want to enter a passphrase each time a context is executed, the identity must be added to the SSH-agent, e.g. using `ssh-add`.
107
107
 
108
108
  * As RemoteRuby reads the block source from the script's source file, the script source file should reside on your machine's disk (e.g. you cannot use RemoteRuby from IRB console).
109
109
 
110
- * Since local and server scripts have different execution contexts, can have different gems (and even Ruby versions) installed, sometimes local variables as well as the block return value, will not be accessible, assigned or can even cause exception. See [usage](#local-variables-and-return-value) section below for more detail.
110
+ * Since local and server scripts have different execution contexts, can have different gems (and even Ruby versions) installed, sometimes local variables as well as the block return value, will not be accessible, assigned or can even cause exception. See the [usage](#local-variables-and-return-value) section below for more details.
111
111
 
112
112
  ## Installation
113
113
 
@@ -186,6 +186,7 @@ In all the examples in this document, where `.remote` method is used, it is assu
186
186
  | --------- | ---- | ---------| ------------- | ----------- |
187
187
  | host | String | no | - | Name of the SSH host to connect to. If omitted, the code will be executed on the local host, in a separate Ruby process |
188
188
  | use_ssh_config_file | String or Boolean | no | true | When boolean, specifies, whether to use ~/.ssh/config file for the initial set of parameters. When string, interpreted as a path to an SSH configuration file to use |
189
+ | ruby_executable | String | no | `ruby` | Absolute path to Ruby executable on the remote host, or executable name, reachable from $PATH |
189
190
  | working_dir | String | no | '~' if running over SSH, or current dir, if running locally | Path to the directory where the script should be executed |
190
191
  | use_cache | Boolean | no | `false` | Specifies if the cache should be used for execution of the block (if the cache is available). Refer to the [Caching](#caching) section to find out more about caching. |
191
192
  | save_cache | Boolean | no | `false` | Specifies if the result of the block execution (i.e. output and error streams) should be cached for the subsequent use. Refer to the [Caching](#caching) section to find out more about caching. |
@@ -200,7 +201,7 @@ RemoteRuby will try to create it. Refer to the [Caching](#caching) section to fi
200
201
 
201
202
  In addition to the arguments above, you can fine-tune the SSH connection to the remote host, if SSH is used (that is, if the `host` argument is specified). The arguments for SSH configuration can be anything that is supported by [net-ssh gem](https://github.com/net-ssh/net-ssh). The complete list of parameters can be found in [the documentation for net-ssh](https://net-ssh.github.io/net-ssh/Net/SSH.html#method-c-start). Some of the parameters are in the table below.
202
203
 
203
- If the SSH configuration file is used (see `ssh_config` parameter in the table above), the explicitly specified values **will override** the values taken from SSH config.
204
+ If the SSH configuration file is used (see `ssh_config` parameter in the table above), the explicitly specified values **will override** those taken from SSH config.
204
205
 
205
206
  | Parameter | Type | Description |
206
207
  | --------- | ---- | ----------- |
@@ -240,7 +241,7 @@ ec3 = RemoteRuby::ExecutionContext.new(
240
241
 
241
242
  ### Output
242
243
 
243
- Standard output and standard error streams from the remote process are captured, and then, depending on your parameters are either forwarded to local STDOUT/STDERR or to the specified streams.
244
+ Standard output and standard error streams from the remote process are captured, and then, depending on your parameters are either forwarded to local standard output/error or to the specified streams.
244
245
 
245
246
  ```ruby
246
247
  remotely(host: 'my_ssh_server', working_dir: '/home/john') do
@@ -251,7 +252,7 @@ end
251
252
 
252
253
  ### Input
253
254
 
254
- Standard input from the client is captured and passed to the remote code. By default the input is captured from STDIN.
255
+ Remote script can receive data from standard input. By default the input is captured from client's standard input, but this can be set to any readable stream using `in_stream` argument to the `ExecutionContext` initializer.
255
256
 
256
257
  ```ruby
257
258
  name = remotely(host: 'my_ssh_server') do
@@ -333,7 +334,7 @@ end
333
334
  puts special_thing == 3 # => true
334
335
  ```
335
336
 
336
- If RemoteRuby cannot deserialize variable on server side, it will print a warning to server's STDERR stream.
337
+ If RemoteRuby cannot deserialize variable on server side, it will print a warning to server's standard error.
337
338
 
338
339
  It is possible to ignore certain types, so that RemoteRuby will never try to send variables of these types to the remote host. This can be done by adding configuration:
339
340
 
@@ -362,12 +363,12 @@ end
362
363
 
363
364
  RemoteRuby always ignores variables of type `RemoteRuby::ExecutionContext`.
364
365
 
365
- ### Return value and remote assignements
366
+ ### Return value and remote assignments
366
367
 
367
- If remote block returns a value which cannot be deserialized on the client side, or if it assigns such a value to the local variable, the exception on the client side will be always raised:
368
+ If remote block returns a value that cannot be deserialized on the client side, or if it assigns such a value to the local variable, the exception on the client side will be always raised:
368
369
 
369
370
  ```ruby
370
- # Unsupportable return value example
371
+ # Unsupported return value example
371
372
 
372
373
  remotely(host: 'my_ssh_server') do
373
374
  # this is not present in the client context
@@ -378,7 +379,7 @@ end
378
379
  ```
379
380
 
380
381
  ```ruby
381
- # Unsupportable local value example
382
+ # Unsupported local value example
382
383
 
383
384
  my_local = nil
384
385
 
@@ -459,7 +460,7 @@ RemoteRuby allows you to save the result of previous block excutions in the loca
459
460
  ```ruby
460
461
  # Caching example
461
462
  # First time this script will take 60 seconds to run,
462
- # but on subsequent runs it will return the result immidiately
463
+ # but on subsequent runs it will return the result immediately
463
464
 
464
465
  require 'remote_ruby'
465
466
 
@@ -475,15 +476,15 @@ end
475
476
  puts res # => Some result
476
477
  ```
477
478
 
478
- You can specify where to put your cache files explicitly, by passing `cache_dir` parameter which is the "cache" directory inside your current working directory by default.
479
+ You can specify where to put your cache files explicitly, by [configuring](#configuration) the `cache_dir` which is by default set to ".remote_ruby/cache" inside your current working directory.
479
480
 
480
- RemoteRuby calculates the cache file to use, based on the code you pass to the remote block, as well as on ExecutionContext 'contextual' parameters (e. g. server or working directory) and serialized local variables. Therefore, if you change anything in your remote block, local variables (passed to the block), or in any of the 'contextual' parameters, RemoteRuby will use different cache file. However, if you revert all your changes back, the old file will be used again.
481
+ RemoteRuby calculates the cache file to use, based on the code you pass to the remote block, as well as on `ExecutionContext` 'contextual' parameters (e. g. server or working directory) and serialized local variables. Therefore, if you change anything in your remote block, local variables (passed to the block), or in any of the 'contextual' parameters, RemoteRuby will use different cache file. However, if you revert all your changes back, the old file will be used again.
481
482
 
482
483
  **IMPORTANT**: RemoteRuby does not know when to clear the cache. Therefore, it is up to you to take care of cleaning the cache when you no longer need it. This is especially important if your output can contain sensitive data.
483
484
 
484
485
  ### Text mode
485
486
 
486
- Text mode allows to treat the output and/or the standard error of the remote process as text. If it is enabled, the server output is prefixed with some string, which makes it easier to distinguish local ouput, and the output coming from the remote code. Additionally it may help distinguishing when the output is taken from cache.
487
+ Text mode allows to treat the output and/or the standard error of the remote process as text. If it is enabled, the server output is prefixed with some string, which makes it easier to distinguish local output, and the output coming from the remote code. Additionally, it may help distinguishing when the output is taken from cache.
487
488
 
488
489
  The text mode is controlled by the `text_mode` parameter to the `::RemoteRuby::ExecutionContext` initializer, and is `false` by default.
489
490
 
@@ -509,7 +510,7 @@ jdoe@my_ssh_server:~> This is a greeting
509
510
  jdoe@my_ssh_server:~> This is a greeting
510
511
  ```
511
512
 
512
- By default, the prefixes for stdout and stderr can be different when running over SSH and locally. Output prefix is marked with green italic, and error with red italic. If the cache is used, the default configuration will append a bold blue '[C]' prefix in front of each ouput line.
513
+ By default, the prefixes for standard output and standard error can be different when running over SSH and locally. Output prefix is marked with green italic, and error with red italic. If the cache is used, the default configuration will append a bold blue '[C]' prefix in front of each output line.
513
514
 
514
515
 
515
516
  You can fine-tune the text mode to your needs by passing a hash as a value to `text_mode` parameter:
@@ -533,11 +534,11 @@ server says: This is a greeting
533
534
  server warns: This is a greeting
534
535
  ```
535
536
 
536
- It is reasonable to avoid text mode if you want to put binary data to stdout:
537
+ It is reasonable to avoid text mode if you want to put binary data to the standard output:
537
538
 
538
539
  ```ruby
539
540
  # copy_avatar.rb
540
- # Reads a file from remote server and writes it to client's stdout.
541
+ # Reads a file from remote server and writes it to client's standard output.
541
542
 
542
543
  remotely(host: 'my_ssh_server', text_mode: false) do
543
544
  STDOUT.write File.read('avatar.jpg')
@@ -621,7 +622,7 @@ Hello world!
621
622
 
622
623
 
623
624
  #### Rails plugin
624
- RemoteRuby can load Rails environment for you, if you want to execute a script in a Rails context. To do this, simply add add built-in Rails plugin by adding `rails` argument to your call:
625
+ RemoteRuby can load Rails environment for you, if you want to execute a script in a Rails context. To do this, simply add built-in Rails plugin by adding `rails` argument to your call:
625
626
 
626
627
  ```ruby
627
628
  # Rails integration example
@@ -8,13 +8,14 @@ module RemoteRuby
8
8
  class SSHAdapter < ConnectionAdapter
9
9
  UnableToExecuteError = Class.new(StandardError)
10
10
 
11
- attr_reader :host, :config, :working_dir, :user
11
+ attr_reader :host, :config, :working_dir, :user, :ruby_executable
12
12
 
13
- def initialize(host:, working_dir: nil, use_ssh_config_file: true, **params)
13
+ def initialize(host:, working_dir: nil, use_ssh_config_file: true, ruby_executable: 'ruby', **params)
14
14
  super
15
15
  @host = host
16
16
  @working_dir = working_dir
17
17
  @config = Net::SSH.configuration_for(@host, use_ssh_config_file)
18
+ @ruby_executable = ruby_executable
18
19
 
19
20
  @config = @config.merge(params)
20
21
  @user = @config[:user]
@@ -25,7 +26,7 @@ module RemoteRuby
25
26
  Net::SSH.start(host, nil, config) do |ssh|
26
27
  with_temp_file(code, ssh) do |fname|
27
28
  res = run_code(ssh, fname, stdin, stdout, stderr)
28
- raise "Process exited with code #{status}" unless res.zero?
29
+ raise "Process exited with code #{res}" unless res.zero?
29
30
 
30
31
  ret = get_result(ssh, fname)
31
32
  end
@@ -106,7 +107,7 @@ module RemoteRuby
106
107
  end
107
108
 
108
109
  def run_code(ssh, fname, stdin, stdout, stderr)
109
- cmd = "cd '#{working_dir}' && ruby \"#{fname}\""
110
+ cmd = "cd '#{working_dir}' && #{ruby_executable} \"#{fname}\""
110
111
  run_remote_process(ssh, cmd, stdin, stdout, stderr)
111
112
  end
112
113
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RemoteRuby
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remote_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Chernukhin
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-06 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: base64
@@ -179,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  requirements: []
182
- rubygems_version: 3.6.2
182
+ rubygems_version: 3.6.7
183
183
  specification_version: 4
184
184
  summary: Execute Ruby code on the remote servers.
185
185
  test_files: []