mirror of
https://github.com/DeNNiiInc/Web-Page-Performance-Test.git
synced 2026-04-17 11:55:59 +00:00
Add deployment automation scripts and remove obsolete debug file
This commit is contained in:
154
deploy-all-fixes.ps1
Normal file
154
deploy-all-fixes.ps1
Normal file
@@ -0,0 +1,154 @@
|
||||
$config = Get-Content "deploy-config.json" | ConvertFrom-Json
|
||||
|
||||
$host_ip = $config.host
|
||||
$password = $config.password
|
||||
$remotePath = $config.remotePath
|
||||
$appName = $config.appName
|
||||
|
||||
Write-Host "🚀 Deploying ALL fixes to production..." -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Install Posh-SSH if not present
|
||||
if (-not (Get-Module -ListAvailable -Name Posh-SSH)) {
|
||||
Write-Host "Installing Posh-SSH module..." -ForegroundColor Yellow
|
||||
Install-Module -Name Posh-SSH -Force -Scope CurrentUser
|
||||
}
|
||||
|
||||
Import-Module Posh-SSH
|
||||
|
||||
# Create credential
|
||||
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
|
||||
$credential = New-Object System.Management.Automation.PSCredential ("root", $securePassword)
|
||||
|
||||
try {
|
||||
# Create SSH session
|
||||
Write-Host "Connecting to $host_ip..." -ForegroundColor Cyan
|
||||
$session = New-SSHSession -ComputerName $host_ip -Credential $credential -AcceptKey
|
||||
|
||||
if (-not $session) {
|
||||
throw "Failed to create SSH session"
|
||||
}
|
||||
|
||||
Write-Host "✅ Connected!" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
|
||||
# Step 1: Pull latest code
|
||||
Write-Host "📥 Pulling latest code from GitHub..." -ForegroundColor Cyan
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "cd $remotePath && git pull"
|
||||
Write-Host $result.Output
|
||||
|
||||
# Step 2: Update Nginx configuration
|
||||
Write-Host ""
|
||||
Write-Host "🔧 Updating Nginx configuration..." -ForegroundColor Cyan
|
||||
$nginxConfig = @"
|
||||
server {
|
||||
listen 80 default_server;
|
||||
server_name _;
|
||||
|
||||
root $remotePath;
|
||||
index index.html;
|
||||
|
||||
location /reports/ {
|
||||
try_files `$uri =404;
|
||||
add_header Content-Type application/json;
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files `$uri `$uri/ /index.html;
|
||||
}
|
||||
|
||||
location /api {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade `$http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host `$host;
|
||||
proxy_set_header X-Real-IP `$remote_addr;
|
||||
proxy_set_header X-Forwarded-For `$proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto `$scheme;
|
||||
proxy_cache_bypass `$http_upgrade;
|
||||
}
|
||||
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
|
||||
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
}
|
||||
"@
|
||||
|
||||
# Write config to server
|
||||
$escapedConfig = $nginxConfig -replace '"', '\"'
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "cat > /etc/nginx/sites-available/$appName << 'EOF'`n$nginxConfig`nEOF"
|
||||
|
||||
# Step 3: Test and reload Nginx
|
||||
Write-Host ""
|
||||
Write-Host "🧪 Testing Nginx configuration..." -ForegroundColor Cyan
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "nginx -t"
|
||||
Write-Host $result.Output
|
||||
Write-Host $result.Error
|
||||
|
||||
if ($result.ExitStatus -eq 0) {
|
||||
Write-Host ""
|
||||
Write-Host "🔄 Reloading Nginx..." -ForegroundColor Cyan
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "nginx -s reload"
|
||||
Write-Host "✅ Nginx reloaded!" -ForegroundColor Green
|
||||
}
|
||||
else {
|
||||
Write-Host "❌ Nginx configuration test failed!" -ForegroundColor Red
|
||||
throw "Nginx configuration error"
|
||||
}
|
||||
|
||||
# Step 4: Install dependencies and restart app
|
||||
Write-Host ""
|
||||
Write-Host "📦 Installing dependencies..." -ForegroundColor Cyan
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "cd $remotePath && npm install --production"
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "🔄 Restarting application..." -ForegroundColor Cyan
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "systemctl restart $appName"
|
||||
Write-Host "✅ Application restarted!" -ForegroundColor Green
|
||||
|
||||
# Verify service is running
|
||||
Start-Sleep -Seconds 2
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "systemctl is-active $appName"
|
||||
if ($result.Output -match "active") {
|
||||
Write-Host "✅ Service is running!" -ForegroundColor Green
|
||||
}
|
||||
else {
|
||||
Write-Host "⚠️ Service status: $($result.Output)" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Green
|
||||
Write-Host "✅ DEPLOYMENT COMPLETE!" -ForegroundColor Green
|
||||
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "📋 What was fixed:" -ForegroundColor Cyan
|
||||
Write-Host " ✅ Pulled latest code (includes runner.js fix)" -ForegroundColor White
|
||||
Write-Host " ✅ Updated Nginx to serve /reports/ JSON files" -ForegroundColor White
|
||||
Write-Host " ✅ Reloaded Nginx configuration" -ForegroundColor White
|
||||
Write-Host " ✅ Installed dependencies" -ForegroundColor White
|
||||
Write-Host " ✅ Restarted application service" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Write-Host "🎯 Next step:" -ForegroundColor Cyan
|
||||
Write-Host " Run a NEW test on https://beyondcloud.solutions/" -ForegroundColor Yellow
|
||||
Write-Host " Then click ⚡ Vitals - it will work now!" -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
|
||||
}
|
||||
catch {
|
||||
Write-Host ""
|
||||
Write-Host "❌ Deployment failed: $_" -ForegroundColor Red
|
||||
Write-Host $_.Exception.Message -ForegroundColor Red
|
||||
}
|
||||
finally {
|
||||
# Clean up session
|
||||
if ($session) {
|
||||
Remove-SSHSession -SessionId $session.SessionId | Out-Null
|
||||
}
|
||||
}
|
||||
47
diagnose-runner.ps1
Normal file
47
diagnose-runner.ps1
Normal file
@@ -0,0 +1,47 @@
|
||||
$config = Get-Content "deploy-config.json" | ConvertFrom-Json
|
||||
$remotePath = $config.remotePath
|
||||
|
||||
Import-Module Posh-SSH
|
||||
|
||||
$securePassword = ConvertTo-SecureString $config.password -AsPlainText -Force
|
||||
$credential = New-Object System.Management.Automation.PSCredential ("root", $securePassword)
|
||||
|
||||
Write-Host "🔍 Investigating runner.js on server..." -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
$session = New-SSHSession -ComputerName $config.host -Credential $credential -AcceptKey
|
||||
|
||||
# Check if details property exists in runner.js
|
||||
Write-Host "Checking for 'details:' in runner.js..." -ForegroundColor Yellow
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "cd $remotePath && grep -n 'details:' lib/runner.js | head -n 5"
|
||||
Write-Host $result.Output
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Checking git status..." -ForegroundColor Yellow
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "cd $remotePath && git status"
|
||||
Write-Host $result.Output
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Checking git log..." -ForegroundColor Yellow
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "cd $remotePath && git log --oneline -n 3"
|
||||
Write-Host $result.Output
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Forcing git pull..." -ForegroundColor Yellow
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "cd $remotePath && git fetch origin && git reset --hard origin/main"
|
||||
Write-Host $result.Output
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Verifying details exists now..." -ForegroundColor Yellow
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "cd $remotePath && grep -A 2 'details:' lib/runner.js | head -n 5"
|
||||
Write-Host $result.Output
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Restarting service..." -ForegroundColor Yellow
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "systemctl restart web-page-performance-test"
|
||||
Write-Host "✅ Service restarted!" -ForegroundColor Green
|
||||
|
||||
Remove-SSHSession -SessionId $session.SessionId | Out-Null
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "✅ DONE! Run a NEW test now." -ForegroundColor Green
|
||||
76
fix-html-reports.ps1
Normal file
76
fix-html-reports.ps1
Normal file
@@ -0,0 +1,76 @@
|
||||
$config = Get-Content "deploy-config.json" | ConvertFrom-Json
|
||||
Import-Module Posh-SSH
|
||||
|
||||
$securePassword = ConvertTo-SecureString $config.password -AsPlainText -Force
|
||||
$credential = New-Object System.Management.Automation.PSCredential ("root", $securePassword)
|
||||
|
||||
Write-Host "🔧 Fixing Nginx Content-Type issue..." -ForegroundColor Cyan
|
||||
|
||||
$session = New-SSHSession -ComputerName $config.host -Credential $credential -AcceptKey
|
||||
|
||||
$nginxConfig = @"
|
||||
server {
|
||||
listen 80 default_server;
|
||||
server_name _;
|
||||
|
||||
root $($config.remotePath);
|
||||
index index.html;
|
||||
|
||||
# Serve JSON reports with correct MIME type
|
||||
location ~ ^/reports/.*\.json$ {
|
||||
try_files `$uri =404;
|
||||
add_header Content-Type application/json;
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
}
|
||||
|
||||
# Serve HTML reports normally
|
||||
location ~ ^/reports/.*\.html$ {
|
||||
try_files `$uri =404;
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files `$uri `$uri/ /index.html;
|
||||
}
|
||||
|
||||
location /api {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade `$http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host `$host;
|
||||
proxy_set_header X-Real-IP `$remote_addr;
|
||||
proxy_set_header X-Forwarded-For `$proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto `$scheme;
|
||||
proxy_cache_bypass `$http_upgrade;
|
||||
}
|
||||
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
|
||||
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
}
|
||||
"@
|
||||
|
||||
Write-Host "Updating Nginx configuration..." -ForegroundColor Yellow
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "cat > /etc/nginx/sites-available/$($config.appName) << 'EOF'`n$nginxConfig`nEOF"
|
||||
|
||||
Write-Host "Testing Nginx..." -ForegroundColor Yellow
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "nginx -t"
|
||||
Write-Host $result.Output
|
||||
Write-Host $result.Error
|
||||
|
||||
if ($result.ExitStatus -eq 0) {
|
||||
Write-Host "Reloading Nginx..." -ForegroundColor Yellow
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "nginx -s reload"
|
||||
Write-Host ""
|
||||
Write-Host "✅ FIXED! HTML reports will work now!" -ForegroundColor Green
|
||||
}
|
||||
else {
|
||||
Write-Host "❌ Nginx test failed!" -ForegroundColor Red
|
||||
}
|
||||
|
||||
Remove-SSHSession -SessionId $session.SessionId | Out-Null
|
||||
62
kill-and-restart.ps1
Normal file
62
kill-and-restart.ps1
Normal file
@@ -0,0 +1,62 @@
|
||||
$config = Get-Content "deploy-config.json" | ConvertFrom-Json
|
||||
Import-Module Posh-SSH
|
||||
|
||||
$securePassword = ConvertTo-SecureString $config.password -AsPlainText -Force
|
||||
$credential = New-Object System.Management.Automation.PSCredential ("root", $securePassword)
|
||||
|
||||
Write-Host "🔍 DEBUGGING: Why is runner.js not updating?" -ForegroundColor Red
|
||||
Write-Host ""
|
||||
|
||||
$session = New-SSHSession -ComputerName $config.host -Credential $credential -AcceptKey
|
||||
|
||||
# Check current running process
|
||||
Write-Host "Current running process:" -ForegroundColor Yellow
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "ps aux | grep 'node.*server.js' | grep -v grep"
|
||||
Write-Host $result.Output
|
||||
|
||||
# Check service file
|
||||
Write-Host ""
|
||||
Write-Host "Service file ExecStart:" -ForegroundColor Yellow
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "cat /etc/systemd/system/web-page-performance-test.service | grep ExecStart"
|
||||
Write-Host $result.Output
|
||||
|
||||
# Check for node_modules cache
|
||||
Write-Host ""
|
||||
Write-Host "Checking node_modules..." -ForegroundColor Yellow
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "ls -la $($config.remotePath)/node_modules/ | head -n 5"
|
||||
Write-Host $result.Output
|
||||
|
||||
# Kill ALL node processes
|
||||
Write-Host ""
|
||||
Write-Host "🛑 Killing ALL node processes..." -ForegroundColor Red
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "pkill -9 node"
|
||||
Write-Host "Killed!"
|
||||
|
||||
# Wait a moment
|
||||
Start-Sleep -Seconds 2
|
||||
|
||||
# Start service fresh
|
||||
Write-Host ""
|
||||
Write-Host "🚀 Starting service fresh..." -ForegroundColor Green
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "systemctl start web-page-performance-test"
|
||||
Write-Host "Started!"
|
||||
|
||||
# Wait for it to come up
|
||||
Start-Sleep -Seconds 3
|
||||
|
||||
# Check status
|
||||
Write-Host ""
|
||||
Write-Host "Service status:" -ForegroundColor Yellow
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "systemctl status web-page-performance-test --no-pager | head -n 15"
|
||||
Write-Host $result.Output
|
||||
|
||||
# Check logs for module loading
|
||||
Write-Host ""
|
||||
Write-Host "Recent logs:" -ForegroundColor Yellow
|
||||
$result = Invoke-SSHCommand -SessionId $session.SessionId -Command "journalctl -u web-page-performance-test --since '1 minute ago' --no-pager | tail -n 20"
|
||||
Write-Host $result.Output
|
||||
|
||||
Remove-SSHSession -SessionId $session.SessionId | Out-Null
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "✅ Done! Run a NEW test now!" -ForegroundColor Green
|
||||
@@ -1,33 +0,0 @@
|
||||
const runner = require('../lib/runner');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
async function debug() {
|
||||
console.log("Starting debug test...");
|
||||
const url = "https://web-page-performance-test.beyondcloud.technology/";
|
||||
|
||||
try {
|
||||
// Run test
|
||||
const result = await runner.runTest(url, { isMobile: false, captureFilmstrip: true });
|
||||
|
||||
console.log("Test finished.");
|
||||
console.log("Extracted Details:", JSON.stringify(result.metrics.details, null, 2));
|
||||
|
||||
// Also let's look at the raw LHR to see where the data actually is
|
||||
// The runner saves the report to reports/<id>.json but that's the summary.
|
||||
// It also saves <id>.html.
|
||||
// We need to inspect the raw LHR object inside runner.js, but since I can't easily modify runner.js logging without potentially breaking things or noisy output,
|
||||
// I will rely on checking the result object first.
|
||||
|
||||
if (!result.metrics.details || !result.metrics.details.lcpElement) {
|
||||
console.error("❌ LCP Element is missing!");
|
||||
} else {
|
||||
console.log("✅ LCP Element found.");
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error("Test failed:", e);
|
||||
}
|
||||
}
|
||||
|
||||
debug();
|
||||
Reference in New Issue
Block a user