-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-responsive-image-server
More file actions
executable file
·49 lines (37 loc) · 1.21 KB
/
deploy-responsive-image-server
File metadata and controls
executable file
·49 lines (37 loc) · 1.21 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
#!/bin/bash
set -x -e
REMOTE_SERVER=$1
# Check if the remote server parameter is provided
if [ -z "$REMOTE_SERVER" ]; then
echo "Usage: $0 machine-name"
exit 1
fi
# Variables for remote server and project
REMOTE_PROJECT_DIR="~/responsive-image-server"
REMOTE_SCRIPT="deploy_responsive-image-server.sh"
# Step 1: Create the deployment script locally
cat << EOF > /tmp/$REMOTE_SCRIPT
#!/bin/bash
set -e -x
# Navigate to project directory, create if it doesn't exist
mkdir -p $REMOTE_PROJECT_DIR
cd $REMOTE_PROJECT_DIR
# Pull the latest code from GitHub (master branch)
if [ ! -d ".git" ]; then
git clone git@github.com:shukebeta/responsive-image-server.git .
else
git pull origin master
fi
# Build and restart the Docker containers
docker compose build --no-cache
docker compose down
docker compose up -d
docker rmi -f \$(docker images -f dangling=true -q)
EOF
# Step 2: Copy the deployment script to the remote machine
scp /tmp/$REMOTE_SCRIPT $REMOTE_SERVER:/tmp/
# Step 3: Run the script on the remote machine via SSH
ssh $REMOTE_SERVER "bash /tmp/$REMOTE_SCRIPT"
# Step 4: Clean up the script from the remote machine
ssh $REMOTE_SERVER "rm /tmp/$REMOTE_SCRIPT"
echo "Deployment script executed on $REMOTE_SERVER."