-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdeploy-ssh.sh
More file actions
executable file
·31 lines (24 loc) · 835 Bytes
/
deploy-ssh.sh
File metadata and controls
executable file
·31 lines (24 loc) · 835 Bytes
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
#!/bin/bash
# Check if both arguments are provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 user@host remote/path"
exit 1
fi
REMOTE_TARGET=$1
REMOTE_PATH=$2
LOCAL_FILE="./build/app.tar.gz"
ssh "$REMOTE_TARGET" "cd \"$REMOTE_PATH\" && docker compose down"
# 1. Create the remote directory structure
# We use escaped quotes to ensure the remote shell sees the path as a single argument
echo "Ensuring remote directory exists..."
ssh "$REMOTE_TARGET" "mkdir -p \"$REMOTE_PATH/build\""
# 2. Upload the file
if [ $? -eq 0 ]; then
echo "Uploading $LOCAL_FILE to $REMOTE_TARGET:$REMOTE_PATH/build/"
scp "$LOCAL_FILE" $REMOTE_TARGET:$REMOTE_PATH/build/
else
echo "Error: Could not create remote directory. Skipping upload."
exit 1
fi
ssh "$REMOTE_TARGET" "cd \"$REMOTE_PATH\" && docker compose up -d"
echo "Done!"