-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·52 lines (42 loc) · 1.49 KB
/
install.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
#!/bin/bash
set -e
# Function to display colorful logs
function color_log {
echo -e "\n\e[1;34m >> $1\e[0m" # Blue color for log messages
}
# Function to stop and remove Docker containers
function docker_compose_down {
color_log "An error occurred. Stopping and removing Docker containers..."
docker compose down
docker volume rm nadin-soft_mysql-data nadin-soft_redis-data
color_log "Docker containers stopped and removed successfully."
}
# Check if .env file exists, if not, copy .env.sample
if [ ! -f .env ]; then
color_log ".env file does not exist, copying .env.sample..."
cp .env.sample .env
fi
# Start Docker Compose
color_log "Starting Docker Compose..."
docker compose up -d || { docker_compose_down; exit 1; }
# Wait for MySQL to be ready
color_log "Waiting for MySQL to be ready..."
until docker exec mysql mysql -h localhost -u root -e 'SELECT 1;' &>/dev/null; do
sleep 1
done
color_log "MySQL is ready."
# Check if pnpm is installed, if not, install it
if ! command -v pnpm &> /dev/null; then
color_log "pnpm is not installed, installing..."
npm install -g pnpm
fi
# Install dependencies
color_log "Installing dependencies..."
pnpm i || { docker_compose_down; exit 1; }
# Run migration
color_log "Running migration..."
while true; do
pnpm migration:run && break || { color_log "Migration failed, waiting and retrying..."; sleep 1; }
done
color_log "All tasks completed successfully. Starting the server.."
pnpm start || { docker_compose_down; exit 1; }