-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
executable file
·145 lines (119 loc) · 3.55 KB
/
docker-entrypoint.sh
File metadata and controls
executable file
·145 lines (119 loc) · 3.55 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
#!/bin/bash
# FlowState Docker Entrypoint Script
# Handles initialization and runtime configuration
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Logging functions
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Initialize directories
init_directories() {
log_info "Initializing directories..."
# Create required directories if they don't exist
mkdir -p "${FLOWSTATE_OUTPUT_DIR:-/app/output}"
mkdir -p "${FLOWSTATE_LOG_DIR:-/app/logs}"
mkdir -p "${FLOWSTATE_TEMP_DIR:-/tmp/flowstate}"
mkdir -p "${FLOWSTATE_CACHE_DIR:-/tmp/flowstate/cache}"
# Ensure proper permissions
if [ -w "${FLOWSTATE_OUTPUT_DIR}" ]; then
log_info "Output directory is writable"
else
log_error "Output directory is not writable: ${FLOWSTATE_OUTPUT_DIR}"
exit 1
fi
}
# Validate environment
validate_environment() {
log_info "Validating environment..."
# Check Python
if ! python --version &> /dev/null; then
log_error "Python is not available"
exit 1
fi
# Check ffmpeg
if ! ffmpeg -version &> /dev/null; then
log_error "FFmpeg is not available"
exit 1
fi
# Test imports
if ! python -c "import torch, ultralytics, cv2, numpy" &> /dev/null; then
log_error "Required Python packages (torch, ultralytics, etc.) are not available"
exit 1
fi
# Check flowstate command
if ! command -v flowstate &> /dev/null; then
log_error "flowstate command not found"
exit 1
fi
log_info "Environment validation passed"
}
# Handle special commands
handle_special_commands() {
case "$1" in
"test"|"validate")
log_info "Running validation tests..."
python -m pytest /app/tests/ -v
exit $?
;;
"shell"|"bash")
log_info "Starting interactive shell..."
exec /bin/bash
;;
"server"|"serve")
log_info "Starting FlowState web server..."
shift # Remove the 'server' command
exec python -m src.core.server "$@"
;;
esac
}
# Performance tuning
tune_performance() {
log_info "Applying performance optimizations..."
# Set OpenMP threads if not already set
if [ -z "$OMP_NUM_THREADS" ]; then
CORES=$(nproc --all)
export OMP_NUM_THREADS=$((CORES > 4 ? 4 : CORES))
log_info "Set OMP_NUM_THREADS to $OMP_NUM_THREADS"
fi
# Enable OpenCV optimizations
export OPENCV_OPENCL_RUNTIME=1
export OPENCV_OPENCL_DEVICE=disabled # CPU-only for consistency
}
# Main execution
main() {
log_info "FlowState Docker Container Starting..."
log_info "Version: $(flowstate --version 2>/dev/null || echo 'unknown')"
# Initialize
init_directories
validate_environment
tune_performance
# Handle special commands
handle_special_commands "$1"
# Check if no arguments provided
if [ $# -eq 0 ]; then
log_warn "No command provided. Showing help..."
exec flowstate --help
fi
# Handle 'analyze' as a compatibility wrapper
if [ "$1" = "analyze" ]; then
log_info "Removing 'analyze' command for compatibility..."
shift # Remove 'analyze' from arguments
fi
# Log the command being executed
log_info "Executing: flowstate $*"
# Execute flowstate with all arguments
exec flowstate "$@"
}
# Run main function with all arguments
main "$@"