Files
convex-monorepo-payload/scripts/sync-local-convex-env
T
Gabriel Brown 7d1884be41
Build and Deploy Next App / quality (push) Successful in 1m24s
Build and Deploy Next App / convex-deploy (push) Successful in 1m58s
Build and Deploy Next App / build-next (push) Successful in 5m32s
Deploy from CI with Infisical and ship Payload changes as migrations
CI reads Infisical staging as the read-only convexmonorepo-ci machine identity, deploys the Convex functions, builds and pushes the image, and asks the VPS to redeploy. Payload schema changes now ship as migrations that production runs on startup; the baseline matches the production schema and is recorded as applied there. The local stack moves to its own ports and syncs the Convex runtime env, and the scripts pick up Infisical account switching, dev-kill and a cache-safe CI install.
2026-10-01 14:42:55 -04:00

48 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd -- "$SCRIPT_DIR/.." && pwd)"
VALUE_FILE=""
readonly RUNTIME_ENV_NAMES=(
AUTH_AUTHENTIK_ID
AUTH_AUTHENTIK_SECRET
AUTH_AUTHENTIK_ISSUER
USESEND_API_KEY
USESEND_URL
USESEND_FROM_EMAIL
)
readonly DEPLOYMENT_ENV_NAMES=(
CONVEX_SELF_HOSTED_URL
CONVEX_SELF_HOSTED_ADMIN_KEY
)
die() { printf 'sync-local-convex-env: %s\n' "$*" >&2; exit 1; }
cleanup() {
if [ -n "$VALUE_FILE" ] && [ -f "$VALUE_FILE" ]; then
rm -f "$VALUE_FILE"
fi
}
trap cleanup EXIT INT TERM HUP
for name in "${DEPLOYMENT_ENV_NAMES[@]}" "${RUNTIME_ENV_NAMES[@]}"; do
[ -n "${!name:-}" ] || die "Missing required environment variable: $name"
done
VALUE_FILE="$(mktemp "${TMPDIR:-/tmp}/convex-monorepo-convex-env.value.XXXXXX")"
chmod 600 "$VALUE_FILE"
for name in "${RUNTIME_ENV_NAMES[@]}"; do
printf '%s' "${!name}" > "$VALUE_FILE"
(
cd "$ROOT_DIR/packages/backend"
env -u CONVEX_DEPLOY_KEY -u CONVEX_DEPLOYMENT \
CONVEX_SELF_HOSTED_URL="$CONVEX_SELF_HOSTED_URL" \
CONVEX_SELF_HOSTED_ADMIN_KEY="$CONVEX_SELF_HOSTED_ADMIN_KEY" \
bunx convex env set "$name" --from-file "$VALUE_FILE" >/dev/null
)
done
printf 'Local Convex runtime environment synchronized.\n'