|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -# Print starting message |
4 | | -echo "I am starting the game now" |
| 3 | +echo "🚀 Starting deployment process..." |
5 | 4 |
|
6 | | -mkdir changes |
| 5 | +# Define variables |
| 6 | +PROJECT_DIR="/home/weberqbot/orbits/stm.org" |
| 7 | +CONTAINER_NAME="stm.weberq.in" |
| 8 | +IMAGE_NAME="stm-image" |
7 | 9 |
|
8 | | -# Check if the directory exists |
9 | | -cd /home/weberqbot/orbits/stm.org || { echo "Error: Failed to change directory. Directory does not exist."; exit 1; } |
| 10 | +echo "🧹 Cleaning up old build (if any)..." |
| 11 | +docker stop $CONTAINER_NAME 2>/dev/null || echo "No running container to stop." |
| 12 | +docker rm $CONTAINER_NAME 2>/dev/null || echo "No container to remove." |
| 13 | +docker rmi $IMAGE_NAME 2>/dev/null || echo "No old image to remove." |
| 14 | + |
| 15 | +echo "📦 Pulling latest changes from Git..." |
| 16 | +cd "$PROJECT_DIR" || { echo "❌ Failed to change directory."; exit 1; } |
10 | 17 |
|
11 | | -# mkdir passing-working-fine |
12 | | -# Pull latest changes from git repository with sudo permissions |
13 | 18 | git pull || { |
14 | | - echo "Git pull failed due to ownership issues. Adding the directory to safe directories..." |
15 | | - git config --global --add safe.directory /home/weberqbot/orbits/stm.org || { echo "Error: Failed to add directory to safe list."; exit 1; } |
16 | | - echo "Retrying git pull..." |
17 | | - git pull || { echo "Git pull failed again. Please check the repository settings."; exit 1; } |
| 19 | + echo "Git pull failed, attempting to add safe directory..." |
| 20 | + git config --global --add safe.directory "$PROJECT_DIR" && git pull || { |
| 21 | + echo "❌ Git pull failed again. Exiting." |
| 22 | + exit 1 |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +echo "🐳 Building Docker image..." |
| 27 | +docker build -t $IMAGE_NAME . || { echo "❌ Docker build failed."; exit 1; } |
| 28 | + |
| 29 | +echo "🚢 Starting new Docker container..." |
| 30 | +docker run -d -p 8081:80 --name $CONTAINER_NAME $IMAGE_NAME || { |
| 31 | + echo "❌ Failed to start container."; exit 1 |
18 | 32 | } |
19 | 33 |
|
| 34 | +echo "✅ Deployment complete!" |
0 commit comments