home
/
u941026986
/
domains
/
irole.co
/
public_html
/
scripts
➕ New
📤 Upload
✎ Editing:
deploy.sh
← Back
#!/bin/bash # Local Build and Deploy Script for iRole # This script builds the frontend locally and pushes to the server set -e # Exit on error echo "đ Starting deployment process..." # Get the root directory of the project ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" cd "$ROOT_DIR" || { echo "â Cannot enter root directory" exit 1 } # Colors for output GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' # No Color # Check if we're on the correct branch CURRENT_BRANCH=$(git branch --show-current) if [ "$CURRENT_BRANCH" != "main" ]; then echo -e "${YELLOW}â ī¸ Warning: You're not on 'main' branch (currently on '$CURRENT_BRANCH')${NC}" read -p "Continue anyway? (y/N) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "â Deployment cancelled" exit 1 fi fi # Check for uncommitted changes if ! git diff-index --quiet HEAD --; then echo -e "${YELLOW}â ī¸ Warning: You have uncommitted changes${NC}" git status --short read -p "Continue with deployment? (y/N) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "â Deployment cancelled. Please commit or stash your changes first." exit 1 fi fi # Step 1: Build the frontend echo "" echo "đĻ Step 1: Building frontend for production..." echo "ââââââââââââââââââââââââââââââââââââââââââââââââââââ" # Use the build-production script if available, otherwise use npm if [ -f "$ROOT_DIR/scripts/build-production.sh" ]; then bash "$ROOT_DIR/scripts/build-production.sh" else echo "Using npm run build..." export NODE_ENV=production export VITE_API_URL="${VITE_API_URL:-https://irole.co/api}" npm run build fi # Verify build was successful if [ ! -d "$ROOT_DIR/build" ] || [ ! -f "$ROOT_DIR/build/index.html" ]; then echo -e "${RED}â Build failed or build directory is invalid!${NC}" exit 1 fi echo -e "${GREEN}â Build completed successfully${NC}" # Step 2: Check if there's a new build echo "" echo "đ Step 2: Checking for new build..." echo "ââââââââââââââââââââââââââââââââââââââââââââââââââââ" # Calculate checksum of current build CURRENT_BUILD_CHECKSUM="" if [ -f "$ROOT_DIR/build/build-info.json" ]; then CURRENT_BUILD_CHECKSUM=$(cat "$ROOT_DIR/build/build-info.json" | grep -o '"buildTime":"[^"]*"' | cut -d'"' -f4 || echo "") fi # If no build-info.json, use a hash of index.html as fallback if [ -z "$CURRENT_BUILD_CHECKSUM" ] && [ -f "$ROOT_DIR/build/index.html" ]; then CURRENT_BUILD_CHECKSUM=$(md5sum "$ROOT_DIR/build/index.html" 2>/dev/null | cut -d' ' -f1 || shasum -a 256 "$ROOT_DIR/build/index.html" 2>/dev/null | cut -d' ' -f1 || echo "") fi # Get the build time from git (last committed build) GIT_BUILD_CHECKSUM="" if git ls-files --error-unmatch build/build-info.json >/dev/null 2>&1; then GIT_BUILD_CHECKSUM=$(git show HEAD:build/build-info.json 2>/dev/null | grep -o '"buildTime":"[^"]*"' | cut -d'"' -f4 || echo "") fi # Compare builds HAS_NEW_BUILD=false if [ -z "$GIT_BUILD_CHECKSUM" ]; then # No build in git, so this is a new build HAS_NEW_BUILD=true echo "âšī¸ No previous build found in git. This is a new build." elif [ "$CURRENT_BUILD_CHECKSUM" != "$GIT_BUILD_CHECKSUM" ]; then # Builds are different HAS_NEW_BUILD=true echo "âšī¸ New build detected (build time changed)" echo " Current: $CURRENT_BUILD_CHECKSUM" echo " In Git: $GIT_BUILD_CHECKSUM" else # Builds are the same HAS_NEW_BUILD=false echo "âšī¸ Build is identical to the one in git" echo " Build time: $CURRENT_BUILD_CHECKSUM" fi # Step 3: Stage and commit build files (only if new build) if [ "$HAS_NEW_BUILD" = true ]; then echo "" echo "đ Step 3: Staging build files for commit..." echo "ââââââââââââââââââââââââââââââââââââââââââââââââââââ" # Add build files to git git add build/ # Check if there are changes to commit if git diff --cached --quiet; then echo "âšī¸ No changes to commit (build already staged)" else # Get build info for commit message BUILD_VERSION="unknown" BUILD_TIME=$(date -u +"%Y-%m-%d %H:%M:%S UTC") if [ -f "$ROOT_DIR/build/build-info.json" ]; then BUILD_VERSION=$(grep -o '"version":"[^"]*"' "$ROOT_DIR/build/build-info.json" | cut -d'"' -f4 || echo "unknown") BUILD_TIME=$(grep -o '"buildTime":"[^"]*"' "$ROOT_DIR/build/build-info.json" | cut -d'"' -f4 || echo "$BUILD_TIME") fi COMMIT_MSG="Build: Frontend production build v$BUILD_VERSION ($BUILD_TIME)" echo "đ Commit message: $COMMIT_MSG" git commit -m "$COMMIT_MSG" echo -e "${GREEN}â Build files committed${NC}" fi # Step 4: Push to remote echo "" echo "âŦī¸ Step 4: Pushing to remote repository..." echo "ââââââââââââââââââââââââââââââââââââââââââââââââââââ" # Check if remote exists if ! git remote | grep -q origin; then echo -e "${RED}â No 'origin' remote found!${NC}" exit 1 fi # Push to main branch echo "Pushing to origin/main..." if git push origin main; then echo -e "${GREEN}â Successfully pushed to remote${NC}" else echo -e "${RED}â Failed to push to remote!${NC}" exit 1 fi else echo "" echo "âī¸ Step 3: Skipping push (no new build)" echo "ââââââââââââââââââââââââââââââââââââââââââââââââââââ" echo -e "${YELLOW}â ī¸ No new build detected. Not pushing to server.${NC}" echo " The existing build on the server will be preserved." echo "" echo " To create a new build and deploy:" echo " âĸ Make changes to your code" echo " âĸ Run this script again to build and deploy" fi # Step 5: Summary echo "" echo "ââââââââââââââââââââââââââââââââââââââââââââââââââââ" if [ "$HAS_NEW_BUILD" = true ]; then echo -e "${GREEN}â Deployment process completed!${NC}" echo "" echo "đ Summary:" echo " âĸ Frontend built for production" echo " âĸ Build files committed to git" echo " âĸ Changes pushed to origin/main" echo "" echo "đ Next steps:" echo " âĸ Server will automatically deploy via webhook/script" echo " âĸ Monitor server logs for deployment status" else echo -e "${YELLOW}âšī¸ Build process completed (no deployment)${NC}" echo "" echo "đ Summary:" echo " âĸ Frontend built for production" echo " âĸ No new build detected (same as git)" echo " âĸ Push skipped to preserve server build" fi echo ""
💾 Save Changes
Cancel
📤 Upload File
×
Select File
Upload
Cancel
➕ Create New
×
Type
📄 File
📁 Folder
Name
Create
Cancel
✎ Rename Item
×
Current Name
New Name
Rename
Cancel
🔐 Change Permissions
×
Target File
Permission (e.g., 0755, 0644)
0755
0644
0777
Apply
Cancel