Practice of Communication Between Electron GUI and Ruby CLI in DevOps
The article explains how DevOps teams can evolve Ruby command‑line tools into gem packages and connect them to an Electron GUI, comparing file‑based, Unix‑domain‑socket, and Node IPC communication methods while addressing Ruby environment setup, bundler nuances, and debugging techniques.
This article discusses how to efficiently manage scattered Ruby scripts in medium to large client development teams and presents four stages of command-line tool evolution. The author focuses on stages 3 and 4, demonstrating how to package Ruby scripts as gem packages for CLI tools and then integrate them with an Electron-based GUI.
The article explores cross-language inter-process communication (IPC) between Electron (JavaScript/TypeScript) and Ruby, presenting three communication approaches:
1. File-based Communication: GUI creates parameter files and result files, passing file paths to CLI via command-line options. Parameters use JSON.stringify(JSON.stringify()) for special character escaping. Suitable for cross-platform compatibility and simple real-time requirements.
2. Unix Domain Socket: Uses filesystem as address space without network protocol stack. Supports multiple concurrent connections and high-throughput scenarios. Requires manual cleanup with fs.unlink() for path reuse.
3. Node Built-in IPC: Uses NODE_CHANNEL_FD environment variable to establish IPC channel between parent and child processes. Only supports JSON format strings. Implemented by passing 'ipc' in stdio array options.
The article also covers practical challenges including Ruby environment injection in Shell processes (using Rvm), two invocation methods (bundle exec vs direct command), Bundler environment handling, and debugging approaches for both Ruby (RubyMine, pry-byebug) and Electron (VSCode).
NetEase Cloud Music Tech Team
Official account of NetEase Cloud Music Tech Team
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.