2 minutes
git tag push
How to git tag and push your code at the same time.
I have mentioned before that I use containers frequently, but I guess most us of do now.
Right now I am mostly working with:
- Cloud Run: Learn the basics of Python and Cloud Run.
- Cloud Build: Learn more about Cloud Build and Cloud Run together.
- Cloud Scheduler: You can trigger Cloud Run in many ways, for example with manual HTTPS, gRPC, Pub/Sub, etc. I do use Cloud Scheduler often too, and it could work for your purposes.
To trigger a container build and deployment, I use a git tag (conforming to a defined regex pattern) in Cloud Build. Here’s how I tag and push at the same time:
- Add or stage your files. Yes add and stage are the same.
$ git add --all
- Commit your code:
git commit -m "<Your informative message goes here>"
$ git commit -m "Your informative message goes here"
[main d928fa7] Your informative message goes here
1 file changed, 5 insertions(+), 1 deletion(-)
Note the commit checksum (d928fa7) after the branch (main):
[main d928fa7]
Use that checksum in the next command.
- Create a tag that matches your build trigger:
git tag <your tag> <commit checksum>
$ git tag v0.1.27 d928fa7
- Push it like it’s hot. Note the
--atomic
flag, see more:git push --atomic origin <branch name> <tag>
$ git push --atomic origin main v0.1.27
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 443 bytes | 443.00 KiB/s, done.
Total 4 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
To github.com:owner/repo.git
fd7e62a..d928fa7 main -> main
* [new tag] v0.1.27 -> v0.1.27
Done. Your code and tag pushed at the same time. Neat, huh?