Consensys / quorum-genesis-tool

The quorum genesis tool creates genesis configs, configuration files, and keys for Hyperledger Besu, GoQuorum and Tessera.
Apache License 2.0
22 stars 20 forks source link

Create copyReplace.ts #57

Closed defiQUG closed 8 months ago

defiQUG commented 9 months ago

A tool which runs a simulation, confirms, creates backup in tar.gz, copy/replaces the existing config with the output from the genesis tool.

Full information for a README:

USER:

Please provide a full description of this typescript tool

ASSISTANT:

Creating a TypeScript-based tool to simulate file operations before actually performing them, especially for tasks like file copying and directory structure alignment, involves a more complex setup than a simple shell script. This is primarily because TypeScript (and JavaScript) runs in a Node.js environment, which is not as directly integrated with the file system and shell operations as bash scripting. However, Node.js provides powerful libraries, such as fs for file system operations and child_process for executing shell commands, making it possible to create a sophisticated tool for your requirements.

Description of the TypeScript Tool

This TypeScript tool will be designed to run on a Node.js environment and will perform the following tasks:

  1. Simulation Phase:

    • It will simulate the copying process from the output directory to the config directory based on the most recent directory within output.
    • It will list all files that would be copied or replaced, showing the source and destination paths without actually performing the copy. This allows the user to review the changes that will be made.
  2. Confirmation:

    • After the simulation, the tool will prompt the user to enter CONFIRM to proceed with the actual copying process. If the user does not confirm, the tool will exit without making any changes.
  3. Backup Phase:

    • Before copying files, the tool will create a tar.gz archive of the entire config directory's current state. This serves as a backup to restore the original state in case of any issues with the update process.
  4. Copy and Replace Phase:

    • Upon confirmation, the tool will then proceed to copy and replace files from the output directory to the config directory, following the simulation's outline.

Technical Considerations

Implementation Outline

The tool will be structured into several main components:

Usage

The tool will be a command-line application executed with Node.js. Users will run it from the terminal in the directory containing both the config and output directories. The workflow will be:

  1. Execute the tool via node [toolName].js or through an npm script.
  2. Review the simulated operations output by the tool.
  3. Enter CONFIRM when prompted to proceed with the copying and backup creation.
  4. Review the final output indicating successful copying and backup.

Advantages

This TypeScript tool provides a user-friendly interface for reviewing potential file system changes before they occur, along with a straightforward method for confirming those changes. It also ensures that a backup is created, adding a layer of safety to the operation.

Development Requirements

This description outlines a high-level overview of what the tool would look like and how it would function. Implementing such a tool requires writing TypeScript code, compiling it to JavaScript, and then running it with Node.js. It offers a robust and user-interactive way to manage file system operations with the added benefit of cross-platform compatibility.

joshuafernandes commented 8 months ago

Hello @defiQUG thanks for this. We welcome contributions so please feel free to send a PR across and we can review and add functionality in.

Could you also elaborate on what problem this PR is actually solving please? Unless Im missing something here, this feels more complex than what it needs to be? Could you explain the benefit of simulating files being written before writing them - this feels more like something that belongs in the https://www.npmjs.com/package/tmp or https://www.npmjs.com/package/fs-extra repos maybe ie its boilerplate, rather than app specific. The app stores values in memory till the final phase before they are written and zipped, so if something breaks it fails fast without waiting for the user to confirm etc.

The second problem with this approach is that the cli is used for automation - ie in CI where we don't want a user input as it halts a pipeline, where this will halt the pipeline until the user allows it? The existing approach will attempt a write and if it fails the exit code can be read by the next step in the pipeline which alerts the user of issues.

Cheers

defiQUG commented 8 months ago

It's a tool I personally have used. This is really for those using the Quorum Dev Quickstart, then using the Genesis Tool to change keys. Honestly, you can put it wherever it is appropriate. I occasionally will share some stuff; but really, I have the FusionAI Orchestrator becoming available soon.

joshuafernandes commented 8 months ago

Hi @defiQUG yep that is correct we use this in the quickstart and k8s repos. Im still not sure what problem the PR is solving though or how it addresses the concerns of automation. I'll close this PR if that's ok (feel free to open it if it addresses the concerns raised above). Let us know when the FusionAI Orchestrator is ready

Cheers