Spaces:
Running
Running
File size: 1,174 Bytes
74626f2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
$SERVER_IP = "172.16.193.4"
$SERVER_PORT = "22"
$SERVER_USER = "suhan"
$SERVER_PASS = "Test@123"
$REMOTE_PATH = "/home/suhan/nl_main"
$ZIP_FILE = "nl_main_deployment.tar.gz"
$PASS = $SERVER_PASS
Write-Host "--- 1. Cleaning up previous bundles ---" -ForegroundColor Cyan
if (Test-Path $ZIP_FILE) { Remove-Item $ZIP_FILE }
Write-Host "--- 2. Building Frontend ---" -ForegroundColor Cyan
npm run build
Write-Host "--- 3. Bundling Source Code with Tar ---" -ForegroundColor Cyan
tar -czf $ZIP_FILE backend dist Dockerfile docker-compose.yml package.json scripts
Write-Host "--- 4. Transferring to Server ($SERVER_IP) ---" -ForegroundColor Cyan
scp -P $SERVER_PORT $ZIP_FILE "$($SERVER_USER)@$($SERVER_IP):$REMOTE_PATH/"
Write-Host "--- 5. Remote Execution: Untar & Restart ---" -ForegroundColor Cyan
$remoteCmd = @"
echo $PASS | sudo -S mkdir -p $REMOTE_PATH
cd $REMOTE_PATH
echo $PASS | sudo -S rm -rf *
echo $PASS | sudo -S tar -xzf $ZIP_FILE
echo $PASS | sudo -S docker-compose down
echo $PASS | sudo -S docker-compose up --build -d
"@
ssh -p $SERVER_PORT "$($SERVER_USER)@$($SERVER_IP)" $remoteCmd
Write-Host "--- Deployment Complete! ---" -ForegroundColor Green
|