-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
139 lines (118 loc) · 6.59 KB
/
Copy pathMakefile
File metadata and controls
139 lines (118 loc) · 6.59 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
# ==============================================================================
# Installation & Setup
# ==============================================================================
# Validate all required environment variables (unified for playground and deploy)
validate-env:
@echo "Validating environment variables..."
@uv run python validate_env.py
# Install dependencies using uv package manager
install:
@command -v uv >/dev/null 2>&1 || { echo "uv is not installed. Installing uv..."; curl -LsSf https://astral.sh/uv/0.8.13/install.sh | sh; source $HOME/.local/bin/env; }
uv sync
# ==============================================================================
# Playground Targets
# ==============================================================================
# Launch local dev playground
playground: validate-env
@echo "==============================================================================="
@echo "| 🚀 Starting your agent playground... |"
@echo "| |"
@echo "| 💡 Try asking: What's the weather in San Francisco? |"
@echo "| |"
@echo "| 🔍 IMPORTANT: Select the 'code-review-agent' folder to interact with your agent. |"
@echo "==============================================================================="
uv run adk web . --port 3000 --reload_agents
# ==============================================================================
# Backend Deployment Targets
# ==============================================================================
# Deploy the agent to Vertex AI Agent Engine (run from project root so paths resolve correctly)
# Sources .env and passes env vars to the deploy script.
deploy-agent: validate-env
@echo "Deploying agent..."
@bash -c 'set -a; [ -f .env ] && source .env; set +a; \
REQ="$${AGENT_REQUIREMENTS_FILE:-agent/app_utils/.requirements.txt}"; \
(uv export --no-hashes --no-header --no-dev --no-emit-project --no-annotate > "$$REQ" 2>/dev/null || \
uv export --no-hashes --no-header --no-dev --no-emit-project > "$$REQ") && \
ENV_VARS="PROJECT_ID=$$PROJECT_ID,DEPLOYMENT_REGION=$$DEPLOYMENT_REGION,MODEL_LOCATION=$$MODEL_LOCATION,MODEL_NAME=$$MODEL_NAME,LLM_LOCATION=$$LLM_LOCATION,DATA_STORE_REGION=$$DATA_STORE_REGION,DATA_STORE_ID=$$DATA_STORE_ID,LOGS_BUCKET_NAME=$$LOGS_BUCKET_NAME,DATASET_ID=$$DATASET_ID,TABLE_ID=$$TABLE_ID,APP_ID_GITHUB=$$APP_ID_GITHUB,INSTALLATION_ID_GITHUB=$$INSTALLATION_ID_GITHUB,SECRET_MANAGER_PROJECT_ID=$$SECRET_MANAGER_PROJECT_ID,SECRET_MANAGER_SECRET_NAME=$$SECRET_MANAGER_SECRET_NAME,SECRET_MANAGER_TOKEN_NAME=$$SECRET_MANAGER_TOKEN_NAME" && \
uv run -m agent.app_utils.deploy \
--source-packages=./agent \
--entrypoint-module=agent_engine_app \
--entrypoint-object=agent_engine \
--requirements-file="$$REQ" \
--set-env-vars="$$ENV_VARS"'
# ==============================================================================
# Testing & Code Quality
# ==============================================================================
.PHONY: test
# Run tests (webhook + deployed agent; deployed agent tests skip if env not set)
test:
uv sync --extra test
uv run pytest test/ -v
# Run code quality checks (codespell, ruff, mypy)
lint:
uv sync --dev --extra lint
uv run codespell
uv run ruff check . --diff
uv run ruff format . --check --diff
uv run mypy .
# ==============================================================================
# Gemini Enterprise Integration
# ==============================================================================
# Register the deployed agent to Gemini Enterprise
# Usage: make register-gemini-enterprise (interactive - will prompt for required details)
# For non-interactive use, set env vars: ID or GEMINI_ENTERPRISE_APP_ID (full GE resource name)
# Optional env vars: GEMINI_DISPLAY_NAME, GEMINI_DESCRIPTION, GEMINI_TOOL_DESCRIPTION, AGENT_ENGINE_ID
register-gemini-enterprise:
@uvx agent-starter-pack@0.26.2 register-gemini-enterprise
# ==============================================================================
# Webhook Deployment
# ==============================================================================
WEBHOOK_REPO_NAME=code-review
DEPLOYMENT_REGION=us-central1
PROJECT_ID=your-gcp-project-id
WEBHOOK_SERVICE_NAME=code-review-webhook
# Directory to watch for changes (trailing slash = directory for git diff)
WEBHOOK_DIR=webhook/
deploy-webhook: validate-env
@echo "Checking for changes in the $(WEBHOOK_DIR) directory..."
@if [ ! -d .git ]; then \
echo "No .git directory (e.g. CI shallow clone). Proceeding with deployment..."; \
$(MAKE) build-and-deploy-webhook; \
elif git diff --quiet HEAD -- $(WEBHOOK_DIR) 2>/dev/null && \
git diff --quiet --cached -- $(WEBHOOK_DIR) 2>/dev/null; then \
echo "No changes in $(WEBHOOK_DIR). Skipping build."; \
else \
echo "Changes detected in $(WEBHOOK_DIR). Proceeding with deployment..."; \
$(MAKE) build-and-deploy-webhook; \
fi
# Internal target: create repo (if needed), build image, deploy to Cloud Run
build-and-deploy-webhook:
@echo "Checking for Artifact Registry repository..."
@if ! gcloud artifacts repositories describe $(WEBHOOK_REPO_NAME) --location=$(DEPLOYMENT_REGION) >/dev/null 2>&1; then \
echo "Creating repository $(WEBHOOK_REPO_NAME)..."; \
gcloud artifacts repositories create $(WEBHOOK_REPO_NAME) \
--repository-format=docker \
--location=$(DEPLOYMENT_REGION) \
--description="Docker repo for code-review-webhook"; \
else \
echo "Repository $(WEBHOOK_REPO_NAME) already exists."; \
fi
@echo "Building and pushing webhook image..."
@cd webhook && gcloud builds submit --tag $(DEPLOYMENT_REGION)-docker.pkg.dev/$(PROJECT_ID)/$(WEBHOOK_REPO_NAME)/$(WEBHOOK_SERVICE_NAME):latest
@echo "Deploying webhook to Cloud Run..."
@bash -c 'set -a; [ -f .env ] && source .env; set +a; \
gcloud run deploy $(WEBHOOK_SERVICE_NAME) \
--image $(DEPLOYMENT_REGION)-docker.pkg.dev/$(PROJECT_ID)/$(WEBHOOK_REPO_NAME)/$(WEBHOOK_SERVICE_NAME):latest \
--platform managed \
--region $(DEPLOYMENT_REGION) \
--allow-unauthenticated \
--set-env-vars "SECRET_MANAGER_PROJECT_ID=$$SECRET_MANAGER_PROJECT_ID,\
SECRET_MANAGER_SECRET_NAME=$$SECRET_MANAGER_SECRET_NAME,\
APP_ID_GITHUB=$$APP_ID_GITHUB,\
INSTALLATION_ID_GITHUB=$$INSTALLATION_ID_GITHUB,\
MYSELF=$$MYSELF,\
VERTEX_AI_PROJECT_ID=$$PROJECT_ID,\
VERTEX_AI_LOCATION=$(DEPLOYMENT_REGION),\
VERTEX_AI_RESOURCE_ID=$$VERTEX_AI_RESOURCE_ID"'
# Force build and deploy webhook only (bypass git change check)
build-webhook-force: build-and-deploy-webhook