-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
79 lines (61 loc) · 1.8 KB
/
deploy.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
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# Function to log messages
log_message() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> storage/logs/deploy.log
}
# Ensure the script is called from the Laravel root folder
if [ ! -f artisan ]; then
echo "Error: artisan file not found. Make sure you're in the Laravel root directory."
exit 1
fi
# Log start of deployment
log_message "Deployment started."
# Get APP_ENV from .env file
APP_ENV=$(grep -w APP_ENV .env | cut -d '=' -f2)
# Install composer dependencies
log_message "Running composer install..."
if [ "$APP_ENV" == "production" ]; then
composer install --no-dev --optimize-autoloader
else
composer install
fi
if [ $? -ne 0 ]; then
log_message "Composer install failed."
echo "Error: Composer install failed."
exit 1
fi
log_message "Composer install completed."
# Migrate the database
log_message "Running database migrations..."
php artisan migrate --force
if [ $? -ne 0 ]; then
log_message "Database migration failed."
echo "Error: Database migration failed."
exit 1
fi
log_message "Database migrations completed."
# Seed the database
log_message "Seeding the database..."
php artisan db:seed --force
if [ $? -ne 0 ]; then
log_message "Database seeding failed."
echo "Error: Database seeding failed."
exit 1
fi
log_message "Database seeding completed."
# Clear and optimize Laravel caches
log_message "Optimizing application..."
php artisan cache:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
if [ $? -ne 0 ]; then
log_message "Application optimization failed."
echo "Error: Application optimization failed."
exit 1
fi
log_message "Application optimized successfully."
# Log end of deployment
log_message "Deployment completed successfully."
# Success message
echo "Deployment completed successfully."