Blame · Line-by-line history
auto-update.sh
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| f635e2f | 1 | #!/usr/bin/env bash |
| 2 | # | |
| 3 | # Fast auto-deploy for the standalone box. Installed as a ~60s systemd timer by | |
| 4 | # scripts/standalone-deploy.sh. Polls the deploy branch; when new commits land, | |
| 5 | # it pulls, rebuilds, and runs migrations. Push -> live in ~1-2 min, hands-off. | |
| 6 | # | |
| 7 | # Exits immediately (cheap) when there is nothing new, so a tight interval is fine. | |
| 8 | set -euo pipefail | |
| 9 | ||
| 10 | REPO_DIR="/opt/gluecron" | |
| 9de2807 | 11 | BRANCH="main" |
| f635e2f | 12 | COMPOSE="docker compose -f docker-compose.standalone.yml" |
| 13 | ||
| 14 | cd "$REPO_DIR" | |
| 15 | git fetch origin "$BRANCH" --quiet | |
| 16 | ||
| 17 | local_sha=$(git rev-parse HEAD) | |
| 18 | remote_sha=$(git rev-parse "origin/$BRANCH") | |
| 19 | [ "$local_sha" = "$remote_sha" ] && exit 0 | |
| 20 | ||
| 21 | echo "$(date -Is) deploying $local_sha -> $remote_sha" | |
| 22 | git reset --hard "origin/$BRANCH" # untracked .env / backups are preserved | |
| 23 | ||
| 24 | $COMPOSE up -d --build | |
| 25 | sleep 5 | |
| 5bac517 | 26 | |
| 27 | # Co-tenant ingress reattach (Coolify boxes only). | |
| 28 | # `docker compose up --build` recreates the gluecron container, which DROPS | |
| 29 | # any network attachment not declared in docker-compose.standalone.yml. On | |
| 30 | # this box the public ingress is Coolify's Traefik ("coolify-proxy"), which | |
| 31 | # reaches the app over the external "coolify" network via the file route | |
| 32 | # /traefik/dynamic/gluecron.yaml in the coolify-proxy container. Without this | |
| 33 | # reattach, every deploy 502s the site until someone reconnects by hand. | |
| 34 | # Idempotent: a no-op if already attached; harmless no-op on a dedicated VPS | |
| 35 | # that has no "coolify" network (errors are swallowed). | |
| 36 | if docker network inspect coolify >/dev/null 2>&1; then | |
| 37 | docker network connect coolify gluecron-gluecron-1 2>/dev/null \ | |
| 38 | && echo "$(date -Is) reattached gluecron to coolify network" \ | |
| 39 | || echo "$(date -Is) coolify network already attached (ok)" | |
| 40 | fi | |
| 41 | ||
| f635e2f | 42 | $COMPOSE exec -T gluecron bun run db:migrate || true |
| 43 | docker image prune -f >/dev/null 2>&1 || true | |
| 44 | ||
| 45 | echo "$(date -Is) deploy complete: $remote_sha" |