Files
zmb-webui/deploy/deploy-frontend-static.sh
T
Claude Code 92bed208e0 ZMB Webui: Complete Project – Rebrand & Initial Clean Commit
ARCHITECTURE
============
Backend: FastAPI + uvicorn (port 8000)
  - JWT authentication with PAM system users
  - ZFS CLI wrapper with caching (30-60s TTL)
  - WebSocket pool status broadcaster (30s interval)
  - Services: auth, zfs_runner, file_manager, shares, identities, system_info
  - Routers: pools, datasets, snapshots, shares, identities, navigator, system

Frontend: Next.js 15 + TypeScript (static export)
  - Incremental Static Regeneration (ISR) for weak hardware
  - Type-safe API client (lib/api.ts)
  - Dark mode + custom Tailwind theme
  - Pages: Dashboard, Login, Snapshots, Datasets, Shares, etc.

DEPLOYMENT
==========
Test Target: 192.168.1.179:8090 (Debian LXC)
Production: 10.66.120.3:9090 (Raspberry Pi 4GB ARM64)
Updater: Automated Gitea-based deployment (update-test.sh, update-pi.sh)

FEATURES COMPLETED
==================
Phase 3a: Dashboard Quick Stats (System, CPU, Memory, Storage)
  - Real-time stats with color-coded progress bars
  - Responsive grid layout (mobile: 1, tablet: 2, desktop: 4 columns)
  - ISR-optimized for fast loads on weak hardware

REBRANDING
==========
Renamed throughout:
  - Project: 'ZFS Manager' → 'ZMB Webui'
  - Services: 'zfs-manager' → 'zmb-webui'
  - Systemd units: zfs-manager-backend → zmb-webui-backend
  - Configuration files and documentation

Co-Authored-By: Patrick <patrick@perlbach24.de>
2026-04-22 00:43:05 +02:00

163 lines
5.0 KiB
Bash

#!/bin/bash
# ZMB Webui Frontend Static Export Deployment
# Für RAM-optimierte Lösung: next build → out/ → nginx serve (kein Node.js Runtime)
set -e
echo "=== ZMB Webui Frontend Static Export Build ==="
# Configuration
FRONTEND_DIR="/opt/zmb-webui/frontend"
FRONTEND_TEMP="/tmp/frontend"
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
# Check frontend directory exists
echo -e "${YELLOW}1. Checking frontend source...${NC}"
if [ ! -d "$FRONTEND_TEMP" ]; then
echo -e "${RED}✗ Frontend source not found: $FRONTEND_TEMP${NC}"
echo -e "${RED} Make sure frontend was copied to container first${NC}"
exit 1
fi
echo -e "${GREEN}✓ Frontend source found${NC}"
# Create/prepare frontend directory
echo -e "${YELLOW}2. Preparing frontend directory...${NC}"
mkdir -p "$FRONTEND_DIR"
rm -rf "$FRONTEND_DIR"/*
cp -r "$FRONTEND_TEMP"/* "$FRONTEND_DIR/"
cd "$FRONTEND_DIR"
echo -e "${GREEN}✓ Frontend prepared${NC}"
# Install dependencies with memory optimization
echo -e "${YELLOW}4. Installing dependencies (memory-optimized)...${NC}"
npm install --prefer-offline --no-audit --production=false 2>&1 | grep -E "added|up to date|npm WARN" || true
echo -e "${GREEN}✓ Dependencies installed${NC}"
# Build static export
echo -e "${YELLOW}5. Building static export...${NC}"
npm run build 2>&1 | tail -20
echo -e "${GREEN}✓ Build complete${NC}"
# Verify out/ directory
echo -e "${YELLOW}6. Verifying export directory...${NC}"
if [ ! -d "$FRONTEND_DIR/out" ]; then
echo -e "${RED}✗ Export directory 'out' not found${NC}"
exit 1
fi
PAGES_COUNT=$(find out -name "*.html" | wc -l)
echo -e "${GREEN}✓ Export successful ($PAGES_COUNT pages)${NC}"
# Configure nginx
echo -e "${YELLOW}7. Configuring nginx...${NC}"
sudo tee /etc/nginx/sites-available/zmb-webui > /dev/null <<'NGINX_CONF'
server {
listen 9090;
server_name _;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
# Compression
gzip on;
gzip_min_length 1000;
gzip_types text/plain text/css application/json application/javascript;
gzip_comp_level 5;
# Static assets cache (7 days)
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
root /opt/zmb-webui/frontend/out;
expires 7d;
add_header Cache-Control "public, max-age=604800, immutable";
access_log off;
}
# Frontend static pages
location / {
root /opt/zmb-webui/frontend/out;
try_files $uri $uri/ /index.html;
add_header Cache-Control "public, max-age=3600";
}
# API routes → Backend
location /api/ {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
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_connect_timeout 10s;
proxy_read_timeout 30s;
}
# Health check
location /health {
proxy_pass http://localhost:8000;
access_log off;
}
# Logging
access_log /var/log/nginx/zmb-webui-access.log combined;
error_log /var/log/nginx/zmb-webui-error.log warn;
}
NGINX_CONF
echo -e "${GREEN}✓ Nginx configured${NC}"
# Enable nginx site
echo -e "${YELLOW}8. Enabling nginx site...${NC}"
sudo rm -f /etc/nginx/sites-enabled/default
sudo ln -sf /etc/nginx/sites-available/zmb-webui /etc/nginx/sites-enabled/zmb-webui
echo -e "${GREEN}✓ Nginx site enabled${NC}"
# Test and reload nginx
echo -e "${YELLOW}9. Testing and reloading nginx...${NC}"
sudo nginx -t
sudo systemctl reload nginx
echo -e "${GREEN}✓ Nginx reloaded${NC}"
# Clean up systemd service (no longer needed for Node.js)
echo -e "${YELLOW}10. Cleaning up systemd services...${NC}"
if [ -f /etc/systemd/system/zmb-webui-frontend.service ]; then
sudo systemctl disable zmb-webui-frontend 2>/dev/null || true
sudo systemctl stop zmb-webui-frontend 2>/dev/null || true
sudo rm -f /etc/systemd/system/zmb-webui-frontend.service
sudo systemctl daemon-reload
echo -e "${GREEN}✓ Frontend Node.js service removed${NC}"
fi
# Verify connectivity
echo -e "${YELLOW}11. Testing connectivity...${NC}"
sleep 1
if curl -s http://localhost:9090 > /dev/null 2>&1; then
echo -e "${GREEN}✓ Frontend accessible at http://localhost:9090${NC}"
else
echo -e "${YELLOW}⚠ Frontend not yet responding (nginx warming up)${NC}"
fi
# Summary
echo ""
echo -e "${GREEN}=== Deployment Complete ===${NC}"
echo ""
echo "Frontend (Static):"
echo " URL: http://$(hostname -I | awk '{print $1}'):9090"
echo ""
echo "Backend API:"
echo " URL: http://localhost:8000"
echo " Health: curl http://localhost:8000/health"
echo ""
echo "Service Management:"
echo " systemctl status nginx"
echo " systemctl restart nginx"
echo ""
echo "Logs:"
echo " tail -f /var/log/nginx/zmb-webui-access.log"
echo " tail -f /var/log/nginx/zmb-webui-error.log"
echo ""