fix: update-server.sh uses git reset --hard to avoid pull conflicts
This commit is contained in:
parent
499b012d82
commit
fc1222d5e8
@ -1,39 +1,45 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Server Update Script: Pull latest main, build, and restart PM2
|
# Server Update Script: Pull latest main, build, and restart PM2
|
||||||
set -e
|
set -e # Stop on any error
|
||||||
|
|
||||||
|
RED='\033[0;31m'
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
YELLOW='\033[1;33m'
|
YELLOW='\033[1;33m'
|
||||||
NC='\033[0m'
|
NC='\033[0m'
|
||||||
|
|
||||||
echo -e "${YELLOW}Step 1: Pulling latest changes from GitHub (main)...${NC}"
|
APP_DIR="/root/My-Weekly-ToDo-List"
|
||||||
cd /root/My-Weekly-ToDo-List
|
PM2_NAME="my-weekly-todo"
|
||||||
git checkout main
|
APP_URL="https://todo.martin-bierschenk.de"
|
||||||
git pull origin main
|
|
||||||
|
|
||||||
echo -e "${YELLOW}Step 2: Installing dependencies...${NC}"
|
cd "$APP_DIR"
|
||||||
|
|
||||||
|
echo -e "${YELLOW}[1/6] Syncing with GitHub (main)...${NC}"
|
||||||
|
git fetch origin
|
||||||
|
git reset --hard origin/main # Force-sync, ignores any local changes
|
||||||
|
echo -e " Version: $(node -p "require('./package.json').version")"
|
||||||
|
|
||||||
|
echo -e "${YELLOW}[2/6] Installing dependencies...${NC}"
|
||||||
npm install
|
npm install
|
||||||
|
|
||||||
echo -e "${YELLOW}Step 3: Updating database schema (Safe Migrate)...${NC}"
|
echo -e "${YELLOW}[3/6] Running database migrations...${NC}"
|
||||||
npx prisma migrate deploy
|
npx prisma migrate deploy
|
||||||
|
|
||||||
echo -e "${YELLOW}Step 4: Regenerating Prisma client...${NC}"
|
|
||||||
npx prisma generate
|
npx prisma generate
|
||||||
|
|
||||||
echo -e "${YELLOW}Step 5: Building application...${NC}"
|
echo -e "${YELLOW}[4/6] Building application...${NC}"
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
echo -e "${YELLOW}Step 5.5: Preparing standalone directory (copying static assets and env)...${NC}"
|
echo -e "${YELLOW}[5/6] Copying static assets to standalone...${NC}"
|
||||||
cp -r public .next/standalone/
|
cp -r public .next/standalone/
|
||||||
mkdir -p .next/standalone/.next/static
|
mkdir -p .next/standalone/.next/static
|
||||||
cp -r .next/static .next/standalone/.next/
|
cp -r .next/static .next/standalone/.next/
|
||||||
cp .env .next/standalone/ 2>/dev/null || true
|
cp .env .next/standalone/ 2>/dev/null || true
|
||||||
|
cp .env.local .next/standalone/ 2>/dev/null || true
|
||||||
|
|
||||||
echo -e "${YELLOW}Step 6: Restarting server with PM2 (Standalone Mode)...${NC}"
|
echo -e "${YELLOW}[6/6] Restarting PM2...${NC}"
|
||||||
# Delete old process if it exists to ensure fresh config
|
pm2 delete "$PM2_NAME" 2>/dev/null || true
|
||||||
pm2 delete my-weekly-todo || true
|
PORT=3000 NEXTAUTH_URL="$APP_URL" pm2 start .next/standalone/server.js --name "$PM2_NAME"
|
||||||
PORT=3000 NEXTAUTH_URL=https://todo.martin-bierschenk.de pm2 start .next/standalone/server.js --name "my-weekly-todo"
|
|
||||||
pm2 save
|
pm2 save
|
||||||
|
|
||||||
echo -e "${GREEN}Update complete! App is running on LXC.${NC}"
|
echo ""
|
||||||
|
echo -e "${GREEN}✓ Update complete! Running v$(node -p "require('./package.json').version")${NC}"
|
||||||
pm2 list
|
pm2 list
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user