shivas / versioning-bundle

Simple way to version (semantic versioning 2.0.0) your Symfony2/3/4/5/6 application
MIT License
111 stars 30 forks source link

Using the bundle with Docker #83

Closed algorun77 closed 2 years ago

algorun77 commented 2 years ago

Hello,

I got tired of setting my app version manually constantly and I ran across this bundle that would perfectly match my needs.

But after a successful installation, I noticed than the version wasn't updated any more, and my guess is that the InitialVersionProvider was used.

I'd like to use the GtiRepositoryProvider to query the tags and display the latest. But I realized that it's gonna be a bit complex since my project is inside a Docker container, meaning that my application has no way to know about Git, right?

So my question is, what would be the best approach to let my app know about those tags? I was thinking of using a Git hook (post-update maybe?) to write a specific file (which would be gitignored). Is it a good way to achieve what I want or should I use something else?

Thanks a lot

dontub commented 2 years ago

You could dump the version into a file named VERSION and use the VersionProvider when GitRepositoryProvider is not possible.

It's surely possible to write the file at different steps. What about doing it when building the container?

algorun77 commented 2 years ago

Yes, I fallback to using the VersionProvider with the VERSION file. So, what I did was pretty simple. Since my version is based on my tags, I just added a post-merge hook to my .git/hooks folder and inside, there's a simple script that fetch the latest tag and write it to the VERSION file which is inside my container, so accessible by Symfony and Shivas bundle.

If anyone is interested, the script is just :

#!/bin/sh

tag=$(git describe --tags --abbrev=0)
echo "$tag" > "symfony/VERSION"

Dont' forget to make the hook executable on Linux, and then, each time I do a git pull on my server, it will automatically update the VERSION file. I just need to do a cache:clearand voilà !

Thanks for your help 😄