-
Notifications
You must be signed in to change notification settings - Fork 171
Description
Background
I'm trying to make the git revision used to build an image available to the application at runtime. In my setup, I have an Image resource that points to main and automatically kicks off new builds when it detects new commits. I've tried following, and neither worked.
paketo-buildpacks/git
Relies on the presence of the .git directory, which is not present in kpack builds.
Custom buildpack
I've looked at exported images and saw that they have labels with the revision
"io.buildpacks.project.metadata": "{\"source\":{\"type\":\"git\",\"version\":{\"commit\":\"49af4e6ac1cdcf366de46d80e0e844d005546f71\"},\"metadata\":{\"repository\":\"git@github.com:org/repo.git\",\"revision\":\"49af4e6ac1cdcf366de46d80e0e844d005546f71\"}}}"and thought that maybe kpack makes the project metadata available to buildpacks. Alas, I don't think it does, or at least I couldn't find where exactly this information is available.
Solutions I haven't tried
Changing from pull model to push
I could add a step to CI to update the Image resource with the revision, and at the same time set an env var for the Build. I don't want to do that because I really like the simplicity of the current pull model, which eliminates the possibility of weird race conditions (older commit could have a newer build number).
Mutating webhooks
When kpack creates the Build resources, it sets the concrete revision in its spec.Source.Git.Revision field. The webhook could read it from there and then inject it as an env var. However, that sounds a bit daunting to me and would require some non-trivial changes - far more than I expected for this kind of change.
My ask
Did anyone have to solve a similar issue, and how did you approach the problem?
Would it make sense to change kpack to simplify this? Either by making the project metadata file available to buildpacks, or by automatically setting env vars containing the metadata in the build (so that they could be used by something like https://github.com/paketo-buildpacks/environment-variables)?