-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-services.sh
More file actions
executable file
·81 lines (66 loc) · 2.72 KB
/
deploy-services.sh
File metadata and controls
executable file
·81 lines (66 loc) · 2.72 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
#!/bin/bash
# Script to deploy all RetailShift application services to the remote server
# Set error handling
set -e
# Server details
SERVER_IP="144.126.212.250"
SERVER_USER="root"
SSH_KEY="~/.ssh/do-retailshift"
REMOTE_DIR="/opt/retailshift"
# Parse command line arguments
DEPLOY_INFRA=false
while getopts "i" opt; do
case ${opt} in
i )
DEPLOY_INFRA=true
;;
\? )
echo "Usage: $0 [-i]"
echo " -i Also deploy infrastructure services"
exit 1
;;
esac
done
echo "===== Deploying RetailShift Application Services ====="
# Check SSH key exists
if [ ! -f "${SSH_KEY/#\~/$HOME}" ]; then
echo "SSH key not found: ${SSH_KEY/#\~/$HOME}"
echo "Please ensure the SSH key exists or update the SSH_KEY variable in this script."
exit 1
fi
# Create the services directory on the remote server
echo "Creating remote directories..."
ssh -i $SSH_KEY $SERVER_USER@$SERVER_IP "mkdir -p $REMOTE_DIR/services"
# Copy the Docker Compose files
echo "Copying Docker Compose files..."
scp -i $SSH_KEY docker-compose.app.yml $SERVER_USER@$SERVER_IP:$REMOTE_DIR/
if [ "$DEPLOY_INFRA" = true ]; then
echo "Copying infrastructure Docker Compose file..."
scp -i $SSH_KEY docker-compose.infra.yml $SERVER_USER@$SERVER_IP:$REMOTE_DIR/
# Create infrastructure directories if they don't exist
ssh -i $SSH_KEY $SERVER_USER@$SERVER_IP "mkdir -p $REMOTE_DIR/data/mongodb $REMOTE_DIR/data/kafka $REMOTE_DIR/data/zookeeper $REMOTE_DIR/data/redis"
fi
# Copy the services code
echo "Copying services code..."
scp -i $SSH_KEY -r services/legacy-adapter $SERVER_USER@$SERVER_IP:$REMOTE_DIR/services/
scp -i $SSH_KEY -r services/inventory $SERVER_USER@$SERVER_IP:$REMOTE_DIR/services/
scp -i $SSH_KEY -r services/data-visualizer $SERVER_USER@$SERVER_IP:$REMOTE_DIR/services/
# Deploy services using Docker Compose
echo "Deploying services..."
if [ "$DEPLOY_INFRA" = true ]; then
echo "Starting infrastructure services..."
ssh -i $SSH_KEY $SERVER_USER@$SERVER_IP "cd $REMOTE_DIR && docker compose -f docker-compose.infra.yml up -d"
# Wait for infrastructure to be ready
echo "Waiting for infrastructure services to initialize (30 seconds)..."
sleep 30
fi
# Deploy application services
ssh -i $SSH_KEY $SERVER_USER@$SERVER_IP "cd $REMOTE_DIR && docker compose -f docker-compose.app.yml build && docker compose -f docker-compose.app.yml up -d"
# Verify services are running
echo "Verifying services are running..."
ssh -i $SSH_KEY $SERVER_USER@$SERVER_IP "cd $REMOTE_DIR && docker compose -f docker-compose.app.yml ps"
echo "===== Deployment completed ====="
echo "Legacy Adapter: http://$SERVER_IP:8081"
echo "Inventory Service: http://$SERVER_IP:8082"
echo "Data Visualizer: http://$SERVER_IP:8083"
echo "Main Application: http://$SERVER_IP"