94 lines
2.5 KiB
Bash
94 lines
2.5 KiB
Bash
#!/bin/bash
|
|
# Deploy agent to Kubernetes cluster
|
|
|
|
set -e
|
|
|
|
echo "=========================================="
|
|
echo "Agent Deployment Script"
|
|
echo "=========================================="
|
|
|
|
# Configuration
|
|
AGENT_IMAGE="swarm-agent:latest"
|
|
AGENT_ID="${AGENT_ID:-agent-$(date +%s)}"
|
|
AGENT_CAPABILITIES="${AGENT_CAPABILITIES:-general,python}"
|
|
|
|
echo "Agent ID: $AGENT_ID"
|
|
echo "Agent Capabilities: $AGENT_CAPABILITIES"
|
|
|
|
# Check required environment variables
|
|
if [ -z "$OPENAI_API_KEY" ]; then
|
|
echo "Error: OPENAI_API_KEY environment variable not set"
|
|
exit 1
|
|
fi
|
|
|
|
# Build Docker image
|
|
echo ""
|
|
echo "Building Docker image..."
|
|
docker build -f Dockerfile.agent -t $AGENT_IMAGE .
|
|
|
|
# Load image into kind cluster
|
|
echo ""
|
|
echo "Loading image into kind cluster..."
|
|
kind load docker-image $AGENT_IMAGE
|
|
|
|
# Create secrets if they don't exist
|
|
echo ""
|
|
echo "Creating/updating secrets..."
|
|
|
|
# Model API key (OpenAI-compatible)
|
|
kubectl create secret generic openai-secret \
|
|
--from-literal=api-key="$OPENAI_API_KEY" \
|
|
--dry-run=client -o yaml | kubectl apply -f -
|
|
|
|
# Git credentials (optional)
|
|
if [ -n "$GIT_USERNAME" ] && [ -n "$GIT_PASSWORD" ]; then
|
|
kubectl create secret generic git-credentials \
|
|
--from-literal=username="$GIT_USERNAME" \
|
|
--from-literal=password="$GIT_PASSWORD" \
|
|
--dry-run=client -o yaml | kubectl apply -f -
|
|
else
|
|
echo "Note: GIT_USERNAME and GIT_PASSWORD not set, skipping git credentials"
|
|
fi
|
|
|
|
# Create ConfigMap
|
|
echo ""
|
|
echo "Creating/updating ConfigMap..."
|
|
kubectl create configmap swarm-config \
|
|
--from-literal=git-repo-url="${GIT_REPO_URL:-}" \
|
|
--from-literal=openai-model="${OPENAI_MODEL:-gpt-4o-mini}" \
|
|
--from-literal=openai-api-base="${OPENAI_API_BASE:-https://api.openai.com/v1}" \
|
|
--dry-run=client -o yaml | kubectl apply -f -
|
|
|
|
# Deploy agent pod
|
|
echo ""
|
|
echo "Deploying agent pod..."
|
|
export AGENT_ID
|
|
export AGENT_CAPABILITIES
|
|
envsubst < k8s/agent-pod-template.yaml | kubectl apply -f -
|
|
|
|
# Wait for pod to be ready
|
|
echo ""
|
|
echo "Waiting for agent pod to be ready..."
|
|
kubectl wait --for=condition=Ready pod/agent-$AGENT_ID --timeout=60s || true
|
|
|
|
# Show pod status
|
|
echo ""
|
|
echo "Agent pod status:"
|
|
kubectl get pod agent-$AGENT_ID
|
|
|
|
# Show logs
|
|
echo ""
|
|
echo "Agent logs (last 20 lines):"
|
|
kubectl logs agent-$AGENT_ID --tail=20 || echo "Pod not ready yet"
|
|
|
|
echo ""
|
|
echo "=========================================="
|
|
echo "Agent deployment complete!"
|
|
echo "=========================================="
|
|
echo ""
|
|
echo "To view logs:"
|
|
echo " kubectl logs -f agent-$AGENT_ID"
|
|
echo ""
|
|
echo "To delete agent:"
|
|
echo " kubectl delete pod agent-$AGENT_ID"
|