1

I would like my micro-services application to respond with the code version of it at runtime. To get that going I would embed a version number in an untracked file, and each micro-service would serve that number when responding to a certain api call.

The version number would be written to the untracked file by a commit script.

Would using git log --oneline | wc -l be a reliable way of auto-generating an incremental version number for every git commit? (other reliable alternatives very welcome...)

My requirement is that each commit would generate a version number higher than all previous ones.. the other requirement is that this is not dependant on any CI server, but rather each developer commit would take care of this (so that this works even before there is a CI server).

What would be the git tinkerings commonly performed by developers, that would undermine this scheme?

3 Answers 3

2

For scripting purposes don't use git log and other porcelain commands. In this case, git rev-list --count HEAD yields the same results using plumbing commands.

Anyway, this sounds like an excellent task for git describe. If you use tags it'll report the closest tag and how far ahead the current commit is. It also includes the SHA-1 of the commit so the version isn't ambiguous like a pure commit count metric is.

Sign up to request clarification or add additional context in comments.

3 Comments

Well git describe and tags assume too much of a manual versioning process, whereas I'm looking at a more agile environment of micro-services where there is no reliance on manual tagging... but the rev-list command looks great!
of course, this versioning scheme will fail if a dev e.g. rolled back a commit, as it won't roll back the output file... and on the other hand, it would be circular to version control that file. This scheme would also fail when branching enters the picture. One idea I can think of, is to version control the version file after all, and then the version number is always determined by the previous run of the same proposed commit script, but is still fulfilling the requirement of an incremental version number. The pitfall: merges.
In summary, maybe it's better to only use the git hashes after all - which are sort of a version management managed by git with somewhat less opportunity for tampering...
1

Alternative partial solution for micro-services environment:

The api that sends back the version of a micro-service would take the commit hash (written to a file by the commit script), and derive an incremental version number (e.g. fetch the repo and run git rev-list --count {hash}, then return that number to the caller. And this would still fail to mean anything if branches were being deployed.

Comments

1

Other alternative solution for micro-services environment:

Version numbers will be managed outside git, as git isn't cut for that. Upon deployment, the deploy tool would register the git hash and obtain a unique incremented version number for it, from my own versioning micro-service (which would use a very simple database or file for that). This lean versioning micro-service will drive checking the version of a micro-service as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.