From 980d7c1561b5e2d02f275ea863899d036aa1e938 Mon Sep 17 00:00:00 2001 From: Esdras Renan Date: Wed, 8 Oct 2025 14:24:50 -0300 Subject: [PATCH] chore: add scripts/deploy-from-git.sh (pull-based deploy fallback on VPS) --- scripts/deploy-from-git.sh | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 scripts/deploy-from-git.sh diff --git a/scripts/deploy-from-git.sh b/scripts/deploy-from-git.sh new file mode 100644 index 0000000..3a4996c --- /dev/null +++ b/scripts/deploy-from-git.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Simple pull-based deployer for the VPS, bypassing GitHub Actions. +# - Syncs repo with origin/main +# - Reapplies Swarm stack +# - If convex/ changed, deploys Convex functions to self-hosted backend +# +# Requirements: +# - Run from /srv/apps/sistema (or set APP_DIR below) +# - A file .ci.env with: +# CONVEX_SELF_HOSTED_URL=https://convex.esdrasrenan.com.br +# CONVEX_SELF_HOSTED_ADMIN_KEY=convex-self-hosted|... + +APP_DIR=${APP_DIR:-/srv/apps/sistema} +cd "$APP_DIR" + +echo "[deploy] Fetching origin/main..." +git fetch origin main --quiet + +CURRENT=$(git rev-parse HEAD || echo "") +REMOTE=$(git rev-parse origin/main) + +if [[ "$CURRENT" == "$REMOTE" ]]; then + echo "[deploy] Nothing to do (up-to-date)." + exit 0 +fi + +echo "[deploy] Computing changed paths..." +CHANGED=$(git diff --name-only "${CURRENT:-$REMOTE}" "$REMOTE" || true) + +echo "[deploy] Resetting to origin/main ($REMOTE)..." +git reset --hard "$REMOTE" + +echo "[deploy] Re-deploying Swarm stack..." +docker stack deploy --with-registry-auth -c stack.yml sistema + +if echo "$CHANGED" | grep -q '^convex/'; then + if [[ -f .ci.env ]]; then + echo "[deploy] convex/ changed -> deploying Convex functions..." + docker run --rm -i \ + -v "$APP_DIR":/app \ + -w /app \ + --env-file .ci.env \ + node:20-bullseye bash -lc "corepack enable && corepack prepare pnpm@9 --activate && pnpm install --frozen-lockfile --prod=false && pnpm exec convex deploy" + else + echo "[deploy] convex/ changed but .ci.env missing; skip Convex deploy" + fi +else + echo "[deploy] convex/ unchanged; skipping Convex deploy" +fi + +echo "[deploy] Done." +