-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
198 lines (163 loc) · 5.34 KB
/
Makefile
File metadata and controls
198 lines (163 loc) · 5.34 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
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
# Vector Database API - Docker Makefile
# Variables
IMAGE_NAME = vectordb-api
IMAGE_TAG = latest
CONTAINER_NAME = vectordb
PORT = 8000
VOLUME_NAME = vectordb_data
# Help
.PHONY: help
help: ## Show this help message
@echo "Vector Database API - Docker Commands"
@echo "====================================="
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
# Build Commands
.PHONY: build
build: ## Build Docker image
docker build -t $(IMAGE_NAME):$(IMAGE_TAG) .
.PHONY: build-no-cache
build-no-cache: ## Build Docker image without cache
docker build --no-cache -t $(IMAGE_NAME):$(IMAGE_TAG) .
# Run Commands
.PHONY: run
run: ## Run container
docker run -d \
--name $(CONTAINER_NAME) \
-p $(PORT):8000 \
-v $(VOLUME_NAME):/app/data \
-e COHERE_API_KEY=${COHERE_API_KEY} \
$(IMAGE_NAME):$(IMAGE_TAG)
.PHONY: run-dev
run-dev: ## Run container in development mode
docker run -it --rm \
--name $(CONTAINER_NAME)-dev \
-p $(PORT):8000 \
-v $(PWD)/src:/app/src \
-v $(PWD)/sdk:/app/sdk \
-e COHERE_API_KEY=${COHERE_API_KEY} \
$(IMAGE_NAME):$(IMAGE_TAG)
.PHONY: run-interactive
run-interactive: ## Run container interactively
docker run -it --rm \
--name $(CONTAINER_NAME)-interactive \
-p $(PORT):8000 \
--entrypoint /bin/bash \
$(IMAGE_NAME):$(IMAGE_TAG)
# Docker Compose Commands
.PHONY: up
up: ## Start services with docker-compose
docker-compose up -d
.PHONY: up-prod
up-prod: ## Start services with production profile
docker-compose --profile production up -d
.PHONY: down
down: ## Stop and remove containers
docker-compose down
.PHONY: restart
restart: down up ## Restart services
# Management Commands
.PHONY: logs
logs: ## Show container logs
docker logs -f $(CONTAINER_NAME)
.PHONY: logs-compose
logs-compose: ## Show docker-compose logs
docker-compose logs -f
.PHONY: shell
shell: ## Open shell in running container
docker exec -it $(CONTAINER_NAME) /bin/bash
.PHONY: stop
stop: ## Stop container
docker stop $(CONTAINER_NAME)
.PHONY: start
start: ## Start stopped container
docker start $(CONTAINER_NAME)
.PHONY: remove
remove: stop ## Remove container
docker rm $(CONTAINER_NAME)
# Testing Commands
.PHONY: test
test: ## Test the API endpoints
@echo "Testing health endpoint..."
curl -f http://localhost:$(PORT)/health || echo "Health check failed"
@echo "\nTesting library creation..."
curl -X POST "http://localhost:$(PORT)/libraries" \
-H "Content-Type: application/json" \
-d '{"name": "Test Library", "metadata": {"test": true}}' || echo "Library creation failed"
@echo "\nTesting library listing..."
curl -f http://localhost:$(PORT)/libraries || echo "Library listing failed"
.PHONY: test-sdk
test-sdk: ## Test SDK functionality
docker exec $(CONTAINER_NAME) python3 /app/sdk/examples.py
# Cleanup Commands
.PHONY: clean
clean: ## Remove container and image
-docker stop $(CONTAINER_NAME)
-docker rm $(CONTAINER_NAME)
-docker rmi $(IMAGE_NAME):$(IMAGE_TAG)
.PHONY: clean-all
clean-all: clean ## Remove everything including volumes
-docker volume rm $(VOLUME_NAME)
-docker system prune -f
# Volume Management
.PHONY: volume-create
volume-create: ## Create data volume
docker volume create $(VOLUME_NAME)
.PHONY: volume-backup
volume-backup: ## Backup data volume
docker run --rm \
-v $(VOLUME_NAME):/data \
-v $(PWD):/backup \
alpine tar czf /backup/vectordb-backup-$(shell date +%Y%m%d_%H%M%S).tar.gz -C /data .
.PHONY: volume-restore
volume-restore: ## Restore data volume (requires BACKUP_FILE)
@if [ -z "$(BACKUP_FILE)" ]; then echo "Please specify BACKUP_FILE=<file>"; exit 1; fi
docker run --rm \
-v $(VOLUME_NAME):/data \
-v $(PWD):/backup \
alpine tar xzf /backup/$(BACKUP_FILE) -C /data
# Monitoring Commands
.PHONY: stats
stats: ## Show container resource usage
docker stats $(CONTAINER_NAME)
.PHONY: inspect
inspect: ## Inspect container configuration
docker inspect $(CONTAINER_NAME)
.PHONY: health
health: ## Check container health status
docker inspect $(CONTAINER_NAME) --format='{{.State.Health.Status}}'
# Development Commands
.PHONY: dev-setup
dev-setup: volume-create build run ## Complete development setup
.PHONY: dev-reset
dev-reset: clean-all dev-setup ## Reset development environment
.PHONY: quick-test
quick-test: build run ## Quick build and test
sleep 5
$(MAKE) test
$(MAKE) remove
# Production Commands
.PHONY: prod-deploy
prod-deploy: ## Deploy to production
$(MAKE) build
$(MAKE) up-prod
.PHONY: prod-update
prod-update: ## Update production deployment
docker-compose pull
docker-compose up -d --force-recreate
# Debug Commands
.PHONY: debug
debug: ## Debug container issues
@echo "=== Container Status ==="
docker ps -a | grep $(CONTAINER_NAME) || echo "Container not found"
@echo "\n=== Resource Usage ==="
docker stats --no-stream $(CONTAINER_NAME) 2>/dev/null || echo "Container not running"
@echo "\n=== Recent Logs ==="
docker logs --tail 20 $(CONTAINER_NAME) 2>/dev/null || echo "No logs available"
@echo "\n=== Health Check ==="
curl -f http://localhost:$(PORT)/health 2>/dev/null || echo "Health check failed"
# Multi-platform build (for deployment)
.PHONY: build-multiplatform
build-multiplatform: ## Build for multiple platforms
docker buildx build --platform linux/amd64,linux/arm64 -t $(IMAGE_NAME):$(IMAGE_TAG) .
# Default target
.DEFAULT_GOAL := help