diff options
Diffstat (limited to 'deploy/post-receive.sample')
| -rw-r--r-- | deploy/post-receive.sample | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/deploy/post-receive.sample b/deploy/post-receive.sample new file mode 100644 index 0000000..a259c2a --- /dev/null +++ b/deploy/post-receive.sample @@ -0,0 +1,29 @@ +#!/bin/sh +# Optional: auto-deploy when pushing to a bare repo on the host. +# +# The normal workflow is scripts/deploy.sh from the development machine; this +# hook is for the variant where the host also has the toolchain and a working +# checkout. Install as hooks/post-receive in the bare repo, make it +# executable, and set WORK_TREE to a checkout whose origin is that bare repo. +set -eu + +WORK_TREE="${WORK_TREE:-/srv/bokf/src}" +DEPLOY_DIR="${DEPLOY_DIR:-/srv/bokf}" +BRANCH="${BRANCH:-refs/heads/main}" + +while read -r _old _new ref; do + [ "$ref" = "$BRANCH" ] || continue + cd "$WORK_TREE" + git pull --ff-only + make -j"$(nproc)" + make test + tag="$(git describe --tags --always)" + docker build -t "bokf:$tag" . + cp compose.yaml "$DEPLOY_DIR/compose.yaml" + touch "$DEPLOY_DIR/.env" + sed -i '/^BOKF_IMAGE=/d;/^BOKF_TAG=/d' "$DEPLOY_DIR/.env" + printf 'BOKF_IMAGE=bokf\nBOKF_TAG=%s\n' "$tag" >> "$DEPLOY_DIR/.env" + cd "$DEPLOY_DIR" + docker compose up -d --no-build + docker compose ps +done |
