-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·262 lines (227 loc) · 8.1 KB
/
dev.sh
File metadata and controls
executable file
·262 lines (227 loc) · 8.1 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/bin/bash
# Velero Dashboard Development Script
# Usage: ./dev.sh [backend|frontend|all|stop|status]
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
function log_info() {
echo -e "${BLUE}ℹ${NC} $1"
}
function log_success() {
echo -e "${GREEN}✓${NC} $1"
}
function log_error() {
echo -e "${RED}✗${NC} $1"
}
function log_warn() {
echo -e "${YELLOW}⚠${NC} $1"
}
function check_deps() {
local missing=0
if ! command -v go &> /dev/null; then
log_error "Go not found. Install Go 1.24+"
missing=1
fi
if ! command -v node &> /dev/null; then
log_error "Node.js not found. Install Node.js 22+"
missing=1
fi
if [ $missing -eq 1 ]; then
exit 1
fi
}
function start_backend() {
log_info "Starting Backend (Hot-Reload)..."
cd "$SCRIPT_DIR/backend"
# Kill existing backend process
pkill -f "velero-dashboard" 2>/dev/null || true
pkill -f "tmp/main" 2>/dev/null || true
# Check for kubeconfig
if [ -z "$KUBECONFIG" ] && [ ! -f "$HOME/.kube/config" ]; then
log_warn "No kubeconfig found. Set KUBECONFIG or ensure ~/.kube/config exists"
log_warn "Backend will fail to connect to Kubernetes cluster"
fi
# Generate encryption key if not set
if [ -z "$CLUSTER_ENCRYPTION_KEY" ]; then
export CLUSTER_ENCRYPTION_KEY=$(openssl rand -base64 32)
log_info "Generated encryption key for cluster storage"
fi
# Start with air (hot-reload) or fall back to go run
AIR_BIN=$(command -v air 2>/dev/null || echo "$HOME/go/bin/air")
if [ -x "$AIR_BIN" ]; then
KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}" \
VELERO_NAMESPACE="${VELERO_NAMESPACE:-velero}" \
CLUSTER_STORAGE_TYPE="${CLUSTER_STORAGE_TYPE:-sqlite}" \
CLUSTER_DB_PATH="${CLUSTER_DB_PATH:-./clusters.db}" \
CLUSTER_ENCRYPTION_KEY="$CLUSTER_ENCRYPTION_KEY" \
SERVER_PORT=8080 \
SERVER_ALLOWED_ORIGINS="http://localhost:3000,http://localhost:3001" \
$AIR_BIN &
log_success "Backend started with hot-reload (air) on :8080"
else
log_warn "air not found. Install with: go install github.com/air-verse/air@latest"
log_info "Falling back to go run..."
KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}" \
VELERO_NAMESPACE="${VELERO_NAMESPACE:-velero}" \
CLUSTER_STORAGE_TYPE="${CLUSTER_STORAGE_TYPE:-sqlite}" \
CLUSTER_DB_PATH="${CLUSTER_DB_PATH:-./clusters.db}" \
CLUSTER_ENCRYPTION_KEY="$CLUSTER_ENCRYPTION_KEY" \
SERVER_PORT=8080 \
SERVER_ALLOWED_ORIGINS="http://localhost:3000,http://localhost:3001" \
go run ./cmd/server &
log_success "Backend started on :8080 (no hot-reload)"
fi
cd "$SCRIPT_DIR"
}
function start_frontend() {
log_info "Starting Frontend (Hot-Reload)..."
cd "$SCRIPT_DIR/frontend"
# Kill existing frontend process
pkill -f "next dev.*velero" 2>/dev/null || true
# Install deps if needed
if [ ! -d "node_modules" ]; then
log_info "Installing frontend dependencies..."
npm install
fi
# Start Next.js dev server
BACKEND_URL="http://localhost:8080" npm run dev -- --port 3001 &
log_success "Frontend started with hot-reload (Next.js dev) on :3001"
cd "$SCRIPT_DIR"
}
function stop_all() {
log_info "Stopping all Velero Dashboard services..."
# Stop backend
pkill -f "velero-dashboard" 2>/dev/null && log_success "Backend stopped" || true
pkill -f "tmp/main" 2>/dev/null || true
pkill -f "air" 2>/dev/null || true
# Stop frontend
pkill -f "next dev.*3001" 2>/dev/null && log_success "Frontend stopped" || true
}
function show_status() {
echo ""
log_info "Velero Dashboard - Service Status:"
echo ""
# Backend
if pgrep -f "tmp/main" > /dev/null 2>&1 || pgrep -f "velero-dashboard" > /dev/null 2>&1; then
echo -e " ${GREEN}●${NC} Backend: Running (http://localhost:8080)"
echo -e " ${GREEN}●${NC} API: http://localhost:8080/api/dashboard/stats"
echo -e " ${GREEN}●${NC} Health: http://localhost:8080/healthz"
else
echo -e " ${RED}●${NC} Backend: Stopped"
fi
# Frontend
if pgrep -f "next dev" > /dev/null 2>&1; then
echo -e " ${GREEN}●${NC} Frontend: Running (http://localhost:3001)"
else
echo -e " ${RED}●${NC} Frontend: Stopped"
fi
# Kubernetes connectivity
if kubectl get ns velero &> /dev/null; then
echo -e " ${GREEN}●${NC} Kubernetes: Connected (velero namespace exists)"
BACKUP_COUNT=$(kubectl get backups.velero.io -n velero --no-headers 2>/dev/null | wc -l)
echo -e " ${GREEN}●${NC} Backups: ${BACKUP_COUNT} found"
else
echo -e " ${YELLOW}●${NC} Kubernetes: Not connected or velero namespace not found"
fi
echo ""
}
function run_tests() {
log_info "Running all tests..."
echo ""
log_info "Backend tests:"
cd "$SCRIPT_DIR/backend"
go test ./... -v
BACKEND_RESULT=$?
cd "$SCRIPT_DIR"
echo ""
log_info "Frontend tests:"
cd "$SCRIPT_DIR/frontend"
npx vitest run
FRONTEND_RESULT=$?
cd "$SCRIPT_DIR"
echo ""
if [ $BACKEND_RESULT -eq 0 ] && [ $FRONTEND_RESULT -eq 0 ]; then
log_success "All tests passed!"
else
log_error "Some tests failed"
exit 1
fi
}
# Main
case "$1" in
backend)
check_deps
start_backend
sleep 2
show_status
log_success "Backend development mode started!"
log_info "Backend will auto-reload on file changes (if air installed)"
;;
frontend)
check_deps
start_frontend
sleep 2
show_status
log_success "Frontend development mode started!"
log_info "Frontend will auto-reload on file changes"
;;
all)
check_deps
start_backend
sleep 2
start_frontend
sleep 3
show_status
log_success "All services started in development mode!"
log_info "Changes will auto-reload for both backend and frontend"
echo ""
log_info "Frontend: http://localhost:3001"
log_info "Backend: http://localhost:8080"
log_info "API: http://localhost:8080/api/dashboard/stats"
;;
stop)
stop_all
show_status
log_success "All services stopped"
;;
status)
show_status
;;
test)
check_deps
run_tests
;;
*)
echo "Velero Dashboard Development Script"
echo ""
echo "Usage: $0 {backend|frontend|all|stop|status|test}"
echo ""
echo "Commands:"
echo " backend - Start Backend with hot-reload (air)"
echo " frontend - Start Frontend with hot-reload (Next.js)"
echo " all - Start all services with hot-reload"
echo " stop - Stop all services"
echo " status - Show service status"
echo " test - Run all tests (Go + Vitest)"
echo ""
echo "Environment:"
echo " KUBECONFIG Path to kubeconfig (default: ~/.kube/config) - For auto-migration"
echo " VELERO_NAMESPACE Velero namespace (default: velero) - For auto-migration"
echo " CLUSTER_STORAGE_TYPE Storage type: sqlite/kubernetes (default: sqlite)"
echo " CLUSTER_DB_PATH SQLite DB path (default: ./clusters.db)"
echo " CLUSTER_ENCRYPTION_KEY 32-byte encryption key (auto-generated if not set)"
echo ""
echo "Multi-Cluster Support:"
echo " If KUBECONFIG is set and no clusters exist in DB, a default cluster will be auto-created."
echo " Otherwise, add clusters via the UI at http://localhost:3001/clusters"
echo ""
echo "Examples:"
echo " $0 all # Start everything with auto-migration"
echo " VELERO_NAMESPACE=backup $0 backend # Custom namespace"
echo " $0 test # Run all tests"
exit 1
;;
esac