Skip to content

Design: Version Control

Nick O'Leary edited this page Jul 13, 2016 · 17 revisions

Target: 0.15

When we talk about version control of node-red instances, there are two things that it covers:

  1. the nodes added to the environment via npm
  2. the deployed flows (+credentials)

It is desirable to have a single artefact (or logical set of artefacts) that can be maintained in version control and used to restore a system to a previous known state.

The priority is version control of flows/credentials - and is the main focus of this work. The Added Nodes scenarios are for a future piece of work.

Added Nodes

Currently, a user simply npm installs nodes in their user directory to add them to the runtime - or uses the admin api to do so. There is no requirement to maintain a package.json file. But it is that file that needs to be version controlled in order to have a restorable system.

This raises some questions:

  • should we try to create/maintain a package.json file under the user directory - in much the same way that npm install --save does.
  • should we do this via the Storage API so alternative (non-filesystem) based solutions can make use of it

Deployed Flows

Use cases include:

  • a user creates a new version of the flows by simply clicking deploy
  • a user can optionally add a comment to the version
  • a user can see a history of versions - showing date/time + comment (aka git log)
  • a user can load a previous version into the editor, which, if then deployed becomes a new version

API

Whilst clearly influenced by git as a likely common backend, the version control API needs to be careful to abstract the operations it provides sufficiently so that alternative VC systems can be used underneath it. It does not require the full breadth of capability that git provides (branching/merging etc).

The basic operations are:

  • get a version - defaults to the most recent version, but a version id can also be specified
  • save a new version of flows/credentials with an optional description. This returns a version id.
  • get the version history - returns a list of id/user/timestamp/description

The API should also allow a 'user' identified to passed to each of these calls.

The existing API has separate methods for saving flows and credentials. The new API must version them as a single entity, although underlying implementations may choose to store them separately.


Storage.init(runtime)

  • runtime : a RED runtime object

Passing in the runtime object allows the storage mechanism to access the settings, log components properly as well as comms if it needs to send notifications to the user.

Storage.getFlows([id])

  • id : optional : identifies a specific version to return

Returns a promise that resolves to the combined flow/credential configuration

Storage.setFlows(flowConfig,[options])

  • flowConfig : the combined flow/credential configuration
  • options : optional : an options object that can contain the following properties:
    • user : optional : an identifier for the user setting the flows
    • description : optional : a short description to associate with the change

Returns a promise that resolves to the id of the version saved.

Storage.getFlowHistory()

Returns a promise that resolves to an array of history entries. Each entry consists of:

  • id : the version id
  • date : the timestamp of the version (format tbd)
  • description : the short description of the change (will have sensible default, or blank, if none specified)
  • user : an identifier for the user who saved the version

The format of the combined flow/credential configuration is a vital detail that needs some more thinking.

The starting point will be the already documented new flow format. With an additional credential property at the top level that contains the node credentials.

UI Changes

There are two parts additions to the UI:

  1. checkbox on Deploy menu to prompt for deploy description
  • if checked, a modal dialog appears each time Deploy is clicked to allow the user to provide a description for the deploy
  • if not checked, clicking deploy does not prompt for a message
  1. an option on Deploy menu to show Deploy History
  • the option opens a new sidebar panel that lists the history of deploys.
  • each list entry provides the ability to load that version into the editor. If the workspace is currently dirty, doing so will first prompt to confirm changes will be lost.

Clone this wiki locally