-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·67 lines (52 loc) · 1.6 KB
/
update.sh
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
61
62
63
64
65
66
67
#!/bin/bash
# Configuration
CONTAINER_NAME="blog"
DIRECTORY_NAME="blog"
GITHUB_REPO="https://[email protected]/timblazing/blog"
# Exit on any error
set -e
# Function to handle errors
handle_error() {
echo "Error occurred in update script. Check the error message above."
exit 1
}
# Set error handler
trap 'handle_error' ERR
echo "Starting update process..."
# Stop and remove all containers
echo "Stopping Docker containers..."
docker compose down 2>/dev/null || true
docker rm -f $(docker ps -a -q --filter name=$CONTAINER_NAME) 2>/dev/null || true
# Remove Docker images
echo "Removing Docker images..."
docker rmi -f $(docker images -q --filter reference=$CONTAINER_NAME) 2>/dev/null || true
# Store current directory
CURRENT_DIR=$(pwd)
DIR_NAME=$(basename "$CURRENT_DIR")
# Remove old directory
echo "Removing old project directory..."
if [ "$DIR_NAME" = "$DIRECTORY_NAME" ]; then
cd ..
fi
rm -rf $DIRECTORY_NAME
# Clone repository
echo "Cloning repository..."
if ! git clone $GITHUB_REPO; then
echo "Failed to clone repository. Please check your internet connection and GitHub token."
exit 1
fi
# Change to project directory
cd $DIRECTORY_NAME || exit 1
# Start Docker container
echo "Starting Docker container..."
if ! docker compose up --build -d; then
echo "Failed to start Docker container. Please check Docker logs for details."
exit 1
fi
# Clean up unused and dangling images
echo "Cleaning up unused Docker images..."
docker image prune -f
# Wait for container to be ready
echo "Waiting for container to be ready..."
sleep 5
echo "Update complete!"