Update Dockerfile
Browse files1 unmodified line234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031 unmodified lineFROM lbjlaq/antigravity-manager:latestUSER root# curl is the only thing we need for Supabase REST APIRUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*ENV DATA_DIR=/root/.antigravity_toolsENV SYNC_INTERVAL=30EXPOSE 8045# Inline entrypoint β pull on start, push on change, push on shutdownCOPY --chmod=755 <<'SCRIPT' /entrypoint.sh#!/bin/bashset -eDATA_DIR="${DATA_DIR:-/root/.antigravity_tools}"SYNC_INTERVAL="${SYNC_INTERVAL:-30}"SYNC_FILE="/tmp/antigravity_data.tar.gz"LAST_SYNC="/tmp/.last_sync"supabase_download() {local codecode=$(curl -s -o "$SYNC_FILE" -w "%{http_code}" \"${SUPABASE_URL}/storage/v1/object/${SUPABASE_BUCKET}/antigravity_data.tar.gz" \-H "Authorization: Bearer ${SUPABASE_KEY}" \-H "Cache-Control: no-cache")[ "$code" = "200" ]}supabase_upload() {tar czf "$SYNC_FILE" -C "$(dirname "$DATA_DIR")" "$(basename "$DATA_DIR")" 2>/dev/null || return 1curl -s -X POST \"${SUPABASE_URL}/storage/v1/object/${SUPABASE_BUCKET}/antigravity_data.tar.gz" \-H "Authorization: Bearer ${SUPABASE_KEY}" \-H "Content-Type: application/gzip" \-H "x-upsert: true" \--data-binary @"$SYNC_FILE" > /dev/null 2>&1touch "$LAST_SYNC"echo "[Sync] Pushed to Supabase at $(date '+%H:%M:%S')"}has_changes() {[ ! -f "$LAST_SYNC" ] && return 0[ -n "$(find "$DATA_DIR" -newer "$LAST_SYNC" -type f 2>/dev/null)" ]}# ββ Step 1: Pull from Supabase (if data exists) ββif [ -n "$SUPABASE_URL" ] && [ -n "$SUPABASE_KEY" ] && [ -n "$SUPABASE_BUCKET" ]; thenecho "[Sync] Checking Supabase for existing data..."if supabase_download; thenecho "[Sync] Found backup β restoring..."mkdir -p "$DATA_DIR"tar xzf "$SYNC_FILE" -C "$(dirname "$DATA_DIR")" 2>/dev/nulltouch "$LAST_SYNC"echo "[Sync] Restore complete!"elseecho "[Sync] No backup found β first run."firm -f "$SYNC_FILE"elseecho "[Sync] No Supabase config β running without sync."fi# ββ Step 2: Start the app ββ/app/antigravity-tools --headless &APP_PID=$!# ββ Step 3: First run β wait for the app to create the data dir, then push ββif [ -n "$SUPABASE_URL" ] && [ ! -f "$LAST_SYNC" ]; thenecho "[Sync] Waiting for data directory..."while [ ! -d "$DATA_DIR" ]; do sleep 2; donesleep 5supabase_uploadfi# ββ Step 4: Background sync β push on change every N seconds ββif [ -n "$SUPABASE_URL" ]; then(while kill -0 $APP_PID 2>/dev/null; dosleep "$SYNC_INTERVAL"has_changes && supabase_uploaddone) &SYNC_PID=$!fi# ββ Step 5: Final sync on shutdown ββcleanup() {echo "[Sync] Shutting down β final push..."[ -n "$SUPABASE_URL" ] && supabase_uploadkill $APP_PID 2>/dev/null[ -n "$SYNC_PID" ] && kill $SYNC_PID 2>/dev/nullwait $APP_PID 2>/dev/nullexit 0}trap cleanup SIGTERM SIGINTwait $APP_PIDSCRIPT1 unmodified line234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161 unmodified lineFROM lbjlaq/antigravity-manager:latestUSER rootRUN apt-get update && apt-get install -y --no-install-recommends curl jq && rm -rf /var/lib/apt/lists/*ENV DATA_DIR=/root/.antigravity_toolsENV SYNC_INTERVAL=30EXPOSE 8045COPY --chmod=755 <<'SCRIPT' /entrypoint.sh#!/bin/bashset -eDATA_DIR="${DATA_DIR:-/root/.antigravity_tools}"SYNC_INTERVAL="${SYNC_INTERVAL:-30}"LAST_SYNC="/tmp/.last_sync"supabase_list() {local prefix="$1" response files foldersresponse=$(curl -s -X POST \"${SUPABASE_URL}/storage/v1/object/list/${SUPABASE_BUCKET}" \-H "Authorization: Bearer ${SUPABASE_KEY}" \-H "Content-Type: application/json" \-d "{\"prefix\":\"${prefix}\",\"limit\":1000}" 2>/dev/null)files=$(echo "$response" | jq -r '.[]? | select(.id != null) | .name' 2>/dev/null)folders=$(echo "$response" | jq -r '.[]? | select(.id == null) | .name' 2>/dev/null)for f in $files; do [ -n "$f" ] && echo "${prefix}${f}"; donefor d in $folders; do [ -n "$d" ] && supabase_list "${prefix}${d}/"; done}supabase_pull() {echo "[Sync] Pulling files from Supabase..."supabase_list "" | while read -r fp; domkdir -p "$(dirname "$DATA_DIR/$fp")"curl -s -o "$DATA_DIR/$fp" \"${SUPABASE_URL}/storage/v1/object/${SUPABASE_BUCKET}/${fp}" \-H "Authorization: Bearer ${SUPABASE_KEY}"echo "[Sync] <- $fp"donetouch "$LAST_SYNC"echo "[Sync] Pull complete!"}supabase_push_file() {local rel="${1#$DATA_DIR/}"curl -s -X POST \"${SUPABASE_URL}/storage/v1/object/${SUPABASE_BUCKET}/${rel}" \-H "Authorization: Bearer ${SUPABASE_KEY}" \-H "Content-Type: application/octet-stream" \-H "x-upsert: true" \--data-binary "@${1}" > /dev/null 2>&1}supabase_push_all() {echo "[Sync] Pushing all files..."find "$DATA_DIR" -type f | while read -r f; dosupabase_push_file "$f"echo "[Sync] -> ${f#$DATA_DIR/}"donetouch "$LAST_SYNC"echo "[Sync] Push complete!"}supabase_push_changed() {local changedchanged=$(find "$DATA_DIR" -type f -newer "$LAST_SYNC" 2>/dev/null)[ -z "$changed" ] && return 1echo "$changed" | while read -r f; dosupabase_push_file "$f"echo "[Sync] -> ${f#$DATA_DIR/}"donetouch "$LAST_SYNC"}supabase_has_data() {local rr=$(curl -s -X POST \"${SUPABASE_URL}/storage/v1/object/list/${SUPABASE_BUCKET}" \-H "Authorization: Bearer ${SUPABASE_KEY}" \-H "Content-Type: application/json" -d '{"prefix":"","limit":1}' 2>/dev/null)[ "$(echo "$r" | jq 'length' 2>/dev/null)" != "0" ]}SYNC=""[ -n "$SUPABASE_URL" ] && [ -n "$SUPABASE_KEY" ] && [ -n "$SUPABASE_BUCKET" ] && SYNC="1"if [ -n "$SYNC" ]; thenecho "[Sync] Checking Supabase..."if supabase_has_data; then supabase_pull; else echo "[Sync] Empty bucket β first run."; fifi/app/antigravity-tools --headless &APP_PID=$!if [ -n "$SYNC" ] && [ ! -f "$LAST_SYNC" ]; thenecho "[Sync] Waiting for data dir..."while [ ! -d "$DATA_DIR" ]; do sleep 2; donesleep 5 && supabase_push_allfiif [ -n "$SYNC" ]; then( while kill -0 $APP_PID 2>/dev/null; do sleep "$SYNC_INTERVAL"; supabase_push_changed || true; done ) &SYNC_PID=$!ficleanup() {echo "[Sync] Shutting down..."[ -n "$SYNC" ] && [ -d "$DATA_DIR" ] && supabase_push_allkill $APP_PID 2>/dev/null; [ -n "$SYNC_PID" ] && kill $SYNC_PID 2>/dev/nullwait $APP_PID 2>/dev/null; exit 0}trap cleanup SIGTERM SIGINTwait $APP_PIDSCRIPT
Dockerfile+71-58