CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
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 | ||
| 30e70f3 | 24 | # NOTE: `|| true` is deliberate. On this Coolify co-tenant box the compose |
| 25 | # also defines a `caddy` service that tries to bind host :80/:443, which | |
| 26 | # Coolify's proxy already owns — so `up` reports a non-zero exit for caddy | |
| 27 | # even though the app (gluecron) started fine. Under `set -e` that would abort | |
| 28 | # the deploy BEFORE the coolify reattach + health gate below. We tolerate the | |
| 29 | # partial failure here and instead gate on the app's OWN health further down. | |
| 30 | $COMPOSE up -d --build || echo "$(date -Is) compose up returned non-zero (likely the co-tenant caddy port conflict) — continuing to app health gate" | |
| f635e2f | 31 | sleep 5 |
| 5bac517 | 32 | |
| 33 | # Co-tenant ingress reattach (Coolify boxes only). | |
| 34 | # `docker compose up --build` recreates the gluecron container, which DROPS | |
| 35 | # any network attachment not declared in docker-compose.standalone.yml. On | |
| 36 | # this box the public ingress is Coolify's Traefik ("coolify-proxy"), which | |
| 37 | # reaches the app over the external "coolify" network via the file route | |
| 38 | # /traefik/dynamic/gluecron.yaml in the coolify-proxy container. Without this | |
| 39 | # reattach, every deploy 502s the site until someone reconnects by hand. | |
| 30e70f3 | 40 | # Idempotent: a no-op if already attached; skipped entirely on a dedicated VPS |
| 41 | # that has no "coolify" network. | |
| 5bac517 | 42 | if docker network inspect coolify >/dev/null 2>&1; then |
| 43 | docker network connect coolify gluecron-gluecron-1 2>/dev/null \ | |
| 44 | && echo "$(date -Is) reattached gluecron to coolify network" \ | |
| 45 | || echo "$(date -Is) coolify network already attached (ok)" | |
| 46 | fi | |
| 47 | ||
| f635e2f | 48 | $COMPOSE exec -T gluecron bun run db:migrate || true |
| 49 | docker image prune -f >/dev/null 2>&1 || true | |
| 50 | ||
| 30e70f3 | 51 | # App health gate — the real success signal (not caddy). Poll the container's |
| 52 | # own /healthz; if the app itself never comes up, exit non-zero so the systemd | |
| 53 | # unit records a failed deploy instead of a silent green. | |
| 54 | healthy=0 | |
| 55 | for _ in $(seq 1 20); do | |
| 56 | if docker exec gluecron-gluecron-1 wget -qO- --timeout=4 http://localhost:3000/healthz >/dev/null 2>&1; then | |
| 57 | healthy=1; break | |
| 58 | fi | |
| 59 | sleep 3 | |
| 60 | done | |
| 61 | if [ "$healthy" != "1" ]; then | |
| 62 | echo "$(date -Is) DEPLOY FAILED: app /healthz never came up for $remote_sha" >&2 | |
| 63 | exit 1 | |
| 64 | fi | |
| 65 | ||
| 66 | echo "$(date -Is) deploy complete: $remote_sha (app healthy)" |