-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMakefile
More file actions
242 lines (211 loc) · 9.94 KB
/
Copy pathMakefile
File metadata and controls
242 lines (211 loc) · 9.94 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# Red Hat Lightspeed Agent for Google Cloud - Makefile
# Common development and deployment commands
.PHONY: help build build-agent build-marketplace run stop logs logs-mcp clean test test-shell lint dev check-env lock lock-agent lock-handler lock-dev lock-eval lock-check audit
# Default target
help:
@echo "Red Hat Lightspeed Agent for Google Cloud - Available Commands"
@echo ""
@echo "Development:"
@echo " make dev - Run agent in development mode (no container)"
@echo " make test - Run tests"
@echo " make test-shell - Run shell tests (shellcheck + bats + coverage)"
@echo " make lint - Run linter and type checker"
@echo ""
@echo "Dependency Management:"
@echo " make lock - Regenerate all lock files (run after changing pyproject.toml)"
@echo " make lock-agent - Regenerate agent lock file only"
@echo " make lock-handler - Regenerate marketplace handler lock file only"
@echo " make lock-dev - Regenerate dev lock file only"
@echo " make lock-eval - Regenerate eval lock file only"
@echo " make lock-check - Verify lock files are in sync (used by CI)"
@echo " make audit - Scan dependencies for known vulnerabilities (pip-audit)"
@echo ""
@echo "Container (Podman):"
@echo " make build - Build all container images (agent + marketplace handler)"
@echo " make build-agent - Build agent container image only"
@echo " make build-marketplace - Build marketplace handler container image only"
@echo " make run - Start the pod with all services"
@echo " make stop - Stop and remove the pod"
@echo " make logs - View agent container logs"
@echo " make logs-mcp - View MCP server container logs"
@echo " make logs-all - View all container logs"
@echo " make status - Show pod and container status"
@echo " make check-env - Check required environment variables"
@echo ""
@echo "Cleanup:"
@echo " make clean - Remove containers, images, and volumes"
@echo ""
@echo "Required Environment Variables:"
@echo " GOOGLE_API_KEY - Google AI Studio API key"
@echo ""
# =============================================================================
# Development Commands
# =============================================================================
dev:
@echo "Starting agent in development mode..."
source .venv/bin/activate && python -m lightspeed_agent.main
test:
@echo "Running tests..."
source .venv/bin/activate && python -m pytest tests/ -v
test-shell:
@echo "Running shellcheck..."
shellcheck deploy/cloudrun/*.sh
@echo "Running bats tests..."
bats tests/shell/
@echo "Checking function coverage..."
bash tests/shell/check_coverage.sh
lint:
@echo "Running linter..."
source .venv/bin/activate && ruff check src/ tests/
@echo "Running type checker..."
source .venv/bin/activate && mypy src/lightspeed_agent/ --ignore-missing-imports
# =============================================================================
# Dependency Management
# =============================================================================
lock:
$(MAKE) lock-agent lock-handler lock-dev lock-eval
lock-agent:
@echo "Regenerating agent lock file..."
source .venv/bin/activate && uv pip compile --generate-hashes --python-version=3.12 --python-platform=linux \
--extra agent --output-file=requirements-agent.txt pyproject.toml
@echo "✓ requirements-agent.txt updated"
lock-handler:
@echo "Regenerating marketplace handler lock file..."
source .venv/bin/activate && uv pip compile --generate-hashes --python-version=3.12 --python-platform=linux \
--output-file=requirements-handler.txt pyproject.toml
@echo "✓ requirements-handler.txt updated"
lock-dev:
@echo "Regenerating dev lock file..."
source .venv/bin/activate && uv pip compile --generate-hashes --python-version=3.12 --python-platform=linux \
--extra dev --output-file=requirements-dev.txt pyproject.toml
@echo "✓ requirements-dev.txt updated"
lock-eval:
@echo "Regenerating eval lock file..."
source .venv/bin/activate && uv pip compile --generate-hashes --python-version=3.12 --python-platform=linux \
--extra eval --output-file=requirements-eval.txt pyproject.toml
@echo "✓ requirements-eval.txt updated"
lock-check:
@echo "Checking if lock files are in sync with pyproject.toml..."
@cp requirements-agent.txt /tmp/requirements-agent-check.txt
@uv pip compile --generate-hashes --python-version=3.12 --python-platform=linux \
--extra agent --output-file=/tmp/requirements-agent-check.txt pyproject.toml
@diff -u <(tail -n +3 requirements-agent.txt) <(tail -n +3 /tmp/requirements-agent-check.txt) || \
(echo "ERROR: requirements-agent.txt is out of sync. Run 'make lock' to update." && rm -f /tmp/requirements-agent-check.txt && exit 1)
@rm -f /tmp/requirements-agent-check.txt
@cp requirements-handler.txt /tmp/requirements-handler-check.txt
@uv pip compile --generate-hashes --python-version=3.12 --python-platform=linux \
--output-file=/tmp/requirements-handler-check.txt pyproject.toml
@diff -u <(tail -n +3 requirements-handler.txt) <(tail -n +3 /tmp/requirements-handler-check.txt) || \
(echo "ERROR: requirements-handler.txt is out of sync. Run 'make lock' to update." && rm -f /tmp/requirements-handler-check.txt && exit 1)
@rm -f /tmp/requirements-handler-check.txt
@cp requirements-dev.txt /tmp/requirements-dev-check.txt
@uv pip compile --generate-hashes --python-version=3.12 --python-platform=linux \
--extra dev --output-file=/tmp/requirements-dev-check.txt pyproject.toml
@diff -u <(tail -n +3 requirements-dev.txt) <(tail -n +3 /tmp/requirements-dev-check.txt) || \
(echo "ERROR: requirements-dev.txt is out of sync. Run 'make lock' to update." && rm -f /tmp/requirements-dev-check.txt && exit 1)
@rm -f /tmp/requirements-dev-check.txt
@cp requirements-eval.txt /tmp/requirements-eval-check.txt
@uv pip compile --generate-hashes --python-version=3.12 --python-platform=linux \
--extra eval --output-file=/tmp/requirements-eval-check.txt pyproject.toml
@diff -u <(tail -n +3 requirements-eval.txt) <(tail -n +3 /tmp/requirements-eval-check.txt) || \
(echo "ERROR: requirements-eval.txt is out of sync. Run 'make lock' to update." && rm -f /tmp/requirements-eval-check.txt && exit 1)
@rm -f /tmp/requirements-eval-check.txt
@echo "✓ Lock files are in sync"
audit:
@echo "Scanning dependencies for known vulnerabilities..."
uv tool run pip-audit --no-deps --disable-pip -r requirements-agent.txt
uv tool run pip-audit --no-deps --disable-pip -r requirements-handler.txt
uv tool run pip-audit --no-deps --disable-pip -r requirements-dev.txt
@echo "✓ Vulnerability scan complete"
# =============================================================================
# Container Commands (Podman)
# =============================================================================
IMAGE_NAME ?= localhost/lightspeed-agent
MARKETPLACE_IMAGE_NAME ?= localhost/marketplace-handler
IMAGE_TAG ?= latest
POD_NAME = lightspeed-agent-pod
build: build-agent build-marketplace
build-agent:
@echo "Building agent container image..."
podman build -t $(IMAGE_NAME):$(IMAGE_TAG) -f Containerfile .
build-marketplace:
@echo "Building marketplace handler container image..."
podman build -t $(MARKETPLACE_IMAGE_NAME):$(IMAGE_TAG) -f Containerfile.marketplace-handler .
run: check-env build
@echo "Starting pod..."
@if podman pod exists $(POD_NAME); then \
echo "Pod already exists. Stopping and removing..."; \
podman pod stop $(POD_NAME) 2>/dev/null || true; \
podman pod rm $(POD_NAME) 2>/dev/null || true; \
fi
@mkdir -p config
podman play kube lightspeed-agent-pod.yaml
@echo ""
@echo "Pod started. Services available at:"
@echo " - Agent API: http://localhost:8000"
@echo " - Health: http://localhost:8000/health"
@echo " - AgentCard: http://localhost:8000/.well-known/agent.json"
@echo " - MCP Server: http://localhost:8081 (internal)"
@echo ""
@echo "View logs:"
@echo " make logs - Agent logs"
@echo " make logs-mcp - MCP server logs"
stop:
@echo "Stopping pod..."
podman pod stop $(POD_NAME) 2>/dev/null || true
podman pod rm $(POD_NAME) 2>/dev/null || true
@echo "Pod stopped and removed."
cve-scan:
@echo "Scanning for CVEs with trivy"
podman run --rm -v $$(pwd):/app:Z aquasec/trivy fs --file-patterns pip:requirements-.*\.txt /app
logs:
@echo "Showing agent logs..."
podman logs -f $(POD_NAME)-lightspeed-agent
logs-mcp:
@echo "Showing MCP server logs..."
podman logs -f $(POD_NAME)-insights-mcp
logs-all:
@echo "Showing all container logs..."
@for container in $$(podman pod inspect $(POD_NAME) --format '{{range .Containers}}{{.Name}} {{end}}'); do \
echo "=== $$container ==="; \
podman logs --tail 50 $$container 2>/dev/null || true; \
echo ""; \
done
status:
@echo "Pod status:"
@podman pod ps --filter name=$(POD_NAME)
@echo ""
@echo "Container status:"
@podman ps --filter pod=$(POD_NAME) --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
check-env:
@echo "Checking required environment variables..."
@missing=0; \
if [ -z "$$GOOGLE_API_KEY" ] && [ "$$GOOGLE_GENAI_USE_VERTEXAI" != "TRUE" ]; then \
echo " ✗ GOOGLE_API_KEY is not set (required unless using Vertex AI)"; \
missing=1; \
else \
echo " ✓ GOOGLE_API_KEY is set (or using Vertex AI)"; \
fi; \
if [ $$missing -eq 1 ]; then \
echo ""; \
echo "Missing required environment variables!"; \
echo "See .env.example for configuration options."; \
exit 1; \
else \
echo ""; \
echo "All required environment variables are set."; \
fi
# =============================================================================
# Cleanup Commands
# =============================================================================
clean: stop
@echo "Removing container images..."
podman rmi $(IMAGE_NAME):$(IMAGE_TAG) 2>/dev/null || true
podman rmi $(MARKETPLACE_IMAGE_NAME):$(IMAGE_TAG) 2>/dev/null || true
@echo "Removing dangling images..."
podman image prune -f
@echo "Cleanup complete."
clean-all: clean
@echo "Removing all volumes..."
podman volume prune -f
@echo "Full cleanup complete."