[STABLE] v0.4.2.4 - Robust .env protection during updates and manual update check UI
This commit is contained in:
parent
2f210d3b34
commit
ead5ff0fdf
3
.gitignore
vendored
3
.gitignore
vendored
@ -40,6 +40,9 @@ Desktop.ini
|
|||||||
|
|
||||||
# Project Specific - Server
|
# Project Specific - Server
|
||||||
server/.env
|
server/.env
|
||||||
|
server/.env.backup*
|
||||||
|
server/*.tmp
|
||||||
|
server/backups/
|
||||||
server/uploads/*
|
server/uploads/*
|
||||||
!server/uploads/.gitkeep
|
!server/uploads/.gitkeep
|
||||||
server/server.zip
|
server/server.zip
|
||||||
|
|||||||
23
server/.env1
Normal file
23
server/.env1
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# ==============================================
|
||||||
|
# [Common Settings]
|
||||||
|
# ==============================================
|
||||||
|
DB_HOST=sokuree.com
|
||||||
|
DB_USER=choibk
|
||||||
|
DB_PASSWORD=^Ocean1472bk
|
||||||
|
PORT=3005
|
||||||
|
|
||||||
|
# ==============================================
|
||||||
|
# [Development Environment] - Local Windows
|
||||||
|
# ==============================================
|
||||||
|
# 로컬 개발용 DB (분리됨: sokuree_platform_dev)
|
||||||
|
# DB_NAME=sokuree_platform_dev
|
||||||
|
# DB_PORT=3307
|
||||||
|
# Windows 환경 호환성 (tcp는 권한 오류 발생 가능)
|
||||||
|
CCTV_TRANSPORT_OVERRIDE=auto
|
||||||
|
|
||||||
|
# ==============================================
|
||||||
|
# [Production Environment] - Synology NAS
|
||||||
|
# ==============================================
|
||||||
|
DB_NAME=sokuree_platform_prod
|
||||||
|
DB_PORT=3307
|
||||||
|
|
||||||
@ -613,7 +613,7 @@ router.post('/version/update', isAuthenticated, hasRole('admin'), async (req, re
|
|||||||
|
|
||||||
// Build auth URL for git commands
|
// Build auth URL for git commands
|
||||||
let remoteUrl = auth.url;
|
let remoteUrl = auth.url;
|
||||||
if (auth.user && auth.pass) {
|
if (auth.user && auth.pass && auth.url.includes('https://')) {
|
||||||
remoteUrl = auth.url.replace('https://', `https://${encodeURIComponent(auth.user)}:${encodeURIComponent(auth.pass)}@`);
|
remoteUrl = auth.url.replace('https://', `https://${encodeURIComponent(auth.user)}:${encodeURIComponent(auth.pass)}@`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -632,18 +632,33 @@ router.post('/version/update', isAuthenticated, hasRole('admin'), async (req, re
|
|||||||
scriptContent = `
|
scriptContent = `
|
||||||
@echo off
|
@echo off
|
||||||
echo [Update] Starting update to ${targetTag}...
|
echo [Update] Starting update to ${targetTag}...
|
||||||
if not exist "${backupDir}" mkdir "${backupDir}"
|
|
||||||
|
|
||||||
echo [Update] Backing up Uploads & Config...
|
REM Ensure backup directory
|
||||||
tar -czvf "${backupDir}/backup_images_${timestamp}.tar.gz" server/uploads/
|
set BACKUP_PATH=${backupDir}
|
||||||
if exist "server\\.env" copy "server\\.env" "${backupDir}\\env_backup_${timestamp}"
|
if not exist "%BACKUP_PATH%" mkdir "%BACKUP_PATH%" 2>nul
|
||||||
|
if not exist "%BACKUP_PATH%" (
|
||||||
|
echo [Warning] Global backup failed, using local backup.
|
||||||
|
set BACKUP_PATH=.\\server\\backups
|
||||||
|
if not exist ".\\server\\backups" mkdir ".\\server\\backups"
|
||||||
|
)
|
||||||
|
|
||||||
|
echo [Update] Backing up Config...
|
||||||
|
if exist "server\\.env" (
|
||||||
|
copy /Y "server\\.env" "%BACKUP_PATH%\\.env.backup.${timestamp}"
|
||||||
|
copy /Y "server\\.env" "server\\.env.tmp"
|
||||||
|
)
|
||||||
|
|
||||||
echo [Update] Syncing Source Code...
|
echo [Update] Syncing Source Code...
|
||||||
git fetch "${remoteUrl}" +refs/tags/*:refs/tags/* --force --prune --prune-tags
|
git fetch "${remoteUrl}" --tags --force --prune
|
||||||
git checkout -f ${targetTag}
|
git checkout -f ${targetTag}
|
||||||
|
|
||||||
echo [Update] Restoring Config...
|
echo [Update] Restoring Config...
|
||||||
if exist "${backupDir}\\env_backup_${timestamp}" copy /Y "${backupDir}\\env_backup_${timestamp}" "server\\.env"
|
if exist "server\\.env.tmp" (
|
||||||
|
copy /Y "server\\.env.tmp" "server\\.env"
|
||||||
|
del "server\\.env.tmp"
|
||||||
|
) else if exist "%BACKUP_PATH%\\.env.backup.${timestamp}" (
|
||||||
|
copy /Y "%BACKUP_PATH%\\.env.backup.${timestamp}" "server\\.env"
|
||||||
|
)
|
||||||
|
|
||||||
echo [Update] Installing & Building...
|
echo [Update] Installing & Building...
|
||||||
call npm install
|
call npm install
|
||||||
@ -651,8 +666,7 @@ call npm run build
|
|||||||
cd server
|
cd server
|
||||||
call npm install
|
call npm install
|
||||||
|
|
||||||
echo [Update] Restarting Server...
|
echo [Update] Done.
|
||||||
echo "Please restart your dev server manually if needed."
|
|
||||||
`;
|
`;
|
||||||
} else {
|
} else {
|
||||||
// Linux/Synology Script
|
// Linux/Synology Script
|
||||||
@ -660,22 +674,59 @@ echo "Please restart your dev server manually if needed."
|
|||||||
scriptContent = `#!/bin/bash
|
scriptContent = `#!/bin/bash
|
||||||
exec > >(tee -a update.log) 2>&1
|
exec > >(tee -a update.log) 2>&1
|
||||||
echo "[Update] Starting update to ${targetTag}..."
|
echo "[Update] Starting update to ${targetTag}..."
|
||||||
mkdir -p ${backupDir}
|
|
||||||
|
# Ensure backup directory
|
||||||
|
BACKUP_DIR="${backupDir}"
|
||||||
|
mkdir -p "$BACKUP_DIR" || {
|
||||||
|
echo "[Warning] Global backup failed, using local backup."
|
||||||
|
BACKUP_DIR="./server/backups"
|
||||||
|
mkdir -p "$BACKUP_DIR"
|
||||||
|
}
|
||||||
|
|
||||||
echo "[Update] Backing up Database..."
|
echo "[Update] Backing up Database..."
|
||||||
${dumpTool} -u ${dbUser} --password='${dbPass}' --port ${dbPort} ${dbName} > ${backupDir}/backup_db_${timestamp}.sql || echo "DB Backup Failed, continuing..."
|
if [ -f "${dumpTool}" ]; then
|
||||||
|
echo "[Info] MySQL dump tool found. Attempting database backup..."
|
||||||
|
${dumpTool} -u ${dbUser} --password='${dbPass}' --port ${dbPort} ${dbName} > "$BACKUP_DIR/backup_db_${timestamp}.sql" 2>/dev/null
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "[Info] Database backup successful."
|
||||||
|
else
|
||||||
|
echo "[Warning] Database backup failed, continuing..."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "[Warning] MySQL dump tool not found. Skipping DB backup."
|
||||||
|
fi
|
||||||
|
|
||||||
echo "[Update] Backing up Uploads & Config..."
|
echo "[Update] Backing up Config..."
|
||||||
tar -czvf ${backupDir}/backup_images_${timestamp}.tar.gz server/uploads/
|
if [ -f "server/.env" ]; then
|
||||||
cp server/.env ${backupDir}/.env.backup.${timestamp}
|
echo "[Info] Backing up 'server/.env' to '$BACKUP_DIR/.env.backup.${timestamp}' and 'server/.env.tmp'."
|
||||||
|
cp "server/.env" "$BACKUP_DIR/.env.backup.${timestamp}"
|
||||||
|
cp "server/.env" "server/.env.tmp"
|
||||||
|
else
|
||||||
|
echo "[Warning] 'server/.env' not found. Skipping config backup."
|
||||||
|
fi
|
||||||
|
|
||||||
echo "[Update] Syncing Source Code..."
|
echo "[Update] Syncing Source Code..."
|
||||||
git remote set-url origin "${remoteUrl}"
|
git remote set-url origin "${remoteUrl}"
|
||||||
git fetch origin +refs/tags/*:refs/tags/* --force --prune --prune-tags
|
git fetch origin --tags --force --prune
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "[Error] Git fetch failed. Exiting update."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "[Info] Git fetch successful."
|
||||||
git checkout -f ${targetTag}
|
git checkout -f ${targetTag}
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "[Error] Git checkout to ${targetTag} failed. Exiting update."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "[Info] Git checkout to ${targetTag} successful."
|
||||||
|
|
||||||
echo "[Update] Restoring Config..."
|
echo "[Update] Restoring Config..."
|
||||||
cp ${backupDir}/.env.backup.${timestamp} server/.env
|
if [ -f "server/.env.tmp" ]; then
|
||||||
|
cp "server/.env.tmp" "server/.env"
|
||||||
|
rm "server/.env.tmp"
|
||||||
|
elif [ -f "$BACKUP_DIR/.env.backup.${timestamp}" ]; then
|
||||||
|
cp "$BACKUP_DIR/.env.backup.${timestamp}" "server/.env"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "[Update] Installing & Building..."
|
echo "[Update] Installing & Building..."
|
||||||
npm install
|
npm install
|
||||||
|
|||||||
@ -67,7 +67,8 @@ export function VersionPage() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchVersion();
|
fetchVersion();
|
||||||
fetchRemoteVersion();
|
// Removed fetchRemoteVersion from auto-load to prevent "automatic" sync feeling
|
||||||
|
// fetchRemoteVersion();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleUpdate = async () => {
|
const handleUpdate = async () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user