File size: 7,294 Bytes
df919d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# Makefile for BackgroundFX Pro Docker operations

.PHONY: help build build-gpu build-cpu build-all run stop clean logs shell test push pull

# Variables
PROJECT_NAME = backgroundfx-pro
VERSION ?= latest
REGISTRY ?= 
DOCKER_COMPOSE = docker-compose
DOCKER = docker

# Colors for output
GREEN = \033[0;32m
YELLOW = \033[1;33m
RED = \033[0;31m
NC = \033[0m # No Color

help: ## Show this help message
	@echo "BackgroundFX Pro Docker Management"
	@echo "=================================="
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(GREEN)%-20s$(NC) %s\n", $$1, $$2}'

# ============================================================================
# Build Commands
# ============================================================================

build: build-gpu ## Build default GPU image

build-gpu: ## Build GPU-enabled image
	@echo "$(GREEN)Building GPU image...$(NC)"
	$(DOCKER) build -f docker/Dockerfile -t $(PROJECT_NAME):gpu ..
	$(DOCKER) tag $(PROJECT_NAME):gpu $(PROJECT_NAME):latest

build-cpu: ## Build CPU-only image
	@echo "$(GREEN)Building CPU image...$(NC)"
	$(DOCKER) build -f docker/Dockerfile.cpu -t $(PROJECT_NAME):cpu ..

build-prod: ## Build production-optimized image
	@echo "$(GREEN)Building production image...$(NC)"
	$(DOCKER) build -f docker/Dockerfile.prod -t $(PROJECT_NAME):prod ..

build-all: build-gpu build-cpu build-prod ## Build all images

build-nocache: ## Build with no cache
	$(DOCKER) build --no-cache -f docker/Dockerfile -t $(PROJECT_NAME):gpu ..

# ============================================================================
# Run Commands
# ============================================================================

run: ## Run with docker-compose (GPU)
	$(DOCKER_COMPOSE) up -d backgroundfx-gpu
	@echo "$(GREEN)BackgroundFX Pro is running at http://localhost:7860$(NC)"

run-cpu: ## Run CPU version
	$(DOCKER_COMPOSE) --profile cpu up -d backgroundfx-cpu
	@echo "$(GREEN)BackgroundFX Pro (CPU) is running at http://localhost:7861$(NC)"

run-dev: ## Run in development mode with live reload
	$(DOCKER_COMPOSE) -f docker-compose.yml -f docker-compose.dev.yml up

run-prod: ## Run in production mode with monitoring
	$(DOCKER_COMPOSE) --profile production --profile monitoring up -d
	@echo "$(GREEN)Production stack running:$(NC)"
	@echo "  - App: http://localhost:7860"
	@echo "  - API: http://localhost:8000"
	@echo "  - Grafana: http://localhost:3000"
	@echo "  - Prometheus: http://localhost:9090"

# ============================================================================
# Management Commands
# ============================================================================

stop: ## Stop all containers
	$(DOCKER_COMPOSE) down

restart: ## Restart all containers
	$(DOCKER_COMPOSE) restart

clean: ## Clean up containers, volumes, and images
	$(DOCKER_COMPOSE) down -v
	$(DOCKER) image prune -f
	@echo "$(GREEN)Cleanup complete$(NC)"

clean-all: ## Deep clean including all images and volumes
	$(DOCKER_COMPOSE) down -v --rmi all
	$(DOCKER) system prune -af --volumes
	@echo "$(YELLOW)All Docker resources cleaned$(NC)"

# ============================================================================
# Monitoring Commands
# ============================================================================

logs: ## Show logs from all containers
	$(DOCKER_COMPOSE) logs -f

logs-app: ## Show only application logs
	$(DOCKER_COMPOSE) logs -f backgroundfx-gpu

logs-tail: ## Show last 100 lines of logs
	$(DOCKER_COMPOSE) logs --tail=100

status: ## Show container status
	$(DOCKER_COMPOSE) ps

stats: ## Show resource usage statistics
	$(DOCKER) stats --no-stream $$($(DOCKER_COMPOSE) ps -q)

health: ## Check health status
	@echo "$(GREEN)Health Status:$(NC)"
	@$(DOCKER) inspect --format='{{.Name}}: {{.State.Health.Status}}' $$($(DOCKER_COMPOSE) ps -q) 2>/dev/null || echo "No health checks configured"

# ============================================================================
# Development Commands
# ============================================================================

shell: ## Open shell in running container
	$(DOCKER_COMPOSE) exec backgroundfx-gpu /bin/bash

shell-root: ## Open root shell in running container
	$(DOCKER_COMPOSE) exec -u root backgroundfx-gpu /bin/bash

test: ## Run tests in container
	$(DOCKER_COMPOSE) run --rm backgroundfx-gpu python -m pytest tests/

lint: ## Run linting in container
	$(DOCKER_COMPOSE) run --rm backgroundfx-gpu python -m flake8 .

format: ## Format code in container
	$(DOCKER_COMPOSE) run --rm backgroundfx-gpu python -m black .

# ============================================================================
# Model Management
# ============================================================================

download-models: ## Download all models
	$(DOCKER_COMPOSE) --profile setup run --rm model-downloader

list-models: ## List available models
	$(DOCKER_COMPOSE) exec backgroundfx-gpu python -c "from models import ModelRegistry; r=ModelRegistry(); print(r.get_statistics())"

# ============================================================================
# Deployment Commands
# ============================================================================

push: ## Push images to registry
	@if [ -z "$(REGISTRY)" ]; then \
		echo "$(RED)Error: REGISTRY not set$(NC)"; \
		exit 1; \
	fi
	$(DOCKER) tag $(PROJECT_NAME):gpu $(REGISTRY)/$(PROJECT_NAME):gpu-$(VERSION)
	$(DOCKER) push $(REGISTRY)/$(PROJECT_NAME):gpu-$(VERSION)

pull: ## Pull images from registry
	@if [ -z "$(REGISTRY)" ]; then \
		echo "$(RED)Error: REGISTRY not set$(NC)"; \
		exit 1; \
	fi
	$(DOCKER) pull $(REGISTRY)/$(PROJECT_NAME):gpu-$(VERSION)

deploy: ## Deploy to production
	./deploy.sh production

# ============================================================================
# Backup Commands
# ============================================================================

backup: ## Backup volumes
	@echo "$(GREEN)Creating backup...$(NC)"
	$(DOCKER) run --rm -v $(PROJECT_NAME)_model-cache:/data -v $$(pwd)/backups:/backup alpine tar czf /backup/models-$$(date +%Y%m%d-%H%M%S).tar.gz -C /data .
	$(DOCKER) run --rm -v $(PROJECT_NAME)_outputs:/data -v $$(pwd)/backups:/backup alpine tar czf /backup/outputs-$$(date +%Y%m%d-%H%M%S).tar.gz -C /data .
	@echo "$(GREEN)Backup complete$(NC)"

restore: ## Restore from backup (set BACKUP_FILE)
	@if [ -z "$(BACKUP_FILE)" ]; then \
		echo "$(RED)Error: BACKUP_FILE not set$(NC)"; \
		exit 1; \
	fi
	$(DOCKER) run --rm -v $(PROJECT_NAME)_model-cache:/data -v $$(pwd)/backups:/backup alpine tar xzf /backup/$(BACKUP_FILE) -C /data

# ============================================================================
# Utility Commands
# ============================================================================

gpu-check: ## Check GPU availability
	$(DOCKER) run --rm --gpus all nvidia/cuda:12.1.0-base-ubuntu20.04 nvidia-smi

env-example: ## Copy example environment file
	cp docker/.env.example docker/.env
	@echo "$(GREEN)Created docker/.env - please edit with your settings$(NC)"

version: ## Show version information
	@echo "Project: $(PROJECT_NAME)"
	@echo "Version: $(VERSION)"
	@echo "Docker: $$(docker --version)"
	@echo "Docker Compose: $$(docker-compose --version)"

.DEFAULT_GOAL := help