Skip to main content

Lab 004: Git Hook

Requirements

The Nautilus application development team was working on a git repository /opt/apps.git which is cloned under /usr/src/kodekloudrepos directory present on Storage server in Stratos DC. The team want to setup a hook on this repository, please find below more details:

  • Merge the feature branch into the master branch`, but before pushing your changes complete below point.

  • Create a post-update hook in this git repository so that whenever any changes are pushed to the master branch, it creates a release tag with name release-2023-06-15, where 2023-06-15 is supposed to be the current date. For example if today is 20th June, 2023 then the release tag must be release-2023-06-20. Make sure you test the hook at least once and create a release tag for today's release.

  • Finally remember to push your changes.


Steps

At the jumphost terminal, SSH to the storage server. Replace the '*******' with the user's password and turn to superuser.

sshpass -p '*******' ssh -o StrictHostKeyChecking=no natasha@172.16.238.15
sudo su
cd /usr/src/kodekloudrepos/media/
git checkout master
git merge feature
touch /opt/media.git/hooks/post-update
chmod +x /opt/media.git/hooks/post-update
vi /opt/media.git/hooks/post-update

Enter the below contents inside the hooks/post-update file and save it

#!/bin/bash
cd /opt/media.git
git_tag=release-$(date "+%Y-%m-%d")
git tag $git_tag
git push
git status
git log