-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset-docker.sh
More file actions
executable file
·157 lines (135 loc) · 6.33 KB
/
Copy pathreset-docker.sh
File metadata and controls
executable file
·157 lines (135 loc) · 6.33 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
#!/bin/bash
echo "🔄 Resetting Docker containers and volumes..."
echo ""
# Stop all containers
echo "1️⃣ Stopping all containers..."
docker-compose down
# Remove volumes to clear database and media
echo "2️⃣ Removing volumes (this will delete the database and media files)..."
docker volume rm nur-cityscope_postgres_data_core nur-cityscope_media_files nur-cityscope_nur-api_data 2>/dev/null || echo " (Some volumes may not exist, that's okay)"
# Remove the initialization flag from the data directory (if it exists locally)
echo "3️⃣ Removing initialization flags..."
rm -rf nur-io/django_api/data/db_initialized nur-io/django_api/data/assets_checksum 2>/dev/null || echo " (Flags don't exist locally, that's okay)"
# Prune unused Docker images only (keeps all containers, including unrelated ones like n8n)
echo "4️⃣ Pruning unused Docker images (containers will be kept)..."
docker image prune -f
echo ""
echo "✅ Reset complete!"
echo ""
# Process layer packs (before starting containers)
echo "5️⃣ Setting up OTEF layer packs..."
VENV_PATH="otef-interactive/scripts/.venv"
if [ ! -d "$VENV_PATH" ]; then
echo " Creating Python virtual environment..."
python3 -m venv "$VENV_PATH"
fi
# Ensure dependencies are installed
echo " Ensuring dependencies are installed..."
"$VENV_PATH/bin/python" -m pip install -q -r "otef-interactive/scripts/requirements.txt"
# Fetch source layers if needed
echo " Fetching source layers if needed..."
"$VENV_PATH/bin/python" "otef-interactive/scripts/fetch_data.py" --output "otef-interactive/public/source"
if docker info >/dev/null 2>&1; then
MANIFEST_PATH="otef-interactive/public/processed/layers/layers-manifest.json"
# Only process if manifest doesn't exist or is older than source files
SHOULD_PROCESS=true
if [ -f "$MANIFEST_PATH" ]; then
MANIFEST_TIME=$(stat -f "%m" "$MANIFEST_PATH" 2>/dev/null || stat -c "%Y" "$MANIFEST_PATH" 2>/dev/null || echo "0")
SOURCE_DIR="otef-interactive/public/source/layers"
# Check if any source files are newer than manifest
if [ -d "$SOURCE_DIR" ]; then
NEWER_FILES=$(find "$SOURCE_DIR" -type f -newer "$MANIFEST_PATH" 2>/dev/null | wc -l)
if [ "$NEWER_FILES" -eq 0 ]; then
echo " Layer packs already processed (manifest up to date), skipping..."
SHOULD_PROCESS=false
fi
fi
fi
if [ "$SHOULD_PROCESS" = true ]; then
echo " Processing layer packs (process_layers.py)..."
"$VENV_PATH/bin/python" "otef-interactive/scripts/process_layers.py" \
--source "otef-interactive/public/source/layers" \
--output "otef-interactive/public/processed/layers"
fi
else
echo " Warning: Docker not running, skipping layer pack processing"
fi
# Ensure OTEF frontend dependencies (for tests and dev)
echo "6️⃣ Ensuring OTEF frontend dependencies..."
if command -v npm >/dev/null 2>&1; then
echo " Installing OTEF frontend dependencies (npm install)..."
npm install --prefix "otef-interactive"
else
echo " Warning: npm not found, skipping otef-interactive deps (run 'npm install' in otef-interactive manually)"
fi
echo "7️⃣ Rebuilding and starting containers..."
COMPOSE_BAKE=true docker-compose up --build -d
echo "8️⃣ Waiting for API and seeding database..."
sleep 15
echo " Running migrations..."
docker exec nur-api python manage.py migrate
echo " Creating data structure (states, indicator data, images)..."
docker exec nur-api python manage.py create_data
echo " Importing OTEF data (layer groups, model bounds)..."
docker exec nur-api python manage.py import_otef_data || echo " (OTEF import skipped if files not present)"
echo ""
echo "✅ All done! Containers are running in the background."
echo ""
# Get local IP address
get_local_ip() {
# Try different methods to get the local IP
if [ "$(uname)" = "Darwin" ]; then
# macOS: Get the default interface and its IP
local default_if=$(route get default 2>/dev/null | grep interface | awk '{print $2}')
if [ -n "$default_if" ]; then
local ip=$(ipconfig getifaddr "$default_if" 2>/dev/null)
if [ -n "$ip" ] && [ "$ip" != "127.0.0.1" ]; then
echo "$ip"
return
fi
fi
# Fallback: try common interfaces
for iface in en0 en1 en2 en3; do
local ip=$(ipconfig getifaddr "$iface" 2>/dev/null)
if [ -n "$ip" ] && [ "$ip" != "127.0.0.1" ]; then
echo "$ip"
return
fi
done
# Last resort: use ifconfig to find first non-loopback IPv4
ifconfig 2>/dev/null | grep -E "inet [0-9]" | grep -v "127.0.0.1" | awk '{print $2}' | head -1 | grep -v "^$"
elif command -v ip >/dev/null 2>&1; then
ip route get 1.1.1.1 2>/dev/null | awk '{print $7; exit}' | grep -v "^$"
elif command -v hostname >/dev/null 2>&1; then
hostname -I 2>/dev/null | awk '{print $1}' | grep -v "^$"
fi
}
LOCAL_IP=$(get_local_ip)
echo "📍 Local access (localhost):"
echo "- Dashboard: http://localhost/dashboard/"
echo "- Projection: http://localhost/projection/"
echo "- Remote Controller: http://localhost/remote/"
echo "- OTEF Interactive: http://localhost/otef-interactive/"
echo "- OTEF Remote: http://localhost/otef-interactive/remote-controller.html"
echo "- OTEF Projection: http://localhost/otef-interactive/projection.html"
echo "- OTEF Curation: http://localhost/otef-interactive/curation.html"
echo "- Admin Interface: http://localhost:9900/admin"
if [ -n "$LOCAL_IP" ]; then
echo ""
echo "🌐 Network access (from other devices):"
echo "- Dashboard: http://$LOCAL_IP/dashboard/"
echo "- Projection: http://$LOCAL_IP/projection/"
echo "- Remote Controller: http://$LOCAL_IP/remote/"
echo "- OTEF Interactive: http://$LOCAL_IP/otef-interactive/"
echo "- OTEF Remote: http://$LOCAL_IP/otef-interactive/remote-controller.html"
echo "- OTEF Projection: http://$LOCAL_IP/otef-interactive/projection.html"
echo "- OTEF Curation: http://$LOCAL_IP/otef-interactive/curation.html"
echo "- Admin Interface: http://$LOCAL_IP:9900/admin"
else
echo ""
echo "⚠️ Could not detect local IP address for network access"
fi
echo ""
echo "View logs with: docker-compose logs -f"
echo "Stop containers with: docker-compose down"
echo ""