MogensR commited on
Commit
df919d5
·
1 Parent(s): b65dc99

Create docker/Makefile

Browse files
Files changed (1) hide show
  1. docker/Makefile +198 -0
docker/Makefile ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Makefile for BackgroundFX Pro Docker operations
2
+
3
+ .PHONY: help build build-gpu build-cpu build-all run stop clean logs shell test push pull
4
+
5
+ # Variables
6
+ PROJECT_NAME = backgroundfx-pro
7
+ VERSION ?= latest
8
+ REGISTRY ?=
9
+ DOCKER_COMPOSE = docker-compose
10
+ DOCKER = docker
11
+
12
+ # Colors for output
13
+ GREEN = \033[0;32m
14
+ YELLOW = \033[1;33m
15
+ RED = \033[0;31m
16
+ NC = \033[0m # No Color
17
+
18
+ help: ## Show this help message
19
+ @echo "BackgroundFX Pro Docker Management"
20
+ @echo "=================================="
21
+ @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(GREEN)%-20s$(NC) %s\n", $$1, $$2}'
22
+
23
+ # ============================================================================
24
+ # Build Commands
25
+ # ============================================================================
26
+
27
+ build: build-gpu ## Build default GPU image
28
+
29
+ build-gpu: ## Build GPU-enabled image
30
+ @echo "$(GREEN)Building GPU image...$(NC)"
31
+ $(DOCKER) build -f docker/Dockerfile -t $(PROJECT_NAME):gpu ..
32
+ $(DOCKER) tag $(PROJECT_NAME):gpu $(PROJECT_NAME):latest
33
+
34
+ build-cpu: ## Build CPU-only image
35
+ @echo "$(GREEN)Building CPU image...$(NC)"
36
+ $(DOCKER) build -f docker/Dockerfile.cpu -t $(PROJECT_NAME):cpu ..
37
+
38
+ build-prod: ## Build production-optimized image
39
+ @echo "$(GREEN)Building production image...$(NC)"
40
+ $(DOCKER) build -f docker/Dockerfile.prod -t $(PROJECT_NAME):prod ..
41
+
42
+ build-all: build-gpu build-cpu build-prod ## Build all images
43
+
44
+ build-nocache: ## Build with no cache
45
+ $(DOCKER) build --no-cache -f docker/Dockerfile -t $(PROJECT_NAME):gpu ..
46
+
47
+ # ============================================================================
48
+ # Run Commands
49
+ # ============================================================================
50
+
51
+ run: ## Run with docker-compose (GPU)
52
+ $(DOCKER_COMPOSE) up -d backgroundfx-gpu
53
+ @echo "$(GREEN)BackgroundFX Pro is running at http://localhost:7860$(NC)"
54
+
55
+ run-cpu: ## Run CPU version
56
+ $(DOCKER_COMPOSE) --profile cpu up -d backgroundfx-cpu
57
+ @echo "$(GREEN)BackgroundFX Pro (CPU) is running at http://localhost:7861$(NC)"
58
+
59
+ run-dev: ## Run in development mode with live reload
60
+ $(DOCKER_COMPOSE) -f docker-compose.yml -f docker-compose.dev.yml up
61
+
62
+ run-prod: ## Run in production mode with monitoring
63
+ $(DOCKER_COMPOSE) --profile production --profile monitoring up -d
64
+ @echo "$(GREEN)Production stack running:$(NC)"
65
+ @echo " - App: http://localhost:7860"
66
+ @echo " - API: http://localhost:8000"
67
+ @echo " - Grafana: http://localhost:3000"
68
+ @echo " - Prometheus: http://localhost:9090"
69
+
70
+ # ============================================================================
71
+ # Management Commands
72
+ # ============================================================================
73
+
74
+ stop: ## Stop all containers
75
+ $(DOCKER_COMPOSE) down
76
+
77
+ restart: ## Restart all containers
78
+ $(DOCKER_COMPOSE) restart
79
+
80
+ clean: ## Clean up containers, volumes, and images
81
+ $(DOCKER_COMPOSE) down -v
82
+ $(DOCKER) image prune -f
83
+ @echo "$(GREEN)Cleanup complete$(NC)"
84
+
85
+ clean-all: ## Deep clean including all images and volumes
86
+ $(DOCKER_COMPOSE) down -v --rmi all
87
+ $(DOCKER) system prune -af --volumes
88
+ @echo "$(YELLOW)All Docker resources cleaned$(NC)"
89
+
90
+ # ============================================================================
91
+ # Monitoring Commands
92
+ # ============================================================================
93
+
94
+ logs: ## Show logs from all containers
95
+ $(DOCKER_COMPOSE) logs -f
96
+
97
+ logs-app: ## Show only application logs
98
+ $(DOCKER_COMPOSE) logs -f backgroundfx-gpu
99
+
100
+ logs-tail: ## Show last 100 lines of logs
101
+ $(DOCKER_COMPOSE) logs --tail=100
102
+
103
+ status: ## Show container status
104
+ $(DOCKER_COMPOSE) ps
105
+
106
+ stats: ## Show resource usage statistics
107
+ $(DOCKER) stats --no-stream $$($(DOCKER_COMPOSE) ps -q)
108
+
109
+ health: ## Check health status
110
+ @echo "$(GREEN)Health Status:$(NC)"
111
+ @$(DOCKER) inspect --format='{{.Name}}: {{.State.Health.Status}}' $$($(DOCKER_COMPOSE) ps -q) 2>/dev/null || echo "No health checks configured"
112
+
113
+ # ============================================================================
114
+ # Development Commands
115
+ # ============================================================================
116
+
117
+ shell: ## Open shell in running container
118
+ $(DOCKER_COMPOSE) exec backgroundfx-gpu /bin/bash
119
+
120
+ shell-root: ## Open root shell in running container
121
+ $(DOCKER_COMPOSE) exec -u root backgroundfx-gpu /bin/bash
122
+
123
+ test: ## Run tests in container
124
+ $(DOCKER_COMPOSE) run --rm backgroundfx-gpu python -m pytest tests/
125
+
126
+ lint: ## Run linting in container
127
+ $(DOCKER_COMPOSE) run --rm backgroundfx-gpu python -m flake8 .
128
+
129
+ format: ## Format code in container
130
+ $(DOCKER_COMPOSE) run --rm backgroundfx-gpu python -m black .
131
+
132
+ # ============================================================================
133
+ # Model Management
134
+ # ============================================================================
135
+
136
+ download-models: ## Download all models
137
+ $(DOCKER_COMPOSE) --profile setup run --rm model-downloader
138
+
139
+ list-models: ## List available models
140
+ $(DOCKER_COMPOSE) exec backgroundfx-gpu python -c "from models import ModelRegistry; r=ModelRegistry(); print(r.get_statistics())"
141
+
142
+ # ============================================================================
143
+ # Deployment Commands
144
+ # ============================================================================
145
+
146
+ push: ## Push images to registry
147
+ @if [ -z "$(REGISTRY)" ]; then \
148
+ echo "$(RED)Error: REGISTRY not set$(NC)"; \
149
+ exit 1; \
150
+ fi
151
+ $(DOCKER) tag $(PROJECT_NAME):gpu $(REGISTRY)/$(PROJECT_NAME):gpu-$(VERSION)
152
+ $(DOCKER) push $(REGISTRY)/$(PROJECT_NAME):gpu-$(VERSION)
153
+
154
+ pull: ## Pull images from registry
155
+ @if [ -z "$(REGISTRY)" ]; then \
156
+ echo "$(RED)Error: REGISTRY not set$(NC)"; \
157
+ exit 1; \
158
+ fi
159
+ $(DOCKER) pull $(REGISTRY)/$(PROJECT_NAME):gpu-$(VERSION)
160
+
161
+ deploy: ## Deploy to production
162
+ ./deploy.sh production
163
+
164
+ # ============================================================================
165
+ # Backup Commands
166
+ # ============================================================================
167
+
168
+ backup: ## Backup volumes
169
+ @echo "$(GREEN)Creating backup...$(NC)"
170
+ $(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 .
171
+ $(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 .
172
+ @echo "$(GREEN)Backup complete$(NC)"
173
+
174
+ restore: ## Restore from backup (set BACKUP_FILE)
175
+ @if [ -z "$(BACKUP_FILE)" ]; then \
176
+ echo "$(RED)Error: BACKUP_FILE not set$(NC)"; \
177
+ exit 1; \
178
+ fi
179
+ $(DOCKER) run --rm -v $(PROJECT_NAME)_model-cache:/data -v $$(pwd)/backups:/backup alpine tar xzf /backup/$(BACKUP_FILE) -C /data
180
+
181
+ # ============================================================================
182
+ # Utility Commands
183
+ # ============================================================================
184
+
185
+ gpu-check: ## Check GPU availability
186
+ $(DOCKER) run --rm --gpus all nvidia/cuda:12.1.0-base-ubuntu20.04 nvidia-smi
187
+
188
+ env-example: ## Copy example environment file
189
+ cp docker/.env.example docker/.env
190
+ @echo "$(GREEN)Created docker/.env - please edit with your settings$(NC)"
191
+
192
+ version: ## Show version information
193
+ @echo "Project: $(PROJECT_NAME)"
194
+ @echo "Version: $(VERSION)"
195
+ @echo "Docker: $$(docker --version)"
196
+ @echo "Docker Compose: $$(docker-compose --version)"
197
+
198
+ .DEFAULT_GOAL := help