Gino Keva – Git Notes key value
Gino Keva is a simple key-value store built on top of Git Notes, using an event source architecture.
- Events are added to the current commit when key values are manipulated via GET or unset.
- Gino Keva compiles a snapshot of all historical key values by replaying all events committed up to now.
Use case
Although Gino Keva was written with the following uses in mind, it is intended to be a universal tool. Don’t be discouraged if your goals are very different. Instead, you are free to open a ticket so we can discuss whether we can make it work.
The requirements for Gino Keva arise in an environment where approximately 20 components (some call microservices) live together in a single repository. Each component is deployed in a Docker container and together they constitute an application/service. There is a single build pipeline that triggers any changes. The pipeline will then fan out, triggering a separate build (and test) for each component affected by the change. For each component, this will generate a new Docker container and push its version to the registry. Once all the components have been rebuilt, this set of containers, some of which are newly built, can be deployed and tested, and eventually rolled out into production.
Versions of components are decoupled due to selective build mechanisms. Some will change little, some will change often. Now, how do you track the set of containers that make up your application? It makes sense to keep this build metadata in the version control system so that we can provide metadata for each build commit. But we don’t want to see the build pipeline contaminate Git history with human commits. This is where Gino Keva was born.
Use case – Store new component versions
Gino Keva is used to store a newly built version of any component as a key/value pair in git comments associated with its build commit: COMPONENT_foo=1.1.0.
Use case – Lists all component versions for a commit
For each deployment, the list of containers that make up the application is simply gathered from the output of the Gino-Keva List.
before | after |
---|---|
COMPONENT_foo = 1.0.0 | COMPONENT_foo=1.1.0 (updated) |
Component_bar = 1.2.3 | COMPONENT_BAR=1.2.3 (untouched) |
… . | … . |
requirements
- Git CLI: Gino Keva uses the Git CLI installed on the host. Use version 2.32.0 for testing, but any recent version will work.
How to use
See below for an example of how to use Gino-Keva, or run gino-keva –help for help.
Warning. Push your changes
By default, Gino-Keva does not push your changes upstream. You may wish to change this behavior by specifying –push, or by setting the environment variable GINO_KEVA_PUSH=1. If you don’t, subsequent searches will overwrite any local changes.
Set up key/value pairs
[email protected] (f10b970d):~$ gino-keva set key my_value
[email protected] (f10b970d):~$ gino-keva set counter 12
[email protected] (f10b970d):~$ gino-keva set foo bar
Copy the code
Lists all key/value pairs
[email protected] (f10b970d):~$ gino-keva list
counter=12
foo=bar
key=my_value
Copy the code
[email protected](f10b970d): git commit -allow-empty -m “Dummy commit”[\[email protected\]](https://golangexample.com/cdn-cgi/l/email-protection)(a8517558): $gino-keva set PI 3.14[email protected](a8517558):~$gino-keva list-output =json {“counter” :”12″, “foo”:”bar”, “Key” : “my_value”, “PI” : “3.14”}
### Unset keys Finally, you can unset keys using `unset`: ```console [email protected] (a8517558):~$ gino-keva unset foo [email protected] (a8517558):~$ gino-keva list counter=12 Key = my_value PI = 3.14Copy the code
Use custom notes reference
By default, notes are saved in refs/ Notes/Gino-keva, but this can be changed with the –ref command line switch. To store your key/value in refs/notes/banana:
[email protected] (a8517558):~
Copy the code
FAQ
Do I need additional Git configuration? How can I do this?
Since Gino Keva only uses git CLI, you can use the (mostly) options it provides to set/override configurations. You can use Git config to set up your system, or use environment variables for the same purpose.
Example. Add a key/value pair as “whatever <[email protected]>” user
GIT_CONFIG_COUNT=2 \
GIT_CONFIG_KEY_0="user.name" GIT_CONFIG_VALUE_0="whatever" \
GIT_CONFIG_KEY_1="user.email" GIT_CONFIG_VALUE_1="[email protected]" \
gino-keva set foo bar
Copy the code
I need a custom output format
Gino Keva supports only the simple key=value format (default) or JSON (–output= JSON). However, you can parse the output in any format you like.
Example. Use Gino-Keva as part of the GitHub action.
[email protected]:~$ gino-keva list | awk -F= '{print "::set-output name="$1"::"$2}' ::set-output name=COUNTER::12 : : the set - the output name = key: : my_value: : set - the output name = PI: : 3.14Copy the code
Example. Use Gino-Keva as part of the Azure Devops pipeline.
[email protected]:~$ gino-keva list | awk -F= '{print "##vso[task.setvariable variable="$1"]"$2}' ##vso[task.setvariable 1 ##vso[task.setVariable =key]my_value ##vso[task.setvariable =PI] 2 ##vso[task.setvariable =PICopy the code