| #!/bin/bash |
|
|
| |
|
|
| echo "🚀 Starting OpenResty + OpenCode Integration..." |
|
|
| |
| export GATEWAY_HOST=${GATEWAY_HOST:-127.0.0.1} |
| export GATEWAY_PORT=${GATEWAY_PORT:-57860} |
| export USERNAME=${USERNAME:-admin} |
| export PASSWORD=${PASSWORD:-admin123} |
|
|
| echo "📍 OpenCode will listen on: ${GATEWAY_HOST}:${GATEWAY_PORT}" |
| echo "🌐 Nginx will listen on: 0.0.0.0:7860" |
|
|
| |
| HTPASSWD_FILE="/usr/local/openresty/nginx/conf/.htpasswd" |
| echo "🔐 Generating .htpasswd file with user: ${USERNAME}" |
| echo "${USERNAME}:$(openssl passwd -apr1 ${PASSWORD})" > ${HTPASSWD_FILE} |
| echo "✅ .htpasswd file generated at ${HTPASSWD_FILE}" |
|
|
| |
| echo "🤖 Starting OpenCode server on port ${GATEWAY_PORT}..." |
| opencode serve --port ${GATEWAY_PORT} --hostname ${GATEWAY_HOST} & |
| OPENCODE_PID=$! |
|
|
| |
| echo "⏳ Waiting for OpenCode to start..." |
| sleep 5 |
|
|
| |
| if curl -s http://${GATEWAY_HOST}:${GATEWAY_PORT}/global/health > /dev/null; then |
| echo "✅ OpenCode server started successfully" |
| echo "📖 OpenCode API docs: http://${GATEWAY_HOST}:${GATEWAY_PORT}/doc" |
| else |
| echo "❌ OpenCode server failed to start" |
| exit 1 |
| fi |
|
|
| |
| echo "🌐 Starting OpenResty with nginx on port 7860..." |
| exec /usr/local/openresty/bin/openresty -g "daemon off;" & |
| OPENRESTY_PID=$! |
|
|
| |
| sleep 3 |
|
|
| |
| if curl -s http://localhost:7860/health > /dev/null; then |
| echo "✅ OpenResty started successfully" |
| echo "🔐 Basic Auth enabled: admin/admin123" |
| echo "🌐 Nginx serving: http://localhost:7860" |
| echo "🔗 API Gateway: http://localhost:7860/opencode/" |
| else |
| echo "❌ OpenResty failed to start" |
| |
| kill $OPENCODE_PID 2>/dev/null |
| exit 1 |
| fi |
|
|
| echo "" |
| echo "🎉 Integration Complete!" |
| echo "" |
| echo "📋 Available Endpoints:" |
| echo " • Main Site: http://localhost:7860/" |
| echo " • Health Check: http://localhost:7860/health" |
| echo " • OpenCode API: http://localhost:7860/opencode/" |
| echo " • OpenCode Docs: http://localhost:7860/opencode/doc" |
| echo " • API Gateway Health: http://localhost:7860/gateway/health" |
| echo "" |
| echo "🔐 Authentication: ${USERNAME}/${PASSWORD}" |
| echo "" |
| echo "🤖 OpenCode Status:" |
| if curl -s http://${GATEWAY_HOST}:${GATEWAY_PORT}/global/health > /dev/null; then |
| echo " ✅ Server: healthy" |
| echo " ✅ Version: $(curl -s http://${GATEWAY_HOST}:${GATEWAY_PORT}/global/health | grep -o '"version":"[^"]*' | cut -d'"' -f4)" |
| else |
| echo " ❌ Server: unhealthy" |
| fi |
| |
| # 保持容器运行,等待信号 |
| wait |