Skip to content

Algorithm for generating env.json for a Unit ​

INFO

The algorithm is used in three scenarios:

  1. Retrieving env.json via get_env
  2. Setting env.json via set_env
  3. Any update of a Unit program: manual or automatic

Algorithm ​

The algorithm is based on the priority of the following four representations of env.json; the lower the number, the higher the priority:

PriorityRepresentationDescription
1ManualManual input from a User in the UI of the Frontend or via set_env over REST and GQL
2Stored in DBenv.json stored in the Pepeunit database
3GeneratedStandard variables generated by the Backend
4TargetVariables specified by the Unit Developer in env_example.json

At the end of the algorithm, all keys that are not present in the Target set are removed.

INFO

If env.json is generated to be sent to a Unit or displayed to a User, an additional variable PU_COMMIT_VERSION is added. It is not stored in the database.

Algorithm examples ​

First env generation ​

Algorithm steps:

  1. Target — taken as is.
  2. Generated — fully re-generated by the Backend and overwrite keys obtained from the previous step.
  3. Stored in DB — not present.
  4. Manual — not present.
  5. All keys not present in Target are removed.

INFO

As a result you get an env.json where variables from the Unit Developer are overwritten by variables generated by Pepeunit. This env.json is already suitable for use in a Unit.

Unit changes its version automatically with a change in the set of keys ​

Algorithm steps:

  1. Target — taken as is.
  2. Generated — fully re-generated by the Backend and overwrite keys obtained from the previous step.
  3. Stored in DB — taken from the database and overwrite all values with matching keys from the previous step.
  4. Manual — not present.
  5. All keys not present in Target are removed.

INFO

As a result you get an env.json where variables from the new version of env_example.json created by the Unit Developer are added.

User modifies an existing env ​

Algorithm steps:

  1. Target — taken as is.
  2. Generated — fully re-generated by the Backend and overwrite keys obtained from the previous step.
  3. Stored in DB — taken from the database and overwrite all values with matching keys from the previous step.
  4. Manual — all keys provided by a User overwrite keys obtained from the previous step.
  5. All keys not present in Target are removed.

INFO

As a result you get an env.json where new User values overwrite the previous ones for keys that the User changed.