Add post-receive hook

This commit is contained in:
Daniel Meiburg 2023-02-12 22:22:49 +01:00
parent 23970fd8ff
commit d8c37ec73b
Signed by: dm
GPG Key ID: E5827ECFFE0AA4F2
2 changed files with 26 additions and 0 deletions

View File

@ -21,3 +21,5 @@ $ gpg -ear key@dmeiburg.de .env
git remote add dmeiburg ssh://root@dmeiburg.de:/root/git/container.git
git push dmeiburg
```
Make sure `post-receive` hook is installed in the bare repository.

24
post-receive Executable file
View File

@ -0,0 +1,24 @@
#!/bin/sh
#
# This hook updates the working repository on dmeiburg.de
# It is meant to update the docker configs of my servers.
WORK_TREE=~/container
# get changed folders
changed=`GIT_WORK_TREE=$WORK_TREE git diff --dirstat=files,0 HEAD | cut -f3 -d' '`
# update files in working direcotry
GIT_WORK_TREE=~/container git checkout -f
# restart changed docker compose stacks
for app in $changed; do
cd $WORK_TREE/$changed
# decrypt .env
[ -f .env.asc ] && gpg -d env.asc > .env
docker compose down
docker compose up -d
done
exit