forked from mihajlovicjj/redmine-mcp-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·234 lines (201 loc) · 6.01 KB
/
deploy.sh
File metadata and controls
executable file
·234 lines (201 loc) · 6.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/bin/bash
# Docker deployment script for Redmine MCP Server
# This script builds and deploys the Docker container with proper configuration
set -e # Exit on error
echo "🐳 Redmine MCP Server Docker Deployment"
echo "========================================"
# Configuration
CONTAINER_NAME="redmine-mcp-server"
IMAGE_NAME="redmine-mcp"
NETWORK_NAME="redmine-mcp-network"
# Function to check if Docker is running
check_docker() {
if ! docker info > /dev/null 2>&1; then
echo "❌ Docker is not running. Please start Docker first."
exit 1
fi
echo "✅ Docker is running"
}
# Function to check if .env.docker file exists
check_env_file() {
if [ ! -f .env.docker ]; then
echo "❌ .env.docker file not found"
echo "📋 Creating .env.docker from .env.example..."
if [ -f .env.example ]; then
cp .env.example .env.docker
echo "⚠️ Please edit .env.docker with your Redmine configuration before running again"
exit 1
else
echo "❌ .env.example not found. Please create .env.docker manually"
exit 1
fi
fi
echo "✅ .env.docker file found"
}
# Function to build Docker image
build_image() {
echo "🔨 Building Docker image..."
docker build -t $IMAGE_NAME:latest .
echo "✅ Docker image built successfully"
}
# Function to create Docker network
create_network() {
if ! docker network ls | grep -q $NETWORK_NAME; then
echo "🌐 Creating Docker network: $NETWORK_NAME"
docker network create $NETWORK_NAME
else
echo "✅ Docker network $NETWORK_NAME already exists"
fi
}
# Function to stop and remove existing container
cleanup_container() {
if docker ps -q -f name=$CONTAINER_NAME | grep -q .; then
echo "🛑 Stopping existing container..."
docker stop $CONTAINER_NAME
fi
if docker ps -aq -f name=$CONTAINER_NAME | grep -q .; then
echo "🗑️ Removing existing container..."
docker rm $CONTAINER_NAME
fi
}
# Function to run the container
run_container() {
echo "🚀 Starting container..."
docker run -d \
--name $CONTAINER_NAME \
--network $NETWORK_NAME \
-p 8000:8000 \
--env-file .env.docker \
-v "$(pwd)/logs:/app/logs" \
-v "$(pwd)/data:/app/data" \
--restart unless-stopped \
$IMAGE_NAME:latest
echo "✅ Container started successfully"
echo "📊 Container status:"
docker ps -f name=$CONTAINER_NAME --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
}
# Function to show logs
show_logs() {
echo "📋 Container logs (last 20 lines):"
echo "--------------------------------"
docker logs --tail 20 $CONTAINER_NAME
echo "--------------------------------"
echo "💡 To follow logs: docker logs -f $CONTAINER_NAME"
}
# Function to test the deployment
test_deployment() {
echo "🧪 Testing deployment..."
sleep 5 # Wait for container to start
if curl -s -f http://localhost:8000/health > /dev/null 2>&1; then
echo "✅ Health check passed"
else
echo "⚠️ Health check failed - checking if server is starting..."
sleep 10
if curl -s -f http://localhost:8000/health > /dev/null 2>&1; then
echo "✅ Health check passed (after delay)"
else
echo "❌ Health check failed"
echo "🔍 Container logs:"
docker logs --tail 10 $CONTAINER_NAME
fi
fi
}
# Function to display usage information
show_usage() {
cat << EOF
🐳 Redmine MCP Server Docker Deployment Script
Usage: $0 [OPTIONS]
Options:
--build-only Build the Docker image only
--no-test Skip deployment testing
--cleanup Stop and remove container
--logs Show container logs
--status Show container status
--help Show this help message
Examples:
$0 # Full deployment (build + run + test)
$0 --build-only # Build image only
$0 --cleanup # Clean up existing deployment
$0 --logs # Show current container logs
$0 --status # Show container status
Container will be available at: http://localhost:8000
MCP endpoint: http://localhost:8000/mcp
EOF
}
# Parse command line arguments
BUILD_ONLY=false
NO_TEST=false
CLEANUP_ONLY=false
LOGS_ONLY=false
STATUS_ONLY=false
while [[ $# -gt 0 ]]; do
case $1 in
--build-only)
BUILD_ONLY=true
shift
;;
--no-test)
NO_TEST=true
shift
;;
--cleanup)
CLEANUP_ONLY=true
shift
;;
--logs)
LOGS_ONLY=true
shift
;;
--status)
STATUS_ONLY=true
shift
;;
--help)
show_usage
exit 0
;;
*)
echo "❌ Unknown option: $1"
show_usage
exit 1
;;
esac
done
# Main execution flow
main() {
check_docker
if [ "$LOGS_ONLY" = true ]; then
show_logs
exit 0
fi
if [ "$STATUS_ONLY" = true ]; then
echo "📊 Container status:"
docker ps -f name=$CONTAINER_NAME --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
exit 0
fi
if [ "$CLEANUP_ONLY" = true ]; then
cleanup_container
echo "✅ Cleanup completed"
exit 0
fi
check_env_file
build_image
if [ "$BUILD_ONLY" = true ]; then
echo "✅ Build completed. Image: $IMAGE_NAME:latest"
exit 0
fi
create_network
cleanup_container
run_container
if [ "$NO_TEST" = false ]; then
test_deployment
fi
echo ""
echo "🎉 Deployment completed!"
echo "🌐 Server URL: http://localhost:8000"
echo "🔗 MCP Endpoint: http://localhost:8000/mcp"
echo "📋 View logs: docker logs -f $CONTAINER_NAME"
echo "🛑 Stop container: docker stop $CONTAINER_NAME"
}
# Run main function
main "$@"