Chore: update environment configuration for local development; modify Dockerfile to streamline SDK installation and enhance startup script for better directory handling; add time verification script for system time synchronization
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# Web environment (Vite)
|
# Web environment (Vite)
|
||||||
VITE_SUPABASE_URL=http://127.0.0.1:54321
|
VITE_SUPABASE_URL=http://localhost:54321
|
||||||
VITE_SUPABASE_ANON_KEY=[REDACTED]
|
VITE_SUPABASE_ANON_KEY=[REDACTED]
|
||||||
|
|
||||||
# API config (optional)
|
# API config (optional)
|
||||||
|
|||||||
@@ -3,23 +3,17 @@ FROM python:3.11-slim
|
|||||||
|
|
||||||
# Install system dependencies required by SDK and tooling
|
# Install system dependencies required by SDK and tooling
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
bash ca-certificates tar \
|
bash ca-certificates tar sudo \
|
||||||
libusb-1.0-0 libgl1 libx11-6 libxext6 libxcb1 libgtk-3-0 \
|
libusb-1.0-0 libgl1 libx11-6 libxext6 libxcb1 libgtk-3-0 \
|
||||||
|
libusb-1.0-0-dev udev \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Copy SDK bundle placed under api/camera_sdk and install native libs
|
# Set working directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY camera_sdk /tmp/camera_sdk
|
|
||||||
|
|
||||||
RUN set -eux; \
|
# Set environment variables for library paths and Python path
|
||||||
mkdir -p /opt/mvsdk; \
|
ENV LD_LIBRARY_PATH=/usr/lib:/usr/local/lib:/lib
|
||||||
TARBALL="$(find /tmp/camera_sdk -maxdepth 1 -type f -name '*.tar.gz' | head -n1)"; \
|
ENV PYTHONPATH=/app:/app/camera_sdk
|
||||||
if [ -z "$TARBALL" ]; then echo 'No SDK .tar.gz found in camera_sdk'; exit 1; fi; \
|
|
||||||
tar -xzf "$TARBALL" -C /opt/mvsdk || true; \
|
|
||||||
# Copy any .so library files into /usr/lib so ctypes can load libMVSDK.so
|
|
||||||
find /opt/mvsdk -type f -name '*.so*' -exec cp -n {} /usr/lib/ \; || true; \
|
|
||||||
ldconfig || true
|
|
||||||
|
|
||||||
ENV LD_LIBRARY_PATH=/usr/lib:/usr/local/lib
|
# The actual app code and SDK will be bind-mounted by docker-compose at runtime
|
||||||
|
# SDK installation will be handled in the docker-compose command
|
||||||
# The actual app code is bind-mounted by docker-compose at runtime
|
|
||||||
|
|||||||
58
camera-management-api/check_time.py
Executable file
58
camera-management-api/check_time.py
Executable file
@@ -0,0 +1,58 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Time verification script for USDA Vision Camera System
|
||||||
|
Checks if system time is properly synchronized
|
||||||
|
"""
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
import pytz
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
|
def check_system_time():
|
||||||
|
"""Check system time against multiple sources"""
|
||||||
|
print("🕐 USDA Vision Camera System - Time Verification")
|
||||||
|
print("=" * 50)
|
||||||
|
|
||||||
|
# Get local time
|
||||||
|
local_time = datetime.datetime.now()
|
||||||
|
utc_time = datetime.datetime.utcnow()
|
||||||
|
|
||||||
|
# Get Atlanta timezone
|
||||||
|
atlanta_tz = pytz.timezone('America/New_York')
|
||||||
|
atlanta_time = datetime.datetime.now(atlanta_tz)
|
||||||
|
|
||||||
|
print(f"Local system time: {local_time}")
|
||||||
|
print(f"UTC time: {utc_time}")
|
||||||
|
print(f"Atlanta time: {atlanta_time}")
|
||||||
|
print(f"Timezone: {atlanta_time.tzname()}")
|
||||||
|
|
||||||
|
# Check against world time API
|
||||||
|
try:
|
||||||
|
print("\n🌐 Checking against world time API...")
|
||||||
|
response = requests.get("http://worldtimeapi.org/api/timezone/America/New_York", timeout=5)
|
||||||
|
if response.status_code == 200:
|
||||||
|
data = response.json()
|
||||||
|
api_time = datetime.datetime.fromisoformat(data['datetime'].replace('Z', '+00:00'))
|
||||||
|
|
||||||
|
# Compare times (allow 5 second difference)
|
||||||
|
time_diff = abs((atlanta_time.replace(tzinfo=None) - api_time.replace(tzinfo=None)).total_seconds())
|
||||||
|
|
||||||
|
print(f"API time: {api_time}")
|
||||||
|
print(f"Time difference: {time_diff:.2f} seconds")
|
||||||
|
|
||||||
|
if time_diff < 5:
|
||||||
|
print("✅ Time is synchronized (within 5 seconds)")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print("❌ Time is NOT synchronized (difference > 5 seconds)")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
print("⚠️ Could not reach time API")
|
||||||
|
return None
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Error checking time API: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
check_system_time()
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"mqtt": {
|
"mqtt": {
|
||||||
"broker_host": "mqtt",
|
"broker_host": "192.168.1.110",
|
||||||
"broker_port": 1883,
|
"broker_port": 1883,
|
||||||
"username": null,
|
"username": null,
|
||||||
"password": null,
|
"password": null,
|
||||||
@@ -89,5 +89,4 @@
|
|||||||
"hdr_gain_mode": 0
|
"hdr_gain_mode": 0
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4,6 +4,11 @@
|
|||||||
|
|
||||||
echo "USDA Vision Camera System - Startup Script"
|
echo "USDA Vision Camera System - Startup Script"
|
||||||
echo "=========================================="
|
echo "=========================================="
|
||||||
|
# Ensure we are running from the script directory
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
cd "$SCRIPT_DIR"
|
||||||
|
echo "📂 Working directory: $SCRIPT_DIR"
|
||||||
|
|
||||||
|
|
||||||
# Check if virtual environment exists
|
# Check if virtual environment exists
|
||||||
if [ ! -d ".venv" ]; then
|
if [ ! -d ".venv" ]; then
|
||||||
@@ -14,6 +19,9 @@ fi
|
|||||||
# Activate virtual environment
|
# Activate virtual environment
|
||||||
echo "🔧 Activating virtual environment..."
|
echo "🔧 Activating virtual environment..."
|
||||||
source .venv/bin/activate
|
source .venv/bin/activate
|
||||||
|
# Ensure project root is on PYTHONPATH for imports
|
||||||
|
export PYTHONPATH="$SCRIPT_DIR:$PYTHONPATH"
|
||||||
|
|
||||||
|
|
||||||
# Check if config file exists
|
# Check if config file exists
|
||||||
if [ ! -f "config.json" ]; then
|
if [ ! -f "config.json" ]; then
|
||||||
@@ -30,11 +38,11 @@ fi
|
|||||||
|
|
||||||
# Check time synchronization
|
# Check time synchronization
|
||||||
echo "🕐 Checking time synchronization..."
|
echo "🕐 Checking time synchronization..."
|
||||||
python check_time.py
|
python tests/core/check_time.py
|
||||||
echo ""
|
echo ""
|
||||||
# Run system tests first
|
# Run system tests first
|
||||||
echo "🧪 Running system tests..."
|
echo "🧪 Running system tests..."
|
||||||
python test_system.py
|
python tests/integration/test_system.py
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "❌ System tests failed. Please check the configuration."
|
echo "❌ System tests failed. Please check the configuration."
|
||||||
|
|||||||
@@ -11,18 +11,36 @@ services:
|
|||||||
- ./camera-management-api/storage:/storage
|
- ./camera-management-api/storage:/storage
|
||||||
environment:
|
environment:
|
||||||
- PYTHONUNBUFFERED=1
|
- PYTHONUNBUFFERED=1
|
||||||
- LD_LIBRARY_PATH=/usr/local/lib:/app/camera_sdk/lib
|
- LD_LIBRARY_PATH=/usr/local/lib:/lib:/usr/lib
|
||||||
|
- PYTHONPATH=/app:/app/camera_sdk
|
||||||
command: >
|
command: >
|
||||||
sh -lc "
|
sh -lc "
|
||||||
apt-get update && apt-get install -y libusb-1.0-0-dev;
|
apt-get update && apt-get install -y libusb-1.0-0-dev;
|
||||||
if [ -d camera_sdk/lib ]; then cp camera_sdk/lib/* /usr/local/lib/ 2>/dev/null || true; fi;
|
|
||||||
if [ -f requirements.txt ]; then pip install --no-cache-dir -r requirements.txt; else pip install --no-cache-dir -e .; fi;
|
# Install camera SDK if not already installed
|
||||||
|
if [ ! -f /lib/libMVSDK.so ] && [ -f 'camera_sdk/linuxSDK_V2.1.0.49(250108)/install.sh' ]; then
|
||||||
|
echo 'Installing camera SDK...';
|
||||||
|
cd 'camera_sdk/linuxSDK_V2.1.0.49(250108)';
|
||||||
|
chmod +x install.sh;
|
||||||
|
./install.sh;
|
||||||
|
cd /app;
|
||||||
|
echo 'Camera SDK installed successfully';
|
||||||
|
else
|
||||||
|
echo 'Camera SDK already installed or install script not found';
|
||||||
|
fi;
|
||||||
|
|
||||||
|
# Install Python dependencies
|
||||||
|
if [ -f requirements.txt ]; then
|
||||||
|
pip install --no-cache-dir -r requirements.txt;
|
||||||
|
else
|
||||||
|
pip install --no-cache-dir -e .;
|
||||||
|
fi;
|
||||||
|
|
||||||
|
# Start the application
|
||||||
python main.py --config config.compose.json
|
python main.py --config config.compose.json
|
||||||
"
|
"
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
depends_on:
|
|
||||||
- mqtt
|
|
||||||
|
|
||||||
web:
|
web:
|
||||||
image: node:20-alpine
|
image: node:20-alpine
|
||||||
@@ -36,19 +54,9 @@ services:
|
|||||||
command: >
|
command: >
|
||||||
sh -lc "
|
sh -lc "
|
||||||
npm ci;
|
npm ci;
|
||||||
npm run dev -- --host 0.0.0.0 --port 5173
|
npm run dev -- --host 0.0.0.0 --port 8080
|
||||||
"
|
"
|
||||||
ports:
|
ports:
|
||||||
- "5173:5173"
|
- "8080:8080"
|
||||||
|
|
||||||
mqtt:
|
|
||||||
image: eclipse-mosquitto:2
|
|
||||||
ports:
|
|
||||||
- "1883:1883"
|
|
||||||
volumes:
|
|
||||||
- mosquitto-data:/mosquitto/data
|
|
||||||
- mosquitto-conf:/mosquitto/config
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
mosquitto-data:
|
|
||||||
mosquitto-conf:
|
|
||||||
|
|||||||
@@ -4,7 +4,14 @@ import tailwindcss from '@tailwindcss/vite'
|
|||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react(),
|
plugins: [
|
||||||
tailwindcss(),
|
react(),
|
||||||
|
tailwindcss(),
|
||||||
],
|
],
|
||||||
|
server: {
|
||||||
|
// Allow connecting via this VM's hostname
|
||||||
|
allowedHosts: ['exp-dash'],
|
||||||
|
// host is provided via CLI in docker-compose, but keeping this commented for local use:
|
||||||
|
// host: true,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user