summaryrefslogtreecommitdiff
path: root/deploy.sh
diff options
context:
space:
mode:
Diffstat (limited to 'deploy.sh')
-rwxr-xr-xdeploy.sh29
1 files changed, 24 insertions, 5 deletions
diff --git a/deploy.sh b/deploy.sh
index 51159fe..306f666 100755
--- a/deploy.sh
+++ b/deploy.sh
@@ -11,6 +11,7 @@ set -euo pipefail
# call must be pointed at $REPO explicitly.
REPO="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
SHA="$(git -C "$REPO" rev-parse --short HEAD)"
+DEPLOY_HOST="${DEPLOY_HOST:-jayrup.me}"
# 1. Render into a fresh temp dir so a partial build never gets deployed
BUILD_DIR="$(mktemp -d /tmp/homepage-local.XXXXXX)"
@@ -45,14 +46,32 @@ mkdir -p public/assets
cp -r assets/* public/
cp -r assets/* public/assets/
-# .txt twin: curl/wget UAs map to .txt, so `curl https://jayrup.me/public_key`
-# resolves to public_key.txt. Source of truth stays assets/public_key.
-cp assets/public_key public/public_key.txt
+# .txt twin for curl/wget: normalize to exactly one line ending in a newline,
+# so `curl https://jayrup.me/public_key >> ~/.ssh/authorized_keys` appends a
+# clean key instead of gluing itself onto the previous line.
+KEY="$(tr -d '\r' < assets/public_key | sed -e 's/[[:space:]]*$//' | tr -d '\n')"
+[ -n "$KEY" ] || { echo "assets/public_key is empty" >&2; exit 1; }
+printf '%s\n' "$KEY" > public/public_key.txt
# 6. Deploy marker
printf 'deployed %s commit %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$SHA" > public/last-deploy.txt
echo "Pushing to vps"
-# Only reached if all renders succeeded (set -e)
-rsync -avz --delete public/ jayrup.me:~/homepage/public/
+# 7. Content. Only reached if all renders succeeded (set -e)
+rsync -avz --delete public/ "$DEPLOY_HOST":~/homepage/public/
+
+# 8. nginx config. It is bind-mounted into the container, so it does not travel
+# with public/. Test it before reloading: a bad file must not take down the
+# running workers, so restore the previous one and fail loudly instead.
+echo "Pushing nginx.conf"
+ssh "$DEPLOY_HOST" 'cp -a ~/homepage/nginx.conf ~/homepage/nginx.conf.prev'
+rsync -avz nginx.conf "$DEPLOY_HOST":~/homepage/nginx.conf
+if ssh "$DEPLOY_HOST" 'docker exec homepage nginx -t'; then
+ ssh "$DEPLOY_HOST" 'docker exec homepage nginx -s reload'
+ echo "nginx reloaded"
+else
+ echo "!! nginx config failed its test - restoring previous config" >&2
+ ssh "$DEPLOY_HOST" 'mv ~/homepage/nginx.conf.prev ~/homepage/nginx.conf'
+ exit 1
+fi