container/post-receive

30 lines
754 B
Bash
Executable File

#!/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 | awk '{print $NF}' `
[ -n "$changed" ] && echo -e "Changed apps:\n$changed"
# 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
echo -e "\nUpdate $app"
# remove old .env if no .env.gpg is supplied
[ -f .env ] && [ -f .env.gpg ] || rm .env
# decrypt .env.gpg
[ -f .env.gpg ] && gpg --quiet -d .env.gpg > .env
docker compose down | uniq
docker compose up --quiet-pull -d | uniq
done
exit