summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdeploy-docker.sh62
-rwxr-xr-xhooks/post-receive44
2 files changed, 106 insertions, 0 deletions
diff --git a/deploy-docker.sh b/deploy-docker.sh
new file mode 100755
index 0000000..0c4c3b7
--- /dev/null
+++ b/deploy-docker.sh
@@ -0,0 +1,62 @@
+#!/usr/bin/env bash
+# deploy-docker.sh — build + deploy jayrup.me. Versioned in the repo so the
+# post-receive hook always uses the deploy logic that matches the pushed tree.
+#
+# Designed to run ON MERU (docker-only machine) from a git archive snapshot:
+# git archive HEAD | tar -x -C /tmp/build && bash /tmp/build/deploy-docker.sh /tmp/build <sha>
+# Quarto runs inside the official quarto/quarto container; rsync ships
+# public/ to nandi (jayrup.me).
+#
+# Usage: deploy-docker.sh <build-dir> <short-sha>
+set -euo pipefail
+
+BUILD_DIR="${1:?usage: deploy-docker.sh <build-dir> <short-sha>}"
+SHORT_SHA="${2:?missing short sha}"
+cd "$BUILD_DIR"
+
+QUARTO_IMAGE="${QUARTO_IMAGE:-quarto/quarto:latest}"
+# Fallback if meru can't reach jayrup.me (IPv6): DEPLOY_HOST=jayrup@100.94.131.98
+DEPLOY_HOST="${DEPLOY_HOST:-jayrup.me}"
+RUN_UID="$(id -u)"
+RUN_GID="$(id -g)"
+
+# Render script runs INSIDE the container (one container spin, both passes).
+# HOME=/tmp so quarto's cache is writable by the unprivileged uid.
+cat > /tmp/homepage-render.sh <<'RENDER_EOF'
+#!/usr/bin/env bash
+set -euo pipefail
+cd /site
+rm -rf public
+quarto render --to html
+find . -name "*.qmd" -not -path "./.*" -not -path "./public/*" | while read -r file; do
+ rel_dir=$(dirname "${file#./}")
+ base_name=$(basename "$file" .qmd)
+ quarto render "$file" --to plain --output "${base_name}.txt" --output-dir "public/$rel_dir"
+done
+RENDER_EOF
+chmod +x /tmp/homepage-render.sh
+
+echo ">> rendering with $QUARTO_IMAGE (commit $SHORT_SHA)"
+# --entrypoint /bin/bash overrides whatever entrypoint the image declares
+docker run --rm \
+ --entrypoint /bin/bash \
+ -u "$RUN_UID:$RUN_GID" \
+ -e HOME=/tmp \
+ -v "$BUILD_DIR":/site \
+ -v /tmp/homepage-render.sh:/render.sh:ro \
+ -w /site \
+ "$QUARTO_IMAGE" /render.sh
+
+# Static assets bundled in the repo
+mkdir -p public/cv
+cp cv/index.pdf public/cv.pdf
+cp cv/index.txt public/cv.txt
+cp assets/dissertation.pdf public/dissertation.pdf
+cp assets/public_key public/public_key
+
+# Deploy status marker — site-visible proof of the last successful deploy
+printf 'deployed %s commit %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$SHORT_SHA" > public/last-deploy.txt
+
+echo ">> pushing to $DEPLOY_HOST"
+rsync -avz --delete public/ "$DEPLOY_HOST":~/homepage/public/
+echo ">> deploy OK ($SHORT_SHA)"
diff --git a/hooks/post-receive b/hooks/post-receive
new file mode 100755
index 0000000..378e777
--- /dev/null
+++ b/hooks/post-receive
@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+# post-receive hook for meru's homepage.git bare repo.
+# Deploys jayrup.me on every push to main, using the pushed deploy-docker.sh.
+#
+# Install on meru (one-time):
+# cp hooks/post-receive ~/projects/homepage.git/hooks/post-receive
+# chmod +x ~/projects/homepage.git/hooks/post-receive
+# Also authorize meru's SSH key on nandi (jayrup@jayrup.me ~/.ssh/authorized_keys).
+#
+# Log: /tmp/homepage-deploy.log — also echoed to the pusher (tee).
+set -uo pipefail
+
+# Serialize concurrent pushes (flock from util-linux)
+exec 9>/tmp/homepage-deploy.lock
+flock 9
+
+LOG=/tmp/homepage-deploy.log
+exec > >(tee -a "$LOG") 2>&1
+echo "=== post-receive $(date -u +%Y-%m-%dT%H:%M:%SZ) ==="
+
+BARE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
+BUILD_DIR="/tmp/homepage-build"
+rm -rf "$BUILD_DIR"
+mkdir -p "$BUILD_DIR"
+
+DEPLOYED=0
+while read oldrev newrev ref; do
+ case "$ref" in
+ refs/heads/main)
+ OLD_SHA="$(git --git-dir="$BARE_DIR" rev-parse --short "$oldrev")"
+ NEW_SHA="$(git --git-dir="$BARE_DIR" rev-parse --short "$newrev")"
+ echo ">> push to main: $OLD_SHA..$NEW_SHA"
+ # Snapshot the pushed tree (no .git, exact commit)
+ git --git-dir="$BARE_DIR" archive "$newrev" | tar -x -C "$BUILD_DIR"
+ bash "$BUILD_DIR/deploy-docker.sh" "$BUILD_DIR" "$NEW_SHA"
+ DEPLOYED=1
+ ;;
+ *)
+ echo ">> skipped $ref (only refs/heads/main deploys)"
+ ;;
+ esac
+done
+
+[ "$DEPLOYED" -eq 1 ] && echo "=== hook done OK ===" || echo "=== nothing deployed ==="