-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·99 lines (82 loc) · 3.44 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·99 lines (82 loc) · 3.44 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
#!/bin/bash
# Simple deployment script for MCP server to OpenShift
# Usage: ./deploy.sh [project-name] [--context=name]
set -e
PROJECT="mcp-demo"
CTX=""
for arg in "$@"; do
case "$arg" in
--context=*) CTX="${arg#--context=}" ;;
*) PROJECT="$arg" ;;
esac
done
# Build oc flags for context (empty string if no context specified)
OC_CTX=""
if [ -n "$CTX" ]; then
OC_CTX="--context=$CTX"
fi
echo "========================================="
echo "MCP Server Deployment to OpenShift"
echo "========================================="
echo "Project: $PROJECT"
if [ -n "$CTX" ]; then
echo "Context: $CTX"
fi
echo ""
# Check if logged in to OpenShift
if ! oc whoami $OC_CTX &>/dev/null; then
echo "Error: Not logged in to OpenShift. Please run 'oc login' first."
exit 1
fi
# Create namespace if it doesn't exist
echo "→ Setting up namespace..."
if oc get namespace "$PROJECT" $OC_CTX &>/dev/null; then
echo " Using existing namespace: $PROJECT"
else
echo " Creating new namespace: $PROJECT"
oc create namespace "$PROJECT" $OC_CTX
fi
# Apply OpenShift resources
echo "→ Applying OpenShift resources..."
sed "s|image: mcp-server:latest|image: image-registry.openshift-image-registry.svc:5000/$PROJECT/mcp-server:latest|g" openshift.yaml | oc apply -f - -n "$PROJECT" $OC_CTX
# Start build
echo "→ Building container image..."
echo " Creating filtered build context..."
# Create a temporary directory for the build context
BUILD_DIR=$(mktemp -d)
trap "rm -rf $BUILD_DIR" EXIT
# Copy only necessary files (exclude __pycache__ and .pyc files)
cp Containerfile requirements.txt pyproject.toml "$BUILD_DIR/"
# Use rsync to copy src/ while excluding cache files
rsync -a --exclude='__pycache__' --exclude='*.pyc' --exclude='*.pyo' --exclude='.mypy_cache' src/ "$BUILD_DIR/src/"
# FIX: Claude Code's Write tool creates files with 600 permissions (owner-only).
# OpenShift containers run as arbitrary non-root UIDs that need at least 644.
# Fix permissions in the build directory before sending to OpenShift.
# Note: Containerfile also has this fix as a backup, but fixing here provides visibility.
FIXED_COUNT=$(find "$BUILD_DIR/src" -name "*.py" -perm 600 2>/dev/null | wc -l | tr -d ' ')
if [ "$FIXED_COUNT" -gt "0" ]; then
echo " Fixing $FIXED_COUNT file(s) with 600 permissions (Claude Code Write tool issue)..."
find "$BUILD_DIR/src" -name "*.py" -perm 600 -exec chmod 644 {} \;
fi
echo " Starting binary build with filtered context..."
oc start-build mcp-server --from-dir="$BUILD_DIR" --follow -n "$PROJECT" $OC_CTX
# Wait for rollout
echo "→ Deploying application..."
oc rollout restart deployment/mcp-server -n "$PROJECT" $OC_CTX 2>/dev/null || true
oc rollout status deployment/mcp-server -n "$PROJECT" $OC_CTX --timeout=300s
# Get route (host and path)
ROUTE_HOST=$(oc get route mcp-server -n "$PROJECT" $OC_CTX -o jsonpath='{.spec.host}' 2>/dev/null || echo "")
ROUTE_PATH=$(oc get route mcp-server -n "$PROJECT" $OC_CTX -o jsonpath='{.spec.path}' 2>/dev/null || echo "/mcp/")
echo ""
echo "========================================="
echo "✅ Deployment Complete!"
echo "========================================="
if [ -n "$ROUTE_HOST" ]; then
echo "MCP Server URL: https://${ROUTE_HOST}${ROUTE_PATH}"
echo ""
echo "Test with MCP Inspector:"
echo " npx @modelcontextprotocol/inspector https://${ROUTE_HOST}${ROUTE_PATH}"
else
echo "Warning: Could not retrieve route URL"
fi
echo "========================================="