Skip to content

Commit 0650f4a

Browse files
authored
Build Docker Image after every update
1 parent 236f962 commit 0650f4a

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

Script.sh

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
#!/bin/bash
22

3-
# Print starting message
4-
echo "I am starting the game now"
3+
echo "🚀 Starting deployment process..."
54

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"
79

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; }
1017

11-
# mkdir passing-working-fine
12-
# Pull latest changes from git repository with sudo permissions
1318
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
1832
}
1933

34+
echo "✅ Deployment complete!"

0 commit comments

Comments
 (0)