Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container images: show git commit hash in --version output when built on GitHub Actions #260

Merged
merged 2 commits into from
Jul 25, 2024

Conversation

julianbrost
Copy link
Collaborator

By default, BuildKit checks out the git repository but does not include the .git directory in the build context. This then prevents go build from embedding the commit hash into the binary which we want to include in the --version output. This behavior can be changed by setting a build argument and fixes our --version output.

This also implies that the use of actions/checkout was actually redundant and I've removed it in a separate commit.

The changes to the Dockerfile (b7281ce) are intended to demonstrate that this actually fixes the issue. After an initial review, I'd remove that commit, wait for a final approval and then merge it.

fixes #257

docker/build-push-action actually does not use the local checkout but instead
simply passes the repo URL to BuildKit which then checks out the repo itself.
Thus, that call of actions/checkout is unnecessary and is removed.
By default, BuildKit checks out the git repository but does not include the
.git directory in the build context. This then prevents go build from embedding
the commit hash into the binary which we want to include in the --version
output. This behavior can be changed by setting a build argument and fixes our
--version output.
@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label Jul 25, 2024
@julianbrost
Copy link
Collaborator Author

The current job output for this PR shows that the git commit hash is now included:

#23 [linux/amd64 stage-1 6/6] RUN /usr/sbin/icinga-notifications --version
#23 0.064 Icinga Notifications version: 0.1.0-gecd2ffd
#23 0.064 
#23 0.064 Build information:
#23 0.064   Go version: go1.22.5 (linux, amd64)
#23 0.064   Git commit: ecd2ffda5996d279045a1c4e673781cd7c022202
#23 0.064 
#23 0.064 System information:
#23 0.064   Platform: Alpine Linux
#23 0.064   Platform version: 3.20.2
#23 DONE 0.1s

@julianbrost julianbrost marked this pull request as ready for review July 25, 2024 10:10
@yhabteab yhabteab added the bug Something isn't working label Jul 25, 2024
@julianbrost julianbrost merged commit 8102c77 into main Jul 25, 2024
26 checks passed
@julianbrost julianbrost deleted the container-commit-hash branch July 25, 2024 11:32
@julianbrost
Copy link
Collaborator Author

Verified to be fixed in the version now on Docker Hub:

$ docker pull icinga/icinga-notifications:main
main: Pulling from icinga/icinga-notifications
c6a83fedfae6: Already exists 
89b1561333ae: Pull complete 
177053750f25: Pull complete 
f342dffd92c5: Pull complete 
e6689d797880: Pull complete 
Digest: sha256:17450231efc68e5862dbd73d3e415b32c7c9f74272d1fb1affeb14d3dffd4efe
Status: Downloaded newer image for icinga/icinga-notifications:main
docker.io/icinga/icinga-notifications:main
$ docker run --rm -it icinga/icinga-notifications:main icinga-notifications --version
Icinga Notifications version: 0.1.0-g8102c77

Build information:
  Go version: go1.22.5 (linux, amd64)
  Git commit: 8102c7797364a1f184526a19083220fa7d7a46c9

System information:
  Platform: Alpine Linux
  Platform version: 3.20.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cla/signed CLA is signed by all contributors of a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Container images missing git commit hash in --version output
2 participants