-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
148 lines (131 loc) · 5.93 KB
/
Makefile
File metadata and controls
148 lines (131 loc) · 5.93 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
.PHONY: demo build setup-env clean help start-web start-workers start-full list-videos
# Default variables
DOCKER_IMAGE ?= video-processor:latest
DOCKER_IMAGE_CPU ?= video-processor:cpu
DEMO_VIDEO ?= $(shell find sample-videos -name "*.mp4" 2>/dev/null | head -1)
ENV_FILE ?= .env.local
# Auto-detect GPU availability (can be overridden with FORCE_CPU=true)
HAS_GPU := $(shell command -v nvidia-smi >/dev/null 2>&1 && nvidia-smi -L 2>/dev/null | grep -q "GPU" && echo "true" || echo "false")
HAS_NVIDIA_DOCKER := $(shell docker info 2>/dev/null | grep -q "nvidia" && echo "true" || echo "false")
# Determine which setup to use
ifeq ($(FORCE_CPU),true)
USE_GPU_SETUP := false
else ifeq ($(HAS_GPU),true)
ifeq ($(HAS_NVIDIA_DOCKER),true)
USE_GPU_SETUP := true
else
USE_GPU_SETUP := false
endif
else
USE_GPU_SETUP := false
endif
help: ## Show this help message
@echo "Available targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "System detection:"
@echo " GPU detected: $(HAS_GPU)"
@echo " Nvidia Docker: $(HAS_NVIDIA_DOCKER)"
@echo " Will use: $(if $(filter true,$(USE_GPU_SETUP)),GPU setup,CPU-only setup)"
@echo ""
@echo "Override with: make demo FORCE_CPU=true"
check-system: ## Show detected system capabilities
@echo "System capabilities:"
@echo " GPU detected: $(HAS_GPU)"
@echo " Nvidia Docker: $(HAS_NVIDIA_DOCKER)"
@echo " Will use: $(if $(filter true,$(USE_GPU_SETUP)),GPU setup,CPU-only setup)"
@echo ""
@echo "Force CPU mode: make demo FORCE_CPU=true"
setup-env: ## Copy example env file if .env doesn't exist
@if [ ! -f .env ]; then \
echo "Creating .env from example..."; \
cp .env.local.example .env; \
echo "✓ Created .env with demo-ready defaults"; \
else \
echo "✓ .env already exists"; \
fi
build: ## Build the appropriate Docker image (GPU or CPU based on detection)
ifeq ($(USE_GPU_SETUP),true)
@echo "Building GPU Docker image: $(DOCKER_IMAGE) (this may take several minutes)..."
DOCKER_BUILDKIT=1 docker build -t $(DOCKER_IMAGE) .
else
@echo "Building CPU Docker image: $(DOCKER_IMAGE_CPU) (this may take several minutes)..."
DOCKER_BUILDKIT=1 docker build -f Dockerfile.cpu -t $(DOCKER_IMAGE_CPU) .
endif
build-gpu: ## Build the GPU Docker image
@echo "Building GPU Docker image: $(DOCKER_IMAGE) (this may take several minutes)..."
DOCKER_BUILDKIT=1 docker build -t $(DOCKER_IMAGE) .
build-cpu: ## Build the CPU Docker image
@echo "Building CPU Docker image: $(DOCKER_IMAGE_CPU) (this may take several minutes)..."
DOCKER_BUILDKIT=1 docker build -f Dockerfile.cpu -t $(DOCKER_IMAGE_CPU) .
demo: setup-env ## Process a demo video synchronously using Django management command
@echo "🎬 Starting demo video processing..."
@if [ -z "$(DEMO_VIDEO)" ]; then \
if [ -d "sample-videos" ] && [ -n "$$(find sample-videos -name '*.mp4' 2>/dev/null | head -1)" ]; then \
echo "Using video from sample-videos directory"; \
else \
echo "❌ No video specified and no sample-videos found"; \
echo ""; \
echo "Options:"; \
echo " 1. Specify a video: make demo DEMO_VIDEO=path/to/your/video.mp4"; \
echo " 2. Create sample-videos/ and add MP4 files"; \
echo ""; \
echo "Example: make demo DEMO_VIDEO=~/Downloads/my-video.mp4"; \
exit 1; \
fi; \
elif [ ! -f "$(DEMO_VIDEO)" ]; then \
echo "❌ Video file not found: $(DEMO_VIDEO)"; \
echo "Please check the path and try again"; \
exit 1; \
fi
@echo "Video: $(DEMO_VIDEO)"
ifeq ($(USE_GPU_SETUP),true)
@echo "Mode: GPU-accelerated processing"
@echo "Setting up .env for GPU mode..."
@sed 's/USE_CPU_ONLY=true/USE_CPU_ONLY=false/' .env.local.example > .env
@echo "DOCKER_IMAGE=$(DOCKER_IMAGE)" >> .env
@echo "Building GPU image (this may take several minutes for MegaDetector installation)..."
DOCKER_BUILDKIT=1 docker build -t $(DOCKER_IMAGE) .
else
@echo "Mode: CPU-only processing (no GPU/Nvidia Container Toolkit required)"
@echo "Setting up .env for CPU mode..."
@cp .env.local.example .env
@echo "DOCKER_IMAGE=$(DOCKER_IMAGE_CPU)" >> .env
@echo "Building CPU image (this may take several minutes for MegaDetector installation)..."
DOCKER_BUILDKIT=1 docker build -f Dockerfile.cpu -t $(DOCKER_IMAGE_CPU) .
endif
@echo "Setting up environment..."
docker compose -f docker-compose-local.yaml up -d db redis
@echo "Waiting for database to be ready..."
@sleep 5
@echo "Processing video synchronously..."
docker compose -f docker-compose-local.yaml run --rm \
-v "$(PWD)/$(DEMO_VIDEO):/input/$(notdir $(DEMO_VIDEO)):ro" \
chunk_video python3 manage.py process_video /input/$(notdir $(DEMO_VIDEO))
@echo ""
@echo "🌐 You can also start the web interface to view results:"
@echo " make start-web"
@echo " Then visit: http://localhost:8000/admin"
clean: ## Stop containers and clean up
@echo "🧹 Cleaning up..."
docker compose -f docker-compose-local.yaml down
docker system prune -f
start-web: setup-env ## Start the web interface only
@echo "🌐 Starting web interface..."
docker compose -f docker-compose-local.yaml up admin
start-workers: setup-env ## Start all processing workers
@echo "⚙️ Starting processing workers..."
docker compose -f docker-compose-local.yaml up chunk_video extract detect create_output
start-services: setup-env ## Start services
@echo "⚙️ Starting services..."
docker compose -f docker-compose-local.yaml up -d db redis
start-full: setup-env ## Start complete system (web + workers + services)
@echo "🚀 Starting complete system..."
docker compose -f docker-compose-local.yaml up
migrate: setup-env ## Create and run database migrations
@echo "🔄 Creating any needed migrations..."
docker compose -f docker-compose-local.yaml up -d db
@sleep 3
docker compose -f docker-compose-local.yaml run --rm admin python3 manage.py makemigrations
@echo "🔄 Running database migrations..."
docker compose -f docker-compose-local.yaml run --rm admin python3 manage.py migrate