-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
143 lines (122 loc) · 5.27 KB
/
Copy pathMakefile
File metadata and controls
143 lines (122 loc) · 5.27 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
# Makefile for opendeepwiki
# Variables
IMAGE_NAME := opendeepwiki
CONTAINER_NAME := opendeepwiki_app
ENV_FILE := .env
ENV_EXAMPLE_FILE := .env.example
# Default target: Show help
.DEFAULT_GOAL := help
# Phony targets (targets that are not actual files)
.PHONY: help build run start stop logs clean prune-all env env-check setup
## -----------------------------------------------------------------------------
## General Commands
## -----------------------------------------------------------------------------
help: ## Show this help message
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
## -----------------------------------------------------------------------------
## Environment Setup
## -----------------------------------------------------------------------------
env: $(ENV_EXAMPLE_FILE) ## Create .env from .env.example if .env does not exist
@if [ ! -f $(ENV_FILE) ]; then \
echo "Creating $(ENV_FILE) from $(ENV_EXAMPLE_FILE)..."; \
cp $(ENV_EXAMPLE_FILE) $(ENV_FILE); \
echo "IMPORTANT: Please fill in your API keys in $(ENV_FILE)."; \
else \
echo "$(ENV_FILE) already exists. Ensure it is correctly configured."; \
fi
$(ENV_EXAMPLE_FILE):
@echo "Creating $(ENV_EXAMPLE_FILE)..."
@echo "# Required API Keys" > $(ENV_EXAMPLE_FILE)
@echo "GEMINI_API_KEY=" >> $(ENV_EXAMPLE_FILE)
@echo "" >> $(ENV_EXAMPLE_FILE)
@echo "# Optional Langfuse Tracing (leave blank if not used)" >> $(ENV_EXAMPLE_FILE)
@echo "LANGFUSE_PUBLIC_KEY=" >> $(ENV_EXAMPLE_FILE)
@echo "LANGFUSE_SECRET_KEY=" >> $(ENV_EXAMPLE_FILE)
@echo "LANGFUSE_HOST=https://cloud.langfuse.com" >> $(ENV_EXAMPLE_FILE)
@echo "$(ENV_EXAMPLE_FILE) created. Copy to .env and fill it out, or run 'make env'."
env-check: ## Check if .env file exists
@if [ ! -f $(ENV_FILE) ]; then \
echo "Error: $(ENV_FILE) not found!"; \
echo "Please create it by copying $(ENV_EXAMPLE_FILE) to $(ENV_FILE) and filling in your API keys,"; \
echo "or run 'make env' to create a template."; \
exit 1; \
fi
@echo "$(ENV_FILE) found."
## -----------------------------------------------------------------------------
## Docker Operations
## -----------------------------------------------------------------------------
build: env-check ## Build the Docker image
@echo "Building Docker image $(IMAGE_NAME)..."
docker build -t $(IMAGE_NAME) .
run: env-check ## Run the Docker container in detached mode
@echo "Checking if container $(CONTAINER_NAME) is already running..."
@if [ $$(docker ps -q -f name=^$(CONTAINER_NAME)$$) ]; then \
echo "Container $(CONTAINER_NAME) is already running."; \
echo "Use 'make stop' or 'make restart' if you want to stop/restart it."; \
elif [ $$(docker ps -aq -f status=exited -f name=^$(CONTAINER_NAME)$$) ]; then \
echo "Removing exited container $(CONTAINER_NAME)..."; \
docker rm $(CONTAINER_NAME); \
echo "Starting Docker container $(CONTAINER_NAME)..."; \
docker run -d --name $(CONTAINER_NAME) \
-p 7860:7860 \
-p 5050:5050 \
-p 8001:8001 \
-p 8002:8002 \
--env-file $(ENV_FILE) \
$(IMAGE_NAME); \
else \
echo "Starting Docker container $(CONTAINER_NAME)..."; \
docker run -d --name $(CONTAINER_NAME) \
-p 7860:7860 \
-p 5050:5050 \
-p 8001:8001 \
-p 8002:8002 \
--env-file $(ENV_FILE) \
$(IMAGE_NAME); \
fi
@echo "Container $(CONTAINER_NAME) should be running. Access UI at http://localhost:7860"
start: run ## Alias for 'run'
stop: ## Stop and remove the Docker container
@echo "Stopping Docker container $(CONTAINER_NAME)..."
@if [ $$(docker ps -q -f name=^$(CONTAINER_NAME)$$) ]; then \
docker stop $(CONTAINER_NAME); \
else \
echo "Container $(CONTAINER_NAME) is not running."; \
fi
@echo "Removing Docker container $(CONTAINER_NAME) if it exists..."
@if [ $$(docker ps -aq -f name=^$(CONTAINER_NAME)$$) ]; then \
docker rm $(CONTAINER_NAME); \
else \
echo "Container $(CONTAINER_NAME) does not exist or already removed."; \
fi
restart: ## Restart the Docker container (stop, then build and run)
$(MAKE) stop
$(MAKE) build
$(MAKE) run
logs: ## Follow logs from the Docker container
@echo "Following logs for $(CONTAINER_NAME)... (Ctrl+C to stop)"
docker logs -f $(CONTAINER_NAME)
## -----------------------------------------------------------------------------
## Cleanup Operations
## -----------------------------------------------------------------------------
clean: stop ## Stop and remove the container, then remove the Docker image
@echo "Removing Docker image $(IMAGE_NAME)..."
@if $$(docker images -q $(IMAGE_NAME)); then \
docker rmi $(IMAGE_NAME); \
else \
echo "Image $(IMAGE_NAME) not found."; \
fi
prune-all: clean ## Clean everything: stop container, remove image, and prune unused Docker objects
@echo "Pruning unused Docker volumes, networks, and dangling images..."
docker system prune -f
docker volume prune -f
@echo "Full Docker prune complete."
## -----------------------------------------------------------------------------
## Convenience Targets
## -----------------------------------------------------------------------------
setup: env build run ## Setup environment, build image, and run container
@echo "Setup complete. opendeepwiki should be accessible at http://localhost:7860"