profileShare

rasmusjy / profileshare

Read-only snapshot

No repository description.

main default branch 54 files Expires Sep 13, 2026, 9:06 AM
deploy.sh 2,402 bytes
1 #!/usr/bin/env bash
2 # One-command redeploy for code.rasmusj.com.
3 #
4 # Ships the source to the VPS, rebuilds the image there and restarts the
5 # container. Run from Git Bash on Windows: ./deploy.sh
6 #
7 # Two things this script deliberately never touches:
8 #
9 # .env lives on the server only. It holds the GitHub App secret and the
10 # session secret, and overwriting it from here would eventually
11 # push a stale copy over a good one.
12 # Caddyfile the shared reverse-proxy config at /opt/caddy. First-time setup
13 # is done once by hand, so a routine redeploy cannot take other
14 # sites down with it.
15 #
16 # The SQLite database is in a named Docker volume, so it survives every rebuild.
17 set -euo pipefail
18
19 # Deploy target. Kept out of the repository on purpose: this code is shared
20 # read-only with people outside the project, and the server address and
21 # login are not theirs to have. Set it once in your shell:
22 #
23 # export VPS=user@host
24 #
25 VPS=${VPS:?set VPS=user@host before deploying}
26 DEST=/opt/projects/profileshare
27
28 cd "$(dirname "$0")"
29
30 echo "==> Running the test suite before shipping anything..."
31 npm test
32
33 echo "==> Ensuring VPS project dir exists..."
34 ssh "$VPS" "mkdir -p '$DEST'"
35
36 echo "==> Checking that .env exists on the server..."
37 if ! ssh "$VPS" "test -f '$DEST/.env'"; then
38 echo ""
39 echo " $DEST/.env is missing. Create it on the server first, see DEPLOY.md."
40 echo " Nothing has been changed."
41 exit 1
42 fi
43
44 echo "==> Uploading source (node_modules, data and .env stay out of it)..."
45 tar --exclude=node_modules --exclude=data --exclude=.env --exclude=.git \
46 --exclude=coverage -czf - . | ssh "$VPS" "
47 rm -rf '$DEST/src.tmp' &&
48 mkdir -p '$DEST/src.tmp' &&
49 tar -C '$DEST/src.tmp' -xzf - &&
50 cp '$DEST/.env' '$DEST/src.tmp/.env' &&
51 rm -rf '$DEST/app' &&
52 mv '$DEST/src.tmp' '$DEST/app'
53 "
54
55 echo "==> Rebuilding and restarting the container..."
56 ssh "$VPS" "cd '$DEST/app' && docker compose up -d --build"
57
58 echo "==> Waiting for the health check to go green..."
59 ssh "$VPS" "
60 for i in \$(seq 1 20); do
61 state=\$(docker inspect -f '{{.State.Health.Status}}' profileshare 2>/dev/null || echo starting)
62 [ \"\$state\" = healthy ] && echo ' healthy' && exit 0
63 sleep 3
64 done
65 echo ' still not healthy, check: docker logs profileshare'
66 exit 1
67 "
68
69 echo ""
70 echo "==> Done. Live at https://code.rasmusj.com"
71