profileShare

rasmusjy / countrysense

Read-only snapshot

No repository description.

main default branch 19 files Expires Sep 13, 2026, 9:06 AM
deploy.sh 2,439 bytes
1 #!/usr/bin/env bash
2 # One-command redeploy for countrysense.rasmusj.com.
3 #
4 # Run from Git Bash on Windows: ./deploy.sh
5 #
6 # The checkpoint is 330 MB and almost never changes, so it travels on its own
7 # and only when its hash differs from the copy already on the server. Everything
8 # else is a few hundred kilobytes of source.
9 #
10 # The shared reverse proxy at /opt/caddy is never touched.
11 set -euo pipefail
12
13 # Deploy target. Kept out of the repository on purpose: this code is shared
14 # read-only with people outside the project, and the server address and
15 # login are not theirs to have. Set it once in your shell:
16 #
17 # export VPS=user@host
18 #
19 VPS=${VPS:?set VPS=user@host before deploying}
20 DEST=/opt/projects/countrysense
21 CKPT=runs/clip_vit_b16/best.pt
22
23 cd "$(dirname "$0")"
24
25 if [ ! -f "$CKPT" ]; then
26 echo " $CKPT is missing. Train first, or copy it in from the run you kept."
27 exit 1
28 fi
29
30 echo "==> Ensuring VPS project dir exists..."
31 ssh "$VPS" "mkdir -p '$DEST/model'"
32
33 echo "==> Comparing the checkpoint with the one on the server..."
34 local_sum=$(sha256sum "$CKPT" | cut -d' ' -f1)
35 remote_sum=$(ssh "$VPS" "sha256sum '$DEST/model/best.pt' 2>/dev/null | cut -d' ' -f1" || true)
36 if [ "$local_sum" != "$remote_sum" ]; then
37 echo " uploading 330 MB, this takes a few minutes..."
38 scp "$CKPT" "$VPS:$DEST/model/best.pt"
39 else
40 echo " unchanged, skipping the upload"
41 fi
42
43 echo "==> Uploading source (the checkpoint, runs output and notebooks stay out)..."
44 tar --exclude=.git --exclude=__pycache__ --exclude=notebooks --exclude='*.pt' \
45 --exclude='*.png' --exclude=data -czf - . | ssh "$VPS" "
46 rm -rf '$DEST/src.tmp' &&
47 mkdir -p '$DEST/src.tmp' &&
48 tar -C '$DEST/src.tmp' -xzf - &&
49 mkdir -p '$DEST/src.tmp/runs/clip_vit_b16' &&
50 cp '$DEST/model/best.pt' '$DEST/src.tmp/runs/clip_vit_b16/best.pt' &&
51 rm -rf '$DEST/app' &&
52 mv '$DEST/src.tmp' '$DEST/app'
53 "
54
55 echo "==> Building 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 (first load reads 330 MB)..."
59 ssh "$VPS" "
60 for i in \$(seq 1 40); do
61 state=\$(docker inspect -f '{{.State.Health.Status}}' countrysense 2>/dev/null || echo starting)
62 [ \"\$state\" = healthy ] && echo ' healthy' && exit 0
63 sleep 5
64 done
65 echo ' still not healthy, check: docker logs countrysense'
66 exit 1
67 "
68
69 echo ""
70 echo "==> Done. Live at https://countrysense.rasmusj.com"
71