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:
salirezav
2025-08-08 16:18:37 -04:00
parent 20907509b1
commit 7a939920fa
7 changed files with 113 additions and 39 deletions

View File

@@ -1,5 +1,5 @@
# Web environment (Vite)
VITE_SUPABASE_URL=http://127.0.0.1:54321
VITE_SUPABASE_URL=http://localhost:54321
VITE_SUPABASE_ANON_KEY=[REDACTED]
# API config (optional)

View File

@@ -3,23 +3,17 @@ FROM python:3.11-slim
# Install system dependencies required by SDK and tooling
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-dev udev \
&& rm -rf /var/lib/apt/lists/*
# Copy SDK bundle placed under api/camera_sdk and install native libs
# Set working directory
WORKDIR /app
COPY camera_sdk /tmp/camera_sdk
RUN set -eux; \
mkdir -p /opt/mvsdk; \
TARBALL="$(find /tmp/camera_sdk -maxdepth 1 -type f -name '*.tar.gz' | head -n1)"; \
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
# Set environment variables for library paths and Python path
ENV LD_LIBRARY_PATH=/usr/lib:/usr/local/lib:/lib
ENV PYTHONPATH=/app:/app/camera_sdk
ENV LD_LIBRARY_PATH=/usr/lib:/usr/local/lib
# The actual app code is bind-mounted by docker-compose at runtime
# 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

View 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()

View File

@@ -1,6 +1,6 @@
{
"mqtt": {
"broker_host": "mqtt",
"broker_host": "192.168.1.110",
"broker_port": 1883,
"username": null,
"password": null,
@@ -89,5 +89,4 @@
"hdr_gain_mode": 0
}
]
}
}

View File

@@ -4,6 +4,11 @@
echo "USDA Vision Camera System - Startup Script"
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
if [ ! -d ".venv" ]; then
@@ -14,6 +19,9 @@ fi
# Activate virtual environment
echo "🔧 Activating virtual environment..."
source .venv/bin/activate
# Ensure project root is on PYTHONPATH for imports
export PYTHONPATH="$SCRIPT_DIR:$PYTHONPATH"
# Check if config file exists
if [ ! -f "config.json" ]; then
@@ -30,11 +38,11 @@ fi
# Check time synchronization
echo "🕐 Checking time synchronization..."
python check_time.py
python tests/core/check_time.py
echo ""
# Run system tests first
echo "🧪 Running system tests..."
python test_system.py
python tests/integration/test_system.py
if [ $? -ne 0 ]; then
echo "❌ System tests failed. Please check the configuration."

View File

@@ -11,18 +11,36 @@ services:
- ./camera-management-api/storage:/storage
environment:
- 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: >
sh -lc "
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
"
ports:
- "8000:8000"
depends_on:
- mqtt
web:
image: node:20-alpine
@@ -36,19 +54,9 @@ services:
command: >
sh -lc "
npm ci;
npm run dev -- --host 0.0.0.0 --port 5173
npm run dev -- --host 0.0.0.0 --port 8080
"
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:

View File

@@ -4,7 +4,14 @@ import tailwindcss from '@tailwindcss/vite'
// https://vite.dev/config/
export default defineConfig({
plugins: [react(),
tailwindcss(),
plugins: [
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,
},
})