Moves the deploy script off the server and into the repo as scripts/update-app.sh, with the two fixes made during the v1.114.0 deploy: - set -euo pipefail, so a failed git pull aborts instead of rebuilding and restarting PM2 on unchanged code while printing "Update Complete" - npm ci instead of npm install, which rewrote package-lock.json and left the tree dirty so the next git pull aborted The body is wrapped in a main() function because the script lives inside the checkout it updates, and git pull rewriting it mid-run would leave bash reading from a stale file offset. v1.114.1 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
48 lines
1.6 KiB
Bash
48 lines
1.6 KiB
Bash
#!/bin/bash
|
|
#
|
|
# Deploy script for the production host (WebApp-Testing-live).
|
|
#
|
|
# The app runs there as a PM2 process ("my-weekly-todo") from /root/My-Weekly-ToDo-List.
|
|
# It is NOT run under Docker — deploy.sh and docker-compose.yml in this repo describe an
|
|
# older Portainer setup that is not what serves todo.martin-bierschenk.de.
|
|
#
|
|
# Usage on the host: /root/My-Weekly-ToDo-List/scripts/update-app.sh
|
|
#
|
|
# The whole body is wrapped in a function so bash parses it in one go: this script lives
|
|
# inside the very checkout it updates, and `git pull` rewriting it mid-run would otherwise
|
|
# make bash resume at a stale file offset.
|
|
|
|
main() {
|
|
set -euo pipefail
|
|
|
|
# Fail fast instead of hanging on a credential prompt when run without a terminal
|
|
# (e.g. from systemd). The host authenticates via a read-only SSH deploy key.
|
|
export GIT_TERMINAL_PROMPT=0
|
|
|
|
local APP_DIR="/root/My-Weekly-ToDo-List"
|
|
local PM2_APP="my-weekly-todo"
|
|
|
|
cd "$APP_DIR"
|
|
|
|
echo "--- Pulling latest changes from git ---"
|
|
git pull origin main
|
|
|
|
# npm ci, not npm install: it installs exactly what package-lock.json specifies and
|
|
# never rewrites it. npm install rewrites the lockfile, which leaves the working tree
|
|
# dirty and makes the *next* git pull abort.
|
|
echo "--- Installing dependencies ---"
|
|
npm ci
|
|
|
|
echo "--- Building application ---"
|
|
npm run build
|
|
|
|
echo "--- Restarting PM2 process ---"
|
|
pm2 restart "$PM2_APP" --update-env
|
|
pm2 save
|
|
|
|
echo "--- Update Complete ---"
|
|
echo "Deployed version: $(node -p "require('$APP_DIR/package.json').version")"
|
|
}
|
|
|
|
main "$@"
|