feat: Add deployment scripts, Docker configuration, and documentation for Cloud MCP project
This commit is contained in:
118
deploy.sh
Executable file
118
deploy.sh
Executable file
@@ -0,0 +1,118 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Cloud MCP Deployment Script
|
||||
# This script builds and deploys the MCP server using Docker
|
||||
# Usage: ./deploy.sh [--pull] [--rebuild]
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Configuration
|
||||
CONTAINER_NAME="cloud-mcp"
|
||||
IMAGE_NAME="cloud-mcp"
|
||||
COMPOSE_FILE="docker-compose.yml"
|
||||
|
||||
# Functions
|
||||
log_info() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Check if Docker is running
|
||||
check_docker() {
|
||||
if ! docker info > /dev/null 2>&1; then
|
||||
log_error "Docker is not running. Please start Docker and try again."
|
||||
exit 1
|
||||
fi
|
||||
log_info "Docker is running"
|
||||
}
|
||||
|
||||
# Pull latest code from git (if --pull flag is set)
|
||||
pull_latest() {
|
||||
if [[ "$1" == "--pull" ]] || [[ "$*" == *"--pull"* ]]; then
|
||||
log_info "Pulling latest code from git..."
|
||||
git pull origin main || git pull origin master || log_warn "Failed to pull from git, continuing with local code"
|
||||
fi
|
||||
}
|
||||
|
||||
# Build Docker image
|
||||
build_image() {
|
||||
local rebuild=false
|
||||
if [[ "$*" == *"--rebuild"* ]]; then
|
||||
rebuild=true
|
||||
fi
|
||||
|
||||
log_info "Building Docker image..."
|
||||
|
||||
if [ "$rebuild" = true ]; then
|
||||
log_info "Force rebuilding image (no cache)..."
|
||||
docker-compose -f "$COMPOSE_FILE" build --no-cache
|
||||
else
|
||||
docker-compose -f "$COMPOSE_FILE" build
|
||||
fi
|
||||
|
||||
log_info "Docker image built successfully"
|
||||
}
|
||||
|
||||
# Stop existing container
|
||||
stop_container() {
|
||||
if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
|
||||
log_info "Stopping existing container..."
|
||||
docker-compose -f "$COMPOSE_FILE" down
|
||||
log_info "Container stopped"
|
||||
else
|
||||
log_info "No existing container found"
|
||||
fi
|
||||
}
|
||||
|
||||
# Start container
|
||||
start_container() {
|
||||
log_info "Starting container..."
|
||||
docker-compose -f "$COMPOSE_FILE" up -d
|
||||
log_info "Container started"
|
||||
}
|
||||
|
||||
# Show container status
|
||||
show_status() {
|
||||
log_info "Container status:"
|
||||
docker ps --filter "name=${CONTAINER_NAME}" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
|
||||
|
||||
log_info "Container logs (last 20 lines):"
|
||||
docker logs --tail 20 "${CONTAINER_NAME}" 2>&1 || log_warn "Could not fetch logs"
|
||||
}
|
||||
|
||||
# Main deployment flow
|
||||
main() {
|
||||
log_info "Starting deployment..."
|
||||
|
||||
check_docker
|
||||
pull_latest "$@"
|
||||
build_image "$@"
|
||||
stop_container
|
||||
start_container
|
||||
|
||||
# Wait a moment for container to start
|
||||
sleep 2
|
||||
|
||||
show_status
|
||||
|
||||
log_info "Deployment completed!"
|
||||
log_info "To view logs: docker logs -f ${CONTAINER_NAME}"
|
||||
log_info "To stop: docker-compose -f ${COMPOSE_FILE} down"
|
||||
}
|
||||
|
||||
# Run main function
|
||||
main "$@"
|
||||
|
||||
Reference in New Issue
Block a user