Algorithm for generating env.json for a Unit
INFO
The algorithm is used in three scenarios:
Algorithm
The algorithm is based on the priority of the following four representations of env.json; the lower the number, the higher the priority:
| Priority | Representation | Description |
|---|---|---|
| 1 | Manual | Manual input from a User in the UI of the Frontend or via set_env over REST and GQL |
| 2 | Stored in DB | env.json stored in the Pepeunit database |
| 3 | Generated | Standard variables generated by the Backend |
| 4 | Target | Variables 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:
Target— taken as is.Generated— fully re-generated by the Backend and overwrite keys obtained from the previous step.Stored in DB— not present.Manual— not present.- All keys not present in
Targetare 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:
Target— taken as is.Generated— fully re-generated by the Backend and overwrite keys obtained from the previous step.Stored in DB— taken from the database and overwrite all values with matching keys from the previous step.Manual— not present.- All keys not present in
Targetare 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:
Target— taken as is.Generated— fully re-generated by the Backend and overwrite keys obtained from the previous step.Stored in DB— taken from the database and overwrite all values with matching keys from the previous step.Manual— all keys provided by a User overwrite keys obtained from the previous step.- All keys not present in
Targetare removed.