-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdev-run.sh
More file actions
executable file
·104 lines (80 loc) · 3.25 KB
/
dev-run.sh
File metadata and controls
executable file
·104 lines (80 loc) · 3.25 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
#!/bin/bash
# Developer startup script with continuous logs
echo "==== BESS Manager Development Environment Setup ===="
# Verify Docker is running
if ! docker info > /dev/null 2>&1; then
echo "Error: Docker is not running."
echo "Please start Docker and try again."
exit 1
fi
# Check if .env exists, if not prompt the user
if [ ! -f .env ]; then
echo "Error: .env file not found."
echo "Please create a .env file with HA_URL and HA_TOKEN defined."
exit 1
fi
# Export environment variables from .env file (excluding comments and empty lines)
echo "Loading environment variables from .env..."
set -a # automatically export all variables
source <(grep -v '^#' .env | grep -v '^$' | sed 's/^\s*//')
set +a # stop automatically exporting
# Display which HA instance we're connecting to
echo "Connecting to Home Assistant at: $HA_URL"
# Check if token is still the default
if [[ "$HA_TOKEN" == "your_long_lived_access_token_here" ]]; then
echo "Please edit .env file to add your Home Assistant token."
exit 1
fi
# Ensure requirements.txt exists with needed packages
echo "Checking requirements.txt..."
if [ ! -f backend/requirements.txt ]; then
echo "Please create requirements.txt in backend directory..."
exit 1
fi
# Extract options from config.yaml to backend/dev-options.json for development
# Note: InfluxDB credentials are passed as environment variables, not in options.json
echo "Extracting development options from config.yaml..."
if [ -f config.yaml ]; then
./.venv/bin/python << 'EOF'
import yaml
import json
with open('config.yaml', 'r') as f:
config = yaml.safe_load(f)
options = config.get('options', {})
# Remove InfluxDB from options - credentials come from environment variables
if 'influxdb' in options:
del options['influxdb']
print(" → InfluxDB credentials will be loaded from environment variables")
with open('backend/dev-options.json', 'w') as f:
json.dump(options, f, indent=2)
print("✓ Created backend/dev-options.json (simulates /data/options.json in HA)")
EOF
else
echo "Warning: config.yaml not found in root directory"
fi
# Create dev settings from example template if missing (file is gitignored)
if [ ! -f backend/dev-bess-settings.json ]; then
cp backend/dev-bess-settings.json.example backend/dev-bess-settings.json
echo "✓ Created backend/dev-bess-settings.json from example template"
fi
# Pass host timezone to containers so log timestamps use local time
export TZ=${TZ:-Europe/Stockholm}
echo "Stopping any existing containers..."
docker-compose down --remove-orphans
echo "Removing any existing containers to force rebuild..."
docker-compose rm -f
echo "Building frontend..."
(cd frontend && npm run build)
echo "Building and starting development container with Python 3.10..."
docker-compose up --build -d
# Wait a moment for container to be ready
echo "Waiting for container to start..."
sleep 5
echo -e "\n==== CHECKING PYTHON VERSION IN CONTAINER ===="
docker-compose exec bess-dev python --version
echo -e "\n==== INITIAL CONTAINER LOGS ===="
docker-compose logs --no-log-prefix
echo -e "\nAccess the web interface at http://localhost:8080 once the app is running correctly."
echo -e "Following container logs now... (Press Ctrl+C to stop)\n"
# Follow the logs continuously
docker-compose logs -f --no-log-prefix