Files
falah-os-ce/deploy-falah-mobile.sh
T
Antigravity AI defeb7f2d2 feat: add falah-shortcodes WP plugin and Falah Mobile deploy script
Implements all missing shortcodes for ummah.falahos.my:
- [prayer_times] — Aladhan API, no auth required
- [dhikr_counter] — localStorage-backed, works offline
- [qibla_compass] — browser Geolocation + DeviceOrientation
- [daily_verse] — AlQuran.cloud API, no auth required
- [nur_ai_chat], [falah_wallet], [souq_marketplace] — iframe Falah Mobile
- [falah_dashboard] — auto-injects dashboard content into empty page

Also adds deploy-falah-mobile.sh to build and run the Next.js app on
13.140.161.244:4013, and Nginx reverse proxy config for falahos.my/mobile.
2026-07-06 15:58:03 +08:00

89 lines
2.8 KiB
Bash

#!/usr/bin/env bash
# deploy-falah-mobile.sh — Build and deploy FalahMobile Next.js app to production
# Usage: bash deploy-falah-mobile.sh <server-ip> [ssh-user]
# Prerequisites: SSH key access to server, Docker installed on server
#
# Credentials: retrieve from bitwarden.falahos.my
# - Server SSH: "Falah OS CE Server - 13.140.161.244"
set -euo pipefail
SERVER="${1:-13.140.161.244}"
SSH_USER="${2:-root}"
REMOTE="$SSH_USER@$SERVER"
DEPLOY_DIR="/opt/falah-mobile"
APP_PORT="4013"
IMAGE="falah-mobile:latest"
CONTAINER="falah-mobile"
echo "▶ Deploying Falah Mobile to $SERVER:$APP_PORT"
# ── 1. Transfer source to server ─────────────────────────────────────────────
echo "── Syncing source files ──"
ssh "$REMOTE" "mkdir -p $DEPLOY_DIR"
rsync -az --delete \
--exclude='.git' \
--exclude='node_modules' \
--exclude='.next' \
--exclude='*.log' \
"$(dirname "$0")/../FalahMobile/" \
"$REMOTE:$DEPLOY_DIR/"
# ── 2. Build and run on server ───────────────────────────────────────────────
ssh "$REMOTE" bash -s << REMOTE_SCRIPT
set -euo pipefail
cd "$DEPLOY_DIR"
# Create .env if missing
if [ ! -f .env ]; then
cat > .env << 'ENVEOF'
NODE_ENV=production
PORT=3000
DATABASE_URL=file:./data/falah.db
NEXTAUTH_URL=https://falahos.my/mobile
NEXTAUTH_SECRET=$(openssl rand -base64 32)
ENVEOF
echo "⚠️ Created .env — review and update NEXTAUTH_URL and secrets"
fi
echo "── Building Docker image ──"
docker build -t $IMAGE .
echo "── Stopping old container (if any) ──"
docker rm -f $CONTAINER 2>/dev/null || true
echo "── Starting new container ──"
docker run -d \
--name $CONTAINER \
--restart unless-stopped \
-p $APP_PORT:3000 \
-v $DEPLOY_DIR/data:/app/data \
--env-file .env \
$IMAGE
echo "── Running Prisma migrations ──"
sleep 5
docker exec $CONTAINER npx prisma migrate deploy --schema=./prisma/schema.prisma || true
echo "── Health check ──"
sleep 5
if curl -sf "http://localhost:$APP_PORT" > /dev/null 2>&1; then
echo "✅ Falah Mobile is running at http://$SERVER:$APP_PORT"
else
echo "⚠️ Health check failed — checking logs:"
docker logs --tail 30 $CONTAINER
fi
REMOTE_SCRIPT
echo ""
echo "✅ Deploy complete."
echo " App: http://$SERVER:$APP_PORT"
echo " Nur AI: http://$SERVER:$APP_PORT/nur"
echo " Wallet: http://$SERVER:$APP_PORT/wallet"
echo " Souq: http://$SERVER:$APP_PORT/souq"
echo ""
echo "Next: Configure Cloudflare/Nginx to proxy falahos.my/mobile → $SERVER:$APP_PORT"
echo " Then update WordPress Settings → Falah Shortcodes → Mobile URL to: https://falahos.my/mobile"