-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
Β·135 lines (114 loc) Β· 4.01 KB
/
update.sh
File metadata and controls
executable file
Β·135 lines (114 loc) Β· 4.01 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
# Update script for Claude Code SDK Container
# Updates the SDK to latest version and rebuilds container
set -e
echo "π Claude Code SDK Container Update Script"
echo "==========================================="
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Check if Docker is running
if ! docker info > /dev/null 2>&1; then
echo -e "${RED}β Docker is not running. Please start Docker first.${NC}"
exit 1
fi
# Check current version
echo "Checking current Claude Code SDK version..."
CURRENT_VERSION=$(grep '"@anthropic-ai/claude-code"' package.json | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "unknown")
echo -e "Current version: ${BLUE}$CURRENT_VERSION${NC}"
echo ""
# Get container name from directory
CONTAINER_NAME="claude-code-$(basename "$(pwd)")"
IMAGE_NAME="claude-code-$(basename "$(pwd)")"
# Check if container exists
CONTAINER_EXISTS=$(docker ps -a --format "table {{.Names}}" | grep -c "$CONTAINER_NAME" || true)
CONTAINER_RUNNING=$(docker ps --format "table {{.Names}}" | grep -c "$CONTAINER_NAME" || true)
# Update packages
echo "Fetching latest version from npm..."
LATEST_VERSION=$(npm view @anthropic-ai/claude-code version 2>/dev/null || echo "")
if [ -z "$LATEST_VERSION" ]; then
echo -e "${RED}β Could not fetch latest version from npm${NC}"
exit 1
fi
echo -e "Latest version: ${GREEN}$LATEST_VERSION${NC}"
echo ""
# Check if update is needed
if [ "$CURRENT_VERSION" = "$LATEST_VERSION" ]; then
echo -e "${GREEN}β
Already on latest version!${NC}"
echo ""
read -p "Do you want to rebuild anyway? (y/N): " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Exiting without changes."
exit 0
fi
else
echo -e "${YELLOW}π¦ Update available: $CURRENT_VERSION β $LATEST_VERSION${NC}"
echo ""
fi
# Update package
echo "Updating Claude Code SDK..."
npm update @anthropic-ai/claude-code
echo -e "${GREEN}β
Package updated${NC}"
echo ""
# Build new image
echo "Building new Docker image..."
docker build -t "$IMAGE_NAME" . || {
echo -e "${RED}β Build failed${NC}"
exit 1
}
echo -e "${GREEN}β
Docker image built${NC}"
echo ""
# Handle existing container
if [ "$CONTAINER_RUNNING" -eq 1 ]; then
echo "Stopping running container..."
docker stop "$CONTAINER_NAME"
echo -e "${GREEN}β
Container stopped${NC}"
fi
if [ "$CONTAINER_EXISTS" -eq 1 ]; then
echo "Removing old container..."
docker rm "$CONTAINER_NAME"
echo -e "${GREEN}β
Old container removed${NC}"
fi
echo ""
# Start new container
echo "Starting new container..."
if [ -f .env ]; then
docker run -d --name "$CONTAINER_NAME" -p 8080:8080 --env-file .env "$IMAGE_NAME"
echo -e "${GREEN}β
Container started with .env file${NC}"
else
echo -e "${YELLOW}β οΈ No .env file found, starting with environment variables${NC}"
docker run -d --name "$CONTAINER_NAME" -p 8080:8080 "$IMAGE_NAME"
fi
echo ""
# Wait for container to be ready
echo "Waiting for container to be ready..."
sleep 3
# Test health endpoint
echo "Testing health endpoint..."
HEALTH_RESPONSE=$(curl -s http://localhost:8080/health 2>/dev/null || echo "FAILED")
if [[ "$HEALTH_RESPONSE" == "FAILED" ]]; then
echo -e "${RED}β Health check failed${NC}"
echo "Check logs with: docker logs $CONTAINER_NAME"
exit 1
elif echo "$HEALTH_RESPONSE" | grep -q '"status":"healthy"'; then
echo -e "${GREEN}β
Container is healthy${NC}"
else
echo -e "${YELLOW}β οΈ Container started but may not be healthy${NC}"
echo "Response: $HEALTH_RESPONSE"
fi
echo ""
# Show final status
NEW_VERSION=$(grep '"@anthropic-ai/claude-code"' package.json | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "unknown")
echo "==========================================="
echo -e "${GREEN}π Update complete!${NC}"
echo -e "Version: ${GREEN}$NEW_VERSION${NC}"
echo ""
echo "Container status:"
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep "$CONTAINER_NAME" || echo "Not running"
echo ""
echo "Test with: ./test.sh"