-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup.sh
More file actions
114 lines (96 loc) · 3.91 KB
/
Copy pathsetup.sh
File metadata and controls
114 lines (96 loc) · 3.91 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
#!/usr/bin/env bash
# setup.sh — one-shot script to boot the Django backend + PostgreSQL via Docker
# Compose, then launch the Vite frontend dev server.
#
# Usage:
# chmod +x setup.sh && ./setup.sh
#
# Prerequisites: docker (with compose plugin), node, npm
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# ── prerequisite checks ──────────────────────────────────────────────────────
check() {
command -v "$1" >/dev/null 2>&1 || { echo "ERROR: '$1' is required but not installed."; exit 1; }
}
check docker
check node
check npm
# Detect 'docker compose' (plugin) vs older 'docker-compose' (standalone).
if docker compose version >/dev/null 2>&1; then
COMPOSE="docker compose"
elif command -v docker-compose >/dev/null 2>&1; then
COMPOSE="docker-compose"
else
echo "ERROR: Docker Compose not found. Install the Docker Compose plugin."
exit 1
fi
# ── backend ───────────────────────────────────────────────────────────────────
echo ""
echo "==> Building and starting Docker services (PostgreSQL + Django)..."
$COMPOSE up --build -d
echo ""
echo "==> Waiting for Django to be ready (migrations + seed run inside the container)..."
ATTEMPTS=0
MAX_ATTEMPTS=60
until curl -sf http://localhost:8000/api/employees/ >/dev/null 2>&1; do
ATTEMPTS=$((ATTEMPTS + 1))
if [ "$ATTEMPTS" -ge "$MAX_ATTEMPTS" ]; then
echo ""
echo "ERROR: Backend did not become ready after ${MAX_ATTEMPTS} attempts."
echo " Check logs with: $COMPOSE logs backend"
exit 1
fi
printf '.'
sleep 2
done
echo ""
echo "==> Backend ready at http://localhost:8000"
echo " API root: http://localhost:8000/api/"
echo " Employees: http://localhost:8000/api/employees/"
echo ""
# ── Angular frontend ──────────────────────────────────────────────────────────
echo "==> Installing Angular frontend dependencies..."
cd "$SCRIPT_DIR/frontend-angular"
npm install
echo ""
echo "==> Building Angular app (first build)..."
npm run build
echo ""
echo "==> Starting Angular build watcher in background..."
npm run watch &
ANGULAR_WATCH_PID=$!
# ── React frontend ────────────────────────────────────────────────────────────
echo ""
echo "==> Installing React frontend dependencies..."
cd "$SCRIPT_DIR/frontend-react"
npm install
echo ""
echo "==> Building React app (first build)..."
npm run build
echo ""
echo "==> Starting React build watcher in background..."
npm run watch &
REACT_WATCH_PID=$!
# ── Vite frontend ─────────────────────────────────────────────────────────────
echo ""
echo "==> Installing frontend dependencies..."
cd "$SCRIPT_DIR/frontend"
npm install
echo ""
echo "========================================================"
echo " Handsontable — Server-side Django Example"
echo "========================================================"
echo " Frontend (JS) : http://localhost:5173"
echo " Frontend (Angular) : http://localhost:5173/angular.html"
echo " Frontend (React) : http://localhost:5173/react.html"
echo " Backend : http://localhost:8000/api/employees/"
echo ""
echo " Press Ctrl+C to stop the frontend dev server."
echo " Run '$COMPOSE down' to stop Docker."
echo "========================================================"
echo ""
npm run dev
# Cleanup watchers when Vite exits
kill "$ANGULAR_WATCH_PID" 2>/dev/null || true
kill "$REACT_WATCH_PID" 2>/dev/null || true