-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
42 lines (32 loc) · 1.04 KB
/
deploy.sh
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
#!/bin/bash
# Variables
REMOTE_HOST="167.71.191.78"
REMOTE_USER="deploy"
APP_DIR="/home/deploy/app"
# Function to execute SSH command
execute_ssh() {
echo "ssh command: $1"
ssh -t -o StrictHostKeyChecking=no "$REMOTE_USER@$REMOTE_HOST" "cd $APP_DIR; $1"
if [ $? -ne 0 ]; then
echo "Error executing command: $1"
exit 1
fi
}
opt_execute_ssh() {
echo "(optional) ssh command: $1"
ssh -t -o StrictHostKeyChecking=no "$REMOTE_USER@$REMOTE_HOST" "cd $APP_DIR; $1"
}
# Stop the previous docker-compose
execute_ssh "docker-compose down"
# Pull the latest code from the git repo
execute_ssh "source ~/.start_ssh && git fetch origin && git reset --hard origin/master && git pull origin master"
# Fix permissions
execute_ssh "chmod 777 ./entrypoint.sh"
# Build using docker-compose
execute_ssh "docker-compose build"
# Start the services using docker-compose
execute_ssh "docker-compose up -d"
# Start the services using docker-compose
execute_ssh "sleep 2 && docker-compose ps"
echo ""
echo "********Deployment complete!********"