interplane.Get Omega
Read in your language

aien-edge

aien-dev/aien-edge

Brought by drakestapleton

branch main Branches Tags History

aien-edge / deploy / publish-site.sh

35 lines · 1310 bytes Raw Blame History
1#!/usr/bin/env bash
2# Build a site on the Spark and publish it to the edge host, then hot-reload.
3#
4# deploy/publish-site.sh aienos.com ~/workspace/aienos.com
5# deploy/publish-site.sh drakestapleton.com ~/workspace/drakestapleton.com
6#
7# EDGE_HOST (ssh target of the edge host) comes from the environment or from
8# deploy/publish.env (local-only, git-ignored; see deploy/publish.env.example).
9set -euo pipefail
10
11here="$(cd "$(dirname "$0")" && pwd)"
12if [ -z "${EDGE_HOST:-}" ] && [ -f "$here/publish.env" ]; then
13 . "$here/publish.env"
14fi
15
16name="${1:?site name, for example aienos.com}"
17src="${2:?path to the site checkout}"
18edge="${EDGE_HOST:?set EDGE_HOST or create deploy/publish.env}"
19
20cd "$src"
21npm ci --no-audit --no-fund
22npm run build
23
24# Upload into a fresh release directory, then repoint the /srv/sites/<name>
25# symlink atomically so visitors never see a half-copied site. The server holds
26# every file in memory, so it keeps serving the old copy until the reload.
27stamp="$(date -u +%Y%m%dT%H%M%SZ)"
28rsync -a --delete dist/ "$edge:/srv/sites/releases/$name-$stamp/"
29ssh "$edge" "set -e
30 cd /srv/sites
31 ln -sfn releases/$name-$stamp .next-$name
32 mv -T .next-$name $name
33 sudo systemctl reload aien-edge
34 ls -1d releases/$name-* | head -n -3 | xargs -r rm -rf"
35echo "published $name ($stamp)"