diff options
| author | Adam Soltys <[email protected]> | 2026-10-16 12:58:17 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-10-16 12:58:17 -0700 |
| commit | 2fe542686dde91f424ecb019c2886e467e9aebd8 (patch) | |
| tree | 3b5931450301779a31c98935ff03b67de38a0d85 /deploy | |
| parent | a3d2dc2e05a4f7c5ab0d6e7689498da9ca63de7b (diff) | |
| download | coinosv3-server-2fe542686dde91f424ecb019c2886e467e9aebd8.tar.gz coinosv3-server-2fe542686dde91f424ecb019c2886e467e9aebd8.zip | |
README, example config and the deploy hook
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'deploy')
| -rwxr-xr-x | deploy/post-receive | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/deploy/post-receive b/deploy/post-receive new file mode 100755 index 0000000..78e4ba2 --- /dev/null +++ b/deploy/post-receive @@ -0,0 +1,61 @@ +#!/bin/sh +# Deploy hook for cs:~/coinosv3-server.git. Install it as hooks/post-receive. +# +# A push to `prod` checks the commit out to $CHECKOUT, installs dependencies, +# restarts the services whose files changed, then mirrors the commit to +# git.coinos.io and gittr. What runs is always a commit: never copy files +# into the checkout by hand. +set -u +CHECKOUT=/home/adam/coinosv3-server +LOG=/home/adam/coinosv3-server-deploy.log +MIRROR=/home/adam/git/coinosv3-server.git [email protected]:npub1w27mc4aa6m0ufe3xs5z3m6qyr52gc0rglept7vqlwx4xeaf72tasnqz70r/coinosv3-server.git +BARE=$(pwd) +SERVICES="names nwcpush blossom" + +while read -r oldrev newrev ref; do + [ "$ref" = refs/heads/prod ] || continue + { + echo "== $(date -u +%FT%TZ) deploy $newrev" + mkdir -p "$CHECKOUT" + git --git-dir="$BARE" --work-tree="$CHECKOUT" checkout -f "$newrev" || { echo "checkout failed"; exit 1; } + cd "$CHECKOUT" || exit 1 + # the pinned coinosv3 commit comes from the coinosv3 repo on this host + env -u GIT_DIR git -C "$CHECKOUT" --git-dir="$BARE" --work-tree="$CHECKOUT" \ + -c submodule.coinosv3.url=/home/adam/coinosv3.git -c protocol.file.allow=always \ + submodule update --init --force || { echo "submodule update failed"; exit 1; } + docker run --rm -v "$CHECKOUT":/app -w /app oven/bun:1.3.14 bun install --frozen-lockfile --production \ + || { echo "bun install failed"; exit 1; } + + # which services to restart: their own directory changed, or something + # they all share did (the pin, dependencies, compose); everything on a + # first deploy + if [ "$oldrev" = 0000000000000000000000000000000000000000 ]; then + restart=$SERVICES + else + changed=$(git --git-dir="$BARE" diff --name-only "$oldrev" "$newrev") + if echo "$changed" | grep -qE '^(coinosv3|package\.json|bun\.lock|compose\.yml)$'; then + restart=$SERVICES + else + restart="" + for s in $SERVICES; do echo "$changed" | grep -q "^$s/" && restart="$restart $s"; done + # names imports bridge/ln.js + echo "$changed" | grep -q '^bridge/ln\.js$' && case "$restart" in *names*) ;; *) restart="$restart names";; esac + fi + fi + if [ -n "$restart" ]; then + echo "restarting:$restart" + docker compose -f "$CHECKOUT/compose.yml" --env-file /home/adam/coinosv3-state/.env up -d --force-recreate $restart \ + || echo "compose up failed" + else + echo "no service files changed" + fi + + # mirrors; a failure here never fails the deploy + git --git-dir="$BARE" push --quiet "$MIRROR" "$newrev:refs/heads/master" "refs/tags/*:refs/tags/*" \ + || echo "mirror push to git.coinos.io failed" + GIT_SSH_COMMAND="ssh -i /home/adam/.ssh/gittr_ed25519 -o IdentitiesOnly=yes -o BatchMode=yes -o ConnectTimeout=15" \ + timeout 120 git --git-dir="$BARE" push --quiet "$GITTR" "$newrev:refs/heads/master" "refs/tags/*:refs/tags/*" \ + || echo "mirror push to gittr failed" + } >> "$LOG" 2>&1 +done |
