#!/usr/bin/env bash # SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC # SPDX-License-Identifier: Apache-2.0 # Publish ./site to /srv/www/ as an atomic release (DEPLOY_ROOT overrides /srv/www). # # scripts/deploy.sh [host] # # Without a host, the script runs on the server itself (the Gitea runner lives # on the droplet). With a host (user@droplet), it rsyncs over SSH. Either way # the layout on the server is: # # /srv/www/ -> symlink to the live release # /srv/www/.releases/ one directory per deployed commit, last 5 kept # # The symlink swap is one rename, so visitors never see a half-copied site, and # rolling back is `ln -sfn /srv/www/.releases/ /srv/www/`. set -euo pipefail slug="${1:?usage: deploy.sh [user@host]}" host="${2:-}" sha="${GITHUB_SHA:-$(git rev-parse HEAD 2>/dev/null || date +%s)}" root="${DEPLOY_ROOT:-/srv/www}" releases="$root/$slug.releases" release="$releases/${sha:0:12}" live="$root/$slug" [ -f site/index.html ] || { echo "site/ is missing; run scripts/assemble.sh first" >&2; exit 1; } # Everything that touches the server, as one script, so the SSH path and the local path stay identical. remote_script=$(cat </dev/null | tail -n +6 | xargs -r rm -rf echo "live: $live -> \$(readlink "$live")" EOS ) if [ -z "$host" ]; then mkdir -p "$releases" rm -rf "$release.incoming" if command -v rsync >/dev/null; then rsync -a --delete site/ "$release.incoming/"; else cp -a site "$release.incoming"; fi bash -c "$remote_script" else ssh -o BatchMode=yes "$host" "mkdir -p '$releases'" rsync -a --delete -e "ssh -o BatchMode=yes" site/ "$host:$release.incoming/" ssh -o BatchMode=yes "$host" "$remote_script" fi