Initial commit: add .gitignore and README
This commit is contained in:
120
migration/migrate-to-api-gateway.sh
Executable file
120
migration/migrate-to-api-gateway.sh
Executable file
@@ -0,0 +1,120 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Load shared libraries
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/../lib/init.sh"
|
||||
|
||||
# Script to help migrate projects to unified API gateway
|
||||
|
||||
set -e
|
||||
|
||||
PROJECT_NAME="${1:-}"
|
||||
SERVICE_URL="${2:-}"
|
||||
|
||||
if [ -z "$PROJECT_NAME" ] || [ -z "$SERVICE_URL" ]; then
|
||||
echo "🚪 API Gateway Migration Helper"
|
||||
echo ""
|
||||
echo "Usage: $0 <project-name> <service-url>"
|
||||
echo ""
|
||||
echo "Example: $0 my-service http://my-service:8080"
|
||||
echo ""
|
||||
echo "This script helps migrate a project to use the unified API gateway."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "🚪 Migrating $PROJECT_NAME to unified API gateway..."
|
||||
|
||||
# Create Kong service configuration
|
||||
cat > "/tmp/${PROJECT_NAME}-kong-service.yaml" << EOF
|
||||
apiVersion: configuration.konghq.com/v1
|
||||
kind: KongService
|
||||
metadata:
|
||||
name: ${PROJECT_NAME}
|
||||
namespace: api-gateway
|
||||
spec:
|
||||
url: ${SERVICE_URL}
|
||||
protocol: http
|
||||
port: 80
|
||||
path: /
|
||||
connect_timeout: 60000
|
||||
write_timeout: 60000
|
||||
read_timeout: 60000
|
||||
EOF
|
||||
|
||||
# Create Kong route configuration
|
||||
cat > "/tmp/${PROJECT_NAME}-kong-route.yaml" << EOF
|
||||
apiVersion: configuration.konghq.com/v1
|
||||
kind: KongRoute
|
||||
metadata:
|
||||
name: ${PROJECT_NAME}-route
|
||||
namespace: api-gateway
|
||||
spec:
|
||||
service: ${PROJECT_NAME}
|
||||
paths:
|
||||
- /api/${PROJECT_NAME}
|
||||
methods:
|
||||
- GET
|
||||
- POST
|
||||
- PUT
|
||||
- DELETE
|
||||
strip_path: false
|
||||
preserve_host: true
|
||||
EOF
|
||||
|
||||
# Create Kong plugin for rate limiting
|
||||
cat > "/tmp/${PROJECT_NAME}-kong-plugin.yaml" << EOF
|
||||
apiVersion: configuration.konghq.com/v1
|
||||
kind: KongPlugin
|
||||
metadata:
|
||||
name: ${PROJECT_NAME}-rate-limit
|
||||
namespace: api-gateway
|
||||
plugin: rate-limiting
|
||||
config:
|
||||
minute: 100
|
||||
hour: 1000
|
||||
policy: local
|
||||
fault_tolerant: true
|
||||
hide_client_headers: false
|
||||
EOF
|
||||
|
||||
# Create Kong plugin for CORS
|
||||
cat > "/tmp/${PROJECT_NAME}-kong-cors.yaml" << EOF
|
||||
apiVersion: configuration.konghq.com/v1
|
||||
kind: KongPlugin
|
||||
metadata:
|
||||
name: ${PROJECT_NAME}-cors
|
||||
namespace: api-gateway
|
||||
plugin: cors
|
||||
config:
|
||||
origins:
|
||||
- "*"
|
||||
methods:
|
||||
- GET
|
||||
- POST
|
||||
- PUT
|
||||
- DELETE
|
||||
- OPTIONS
|
||||
headers:
|
||||
- Accept
|
||||
- Authorization
|
||||
- Content-Type
|
||||
exposed_headers:
|
||||
- X-Auth-Token
|
||||
credentials: true
|
||||
max_age: 3600
|
||||
EOF
|
||||
|
||||
echo "✅ Created Kong configuration templates:"
|
||||
echo " - /tmp/${PROJECT_NAME}-kong-service.yaml"
|
||||
echo " - /tmp/${PROJECT_NAME}-kong-route.yaml"
|
||||
echo " - /tmp/${PROJECT_NAME}-kong-plugin.yaml"
|
||||
echo " - /tmp/${PROJECT_NAME}-kong-cors.yaml"
|
||||
echo ""
|
||||
echo "📝 Next steps:"
|
||||
echo " 1. Review and customize configurations"
|
||||
echo " 2. Update service URL if needed"
|
||||
echo " 3. Apply Kong resources:"
|
||||
echo " kubectl apply -f /tmp/${PROJECT_NAME}-kong-*.yaml"
|
||||
echo ""
|
||||
echo "📖 See docs/API_GATEWAY_MIGRATION_GUIDE.md for detailed instructions"
|
||||
|
||||
Reference in New Issue
Block a user