| 1 | #!/bin/bash
|
|---|
| 2 | # PrutFolio deploy-hook — werkt zoals logboek-hook.
|
|---|
| 3 | # Bare repo is single source of truth.
|
|---|
| 4 | # /srv/prutfolio is de working tree — gevuld via "git --work-tree=..."
|
|---|
| 5 | # (geen .git submap erin), zelfde patroon als logboek->celine.
|
|---|
| 6 | set -e
|
|---|
| 7 |
|
|---|
| 8 | DEPLOY=/srv/prutfolio
|
|---|
| 9 | GIT_DIR=/home/roboburr/git-repos/prutfolio.git
|
|---|
| 10 |
|
|---|
| 11 | while read oldrev newrev refname ; do
|
|---|
| 12 | [ "$refname" != "refs/heads/main" ] && continue
|
|---|
| 13 |
|
|---|
| 14 | echo ">>> Deploying $newrev to $DEPLOY"
|
|---|
| 15 |
|
|---|
| 16 | # 1. Heel zelden — als een eerdere bug git-internals los in $DEPLOY
|
|---|
| 17 | # heeft gedumpt (HEAD/objects/refs op root), eenmalig opruimen
|
|---|
| 18 | # zodat dit een echte working tree wordt.
|
|---|
| 19 | if [ -f "$DEPLOY/HEAD" ] && [ -d "$DEPLOY/objects" ] && [ ! -d "$DEPLOY/.git" ]; then
|
|---|
| 20 | echo " cleanup: stale bare-init artifacts in $DEPLOY"
|
|---|
| 21 | for f in branches config description FETCH_HEAD HEAD hooks info objects refs ORIG_HEAD; do
|
|---|
| 22 | rm -rf "$DEPLOY/$f" 2>/dev/null || true
|
|---|
| 23 | done
|
|---|
| 24 | fi
|
|---|
| 25 |
|
|---|
| 26 | # 2. Force-checkout van bare-repo state naar working tree.
|
|---|
| 27 | git --git-dir="$GIT_DIR" --work-tree="$DEPLOY" checkout -f main
|
|---|
| 28 |
|
|---|
| 29 | # 3. npm install alleen als package-lock.json wijzigde.
|
|---|
| 30 | if [ -n "$oldrev" ] && [ "$oldrev" != "0000000000000000000000000000000000000000" ]; then
|
|---|
| 31 | if git --git-dir="$GIT_DIR" diff --name-only "$oldrev" "$newrev" | grep -q "^package-lock.json$"; then
|
|---|
| 32 | echo ">>> package-lock.json changed — npm ci --production"
|
|---|
| 33 | cd "$DEPLOY" && npm ci --production
|
|---|
| 34 | fi
|
|---|
| 35 | fi
|
|---|
| 36 |
|
|---|
| 37 | # 4. pm2 reload — process is named "klonkt"
|
|---|
| 38 | pm2 reload klonkt 2>/dev/null || true
|
|---|
| 39 |
|
|---|
| 40 | echo ">>> Done. App-files in $DEPLOY ongemoeid (.env, node_modules, storage)."
|
|---|
| 41 | done
|
|---|