Simplify deploy.sh to run in place on the server
Removes local/prod cases — script now just does git pull, writes BUILD, and runs migrate wherever it's executed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e8e4476a58
commit
e1f7fb14fc
2 changed files with 20 additions and 67 deletions
|
|
@ -110,12 +110,11 @@ Tables in play (beyond core `users`/`projects`/`scan_paths`/`settings`):
|
||||||
| Target | Command | What it does |
|
| Target | Command | What it does |
|
||||||
|---------|--------------------------|--------------|
|
|---------|--------------------------|--------------|
|
||||||
| local | `sudo ./deploylocal.sh` | rsync to `/var/www/hackmancms`, chown www-data, migrate, reload Apache (port 8082) |
|
| local | `sudo ./deploylocal.sh` | rsync to `/var/www/hackmancms`, chown www-data, migrate, reload Apache (port 8082) |
|
||||||
| local (minimal) | `./bin/deploy.sh local` | rsync to `/var/www/hackmancms`, migrate (no chown/reload) |
|
| server | `./bin/deploy.sh` | git pull, write BUILD, migrate — run directly on the server |
|
||||||
| prod | `./bin/deploy.sh prod` | SSH git pull + migrate on `bashy@37.205.12.57:/opt/hackmancms` |
|
|
||||||
|
|
||||||
`deploylocal.sh` is the one to use day-to-day on bashyMint — it sets www-data ownership
|
`deploylocal.sh` is the one to use day-to-day on bashyMint — it sets www-data ownership
|
||||||
so the schedules cron and npm/git child processes can write to project paths and to
|
so the schedules cron and npm/git child processes can write to project paths and to
|
||||||
`data/hackmancms.sqlite`. Plain `./bin/deploy.sh local` exists for parity with prod.
|
`data/hackmancms.sqlite`.
|
||||||
|
|
||||||
On the server: Apache doc root = `/opt/hackmancms/web`. SQLite at `/opt/hackmancms/data/hackmancms.sqlite`.
|
On the server: Apache doc root = `/opt/hackmancms/web`. SQLite at `/opt/hackmancms/data/hackmancms.sqlite`.
|
||||||
Web server process needs write access to `/opt/hackmancms/data/`.
|
Web server process needs write access to `/opt/hackmancms/data/`.
|
||||||
|
|
|
||||||
|
|
@ -1,75 +1,29 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
TARGET="${1:-local}"
|
|
||||||
REPO="$(cd "$(dirname "$0")/.." && pwd)"
|
REPO="$(cd "$(dirname "$0")/.." && pwd)"
|
||||||
|
|
||||||
write_build_file() {
|
echo "→ deploy $REPO"
|
||||||
# $1 = repo dir, $2 = web dir
|
git -C "$REPO" pull --ff-only
|
||||||
local repo="$1" webdir="$2"
|
|
||||||
local vmm vbump bnum version sha branch built
|
vmm=$(tr -d '[:space:]' < "$REPO/VERSION" 2>/dev/null || echo '0.0')
|
||||||
vmm=$(tr -d '[:space:]' < "$repo/VERSION" 2>/dev/null || echo '0.0')
|
vbump=$(git -C "$REPO" log -1 --format=%H -- VERSION 2>/dev/null || echo '')
|
||||||
vbump=$(git -C "$repo" log -1 --format=%H -- VERSION 2>/dev/null || echo '')
|
|
||||||
if [ -n "$vbump" ]; then
|
if [ -n "$vbump" ]; then
|
||||||
bnum=$(git -C "$repo" rev-list --count "${vbump}..HEAD" 2>/dev/null || echo '0')
|
bnum=$(git -C "$REPO" rev-list --count "${vbump}..HEAD" 2>/dev/null || echo '0')
|
||||||
else
|
else
|
||||||
bnum=$(git -C "$repo" rev-list --count HEAD 2>/dev/null || echo '0')
|
bnum=$(git -C "$REPO" rev-list --count HEAD 2>/dev/null || echo '0')
|
||||||
fi
|
fi
|
||||||
version="${vmm}.${bnum}"
|
version="${vmm}.${bnum}"
|
||||||
sha=$(git -C "$repo" rev-parse --short HEAD 2>/dev/null || echo 'unknown')
|
sha=$(git -C "$REPO" rev-parse --short HEAD 2>/dev/null || echo 'unknown')
|
||||||
branch=$(git -C "$repo" rev-parse --abbrev-ref HEAD 2>/dev/null || echo 'unknown')
|
branch=$(git -C "$REPO" rev-parse --abbrev-ref HEAD 2>/dev/null || echo 'unknown')
|
||||||
built=$(date '+%Y-%m-%d %H:%M:%S')
|
built=$(date '+%Y-%m-%d %H:%M:%S')
|
||||||
cat > "$webdir/BUILD" <<BUILD
|
cat > "$REPO/web/BUILD" <<BUILD
|
||||||
version=$version
|
version=$version
|
||||||
sha=$sha
|
sha=$sha
|
||||||
branch=$branch
|
branch=$branch
|
||||||
built=$built
|
built=$built
|
||||||
BUILD
|
BUILD
|
||||||
echo " ✓ BUILD: v$version · $sha · $built"
|
echo " ✓ BUILD: v$version · $sha · $built"
|
||||||
}
|
|
||||||
|
|
||||||
case "$TARGET" in
|
php "$REPO/bin/migrate.php"
|
||||||
local)
|
|
||||||
DEST="/var/www/hackmancms"
|
|
||||||
echo "→ local deploy to $DEST"
|
|
||||||
sudo mkdir -p "$DEST"
|
|
||||||
sudo rsync -av --delete \
|
|
||||||
--exclude='.git' \
|
|
||||||
--exclude='data/' \
|
|
||||||
--exclude='config/config.local.php' \
|
|
||||||
--exclude='web/BUILD' \
|
|
||||||
"$REPO/" "$DEST/"
|
|
||||||
write_build_file "$REPO" "$DEST/web"
|
|
||||||
sudo php "$DEST/bin/migrate.php"
|
|
||||||
echo "→ done"
|
echo "→ done"
|
||||||
;;
|
|
||||||
|
|
||||||
prod)
|
|
||||||
# Code lives at /opt/hackmancms on the server; Apache root = /opt/hackmancms/web
|
|
||||||
echo "→ prod deploy"
|
|
||||||
ssh bashy@37.205.12.57 'set -e
|
|
||||||
cd /opt/hackmancms
|
|
||||||
git pull --ff-only
|
|
||||||
VMM=$(tr -d "[:space:]" < VERSION 2>/dev/null || echo "0.0")
|
|
||||||
VBUMP=$(git log -1 --format=%H -- VERSION 2>/dev/null || echo "")
|
|
||||||
if [ -n "$VBUMP" ]; then
|
|
||||||
BNUM=$(git rev-list --count "${VBUMP}..HEAD" 2>/dev/null || echo "0")
|
|
||||||
else
|
|
||||||
BNUM=$(git rev-list --count HEAD 2>/dev/null || echo "0")
|
|
||||||
fi
|
|
||||||
VERSION="${VMM}.${BNUM}"
|
|
||||||
SHA=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
|
|
||||||
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
|
|
||||||
BUILT=$(date "+%Y-%m-%d %H:%M:%S")
|
|
||||||
printf "version=%s\nsha=%s\nbranch=%s\nbuilt=%s\n" "$VERSION" "$SHA" "$BRANCH" "$BUILT" > web/BUILD
|
|
||||||
echo " BUILD: v$VERSION · $SHA · $BUILT"
|
|
||||||
php bin/migrate.php
|
|
||||||
'
|
|
||||||
echo "→ done"
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
echo "Usage: $0 [local|prod]"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue