-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·60 lines (51 loc) · 2.07 KB
/
deploy.sh
File metadata and controls
executable file
·60 lines (51 loc) · 2.07 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
#!/bin/bash
set -e # exit if any command fails
# --- Configuration ---
# Set the remote user and host IP address.
# IMPORTANT: Ensure you have set up SSH key-based authentication for this user.
# For example, run: ssh-copy-id user@192.168.1.83
REMOTE_USER="stefan"
REMOTE_HOST_IP="192.168.1.83"
# Set the remote directory where the project will be deployed.
# This directory will be created if it doesn't exist.
REMOTE_DIR="/home/${REMOTE_USER}/hackstream"
# --- Script ---
REMOTE_HOST="${REMOTE_USER}@${REMOTE_HOST_IP}"
echo "Deploying to ${REMOTE_HOST}..."
# Create the remote directory if it doesn't exist
ssh ${REMOTE_HOST} "mkdir -p ${REMOTE_DIR}"
# Use rsync to synchronize the project directory with the remote directory.
# This is more efficient than copying everything each time.
# --delete: deletes files on the remote that are not in the source.
rsync -avz --progress \
--exclude='.git/' \
--exclude='.pytest_cache/' \
--exclude='__pycache__/' \
--exclude='*.pyc' \
--exclude='*.pyo' \
--exclude='*.pyd' \
--exclude='.env*' \
--exclude='*.log' \
--exclude='.vscode/' \
--exclude='.idea/' \
--exclude='venv/' \
--exclude='.venv/' \
--exclude='env/' \
--exclude='*.egg-info/' \
--delete \
. ${REMOTE_HOST}:${REMOTE_DIR}
# Check if the rsync command was successful
if [ $? -eq 0 ]; then
echo "✅ Files synchronized successfully."
echo "🚀 Building and starting the application on the remote host..."
# Use ssh to execute docker-compose commands on the remote server.
# - `docker compose down`: Stops and removes the container if it's running.
# - `docker compose up -d --build`: Builds the image and starts the container in detached mode.
ssh ${REMOTE_HOST} "cd ${REMOTE_DIR} && sudo docker compose down && sudo docker compose up -d --build"
echo "✅ Application deployed successfully!"
echo "➡️ xpra server should be running on ${REMOTE_HOST_IP}:14500"
echo "➡️ You can now attach to it from a client on the same LAN."
else
echo "❌ rsync failed. Deployment aborted."
exit 1
fi