Previously we relied upon GO_LDFLAGS to be passed in to get information such as the branch, revision, and version information. Another pattern we can follow is to use the existing make build-binary command which as all of the scripting defined for the necessary variables to build up the GO_LDFLAGS. In order to support this, we need git and make installed, which thankfully come bundled with the regular golang image.
Updates VERSION to be git describe --tags --dirty --always which will use the the tag information from git directly. The neat this about this command is that if you're on a branch that isn't tagged, it'll return the latest tag and append an abbreviation of the current commit which will guarantee uniqueness between branches. This will support us making "dirty" releases on main, and then when we create a new tags, we'll have an image created with that specific tag.
To test out, I've built locally with a tag poko-test-local:
When running the image locally, you'll note the version gets propogated:
docker run docker.io/grafana/cloudcost-exporter:dev-poko-test-local ~/dev/grafana/cloudcost-exporter
2024/05/01 17:57:33 Version (version=dev-poko-test-local, branch=ci/update-build-binary-to-use-make, revision=a7db1f2)
Previously we relied upon
GO_LDFLAGS
to be passed in to get information such as the branch, revision, and version information. Another pattern we can follow is to use the existingmake build-binary
command which as all of the scripting defined for the necessary variables to build up theGO_LDFLAGS
. In order to support this, we needgit
andmake
installed, which thankfully come bundled with the regular golang image.Updates
VERSION
to begit describe --tags --dirty --always
which will use the the tag information from git directly. The neat this about this command is that if you're on a branch that isn't tagged, it'll return the latest tag and append an abbreviation of the current commit which will guarantee uniqueness between branches. This will support us making "dirty" releases on main, and then when we create a new tags, we'll have an image created with that specific tag.To test out, I've built locally with a tag
poko-test-local
:When running the image locally, you'll note the version gets propogated: