-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·237 lines (194 loc) · 6 KB
/
deploy.sh
File metadata and controls
executable file
·237 lines (194 loc) · 6 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
#!/bin/bash
# 部署脚本 - 自动化部署层级多智能体系统 API
set -e # 遇到错误立即退出
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 打印带颜色的消息
print_info() {
echo -e "${BLUE}ℹ${NC} $1"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
# 打印横幅
print_banner() {
echo ""
echo "═══════════════════════════════════════════════════════"
echo " 层级多智能体系统 API 部署脚本"
echo "═══════════════════════════════════════════════════════"
echo ""
}
# 检查命令是否存在
check_command() {
if ! command -v $1 &> /dev/null; then
print_error "$1 未安装"
return 1
fi
return 0
}
# 检查先决条件
check_prerequisites() {
print_info "检查先决条件..."
local all_good=true
# 检查 AWS CLI
if check_command aws; then
print_success "AWS CLI 已安装"
else
print_error "请安装 AWS CLI: https://aws.amazon.com/cli/"
all_good=false
fi
# 检查 SAM CLI
if check_command sam; then
print_success "SAM CLI 已安装"
else
print_error "请安装 SAM CLI: pip install aws-sam-cli"
all_good=false
fi
# 检查 Python
if check_command python3; then
print_success "Python3 已安装"
else
print_error "请安装 Python 3"
all_good=false
fi
# 检查 AWS 凭证
if aws sts get-caller-identity &> /dev/null; then
print_success "AWS 凭证已配置"
else
print_error "请配置 AWS 凭证: aws configure"
all_good=false
fi
if [ "$all_good" = false ]; then
exit 1
fi
echo ""
}
# 构建应用
build_app() {
print_info "构建应用..."
if sam build; then
print_success "构建成功"
else
print_error "构建失败"
exit 1
fi
echo ""
}
# 部署应用
deploy_app() {
print_info "部署应用..."
# 检查是否是首次部署
if [ ! -f "samconfig.toml" ]; then
print_warning "首次部署,将使用引导部署模式"
print_info "请按照提示输入配置参数..."
sam deploy --guided
else
print_info "使用现有配置部署..."
sam deploy
fi
if [ $? -eq 0 ]; then
print_success "部署成功"
else
print_error "部署失败"
exit 1
fi
echo ""
}
# 获取 API 端点
get_endpoints() {
print_info "获取 API 端点..."
# 从 CloudFormation 输出中提取端点
STACK_NAME=$(grep stack_name samconfig.toml | cut -d '"' -f 2 || echo "hierarchical-agents-api")
ENDPOINTS=$(aws cloudformation describe-stacks \
--stack-name $STACK_NAME \
--query 'Stacks[0].Outputs' \
--output table 2>/dev/null)
if [ $? -eq 0 ]; then
echo ""
echo "═══════════════════════════════════════════════════════"
echo " API 端点"
echo "═══════════════════════════════════════════════════════"
echo "$ENDPOINTS"
else
print_warning "无法获取端点信息"
fi
echo ""
}
# 测试健康检查
test_health_check() {
print_info "测试健康检查端点..."
STACK_NAME=$(grep stack_name samconfig.toml | cut -d '"' -f 2 || echo "hierarchical-agents-api")
HEALTH_ENDPOINT=$(aws cloudformation describe-stacks \
--stack-name $STACK_NAME \
--query 'Stacks[0].Outputs[?OutputKey==`HealthCheckEndpoint`].OutputValue' \
--output text 2>/dev/null)
if [ -n "$HEALTH_ENDPOINT" ]; then
RESPONSE=$(curl -s -w "\n%{http_code}" "$HEALTH_ENDPOINT")
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
BODY=$(echo "$RESPONSE" | head -n-1)
if [ "$HTTP_CODE" = "200" ]; then
print_success "健康检查通过"
echo "响应: $BODY"
else
print_warning "健康检查失败 (HTTP $HTTP_CODE)"
echo "响应: $BODY"
fi
else
print_warning "无法获取健康检查端点"
fi
echo ""
}
# 显示下一步操作
show_next_steps() {
echo ""
echo "═══════════════════════════════════════════════════════"
echo " 下一步操作"
echo "═══════════════════════════════════════════════════════"
echo ""
echo "1. 测试 API:"
echo " curl -X POST <ExecuteEndpoint> \\"
echo " -H \"Content-Type: application/json\" \\"
echo " -d @examples/simple_request.json"
echo ""
echo "2. 查看日志:"
echo " sam logs -n HierarchicalAgentsFunction --tail"
echo ""
echo "3. 本地测试:"
echo " export AWS_BEDROCK_API_KEY='your-api-key'"
echo " python test_api.py"
echo ""
echo "4. 更新部署:"
echo " ./deploy.sh"
echo ""
echo "5. 删除堆栈:"
echo " sam delete"
echo ""
}
# 主函数
main() {
print_banner
# 检查参数
if [ "$1" = "--skip-checks" ]; then
print_warning "跳过先决条件检查"
else
check_prerequisites
fi
build_app
deploy_app
get_endpoints
test_health_check
show_next_steps
print_success "部署完成!"
}
# 运行主函数
main "$@"