-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathrebuild.sh
67 lines (53 loc) · 1.54 KB
/
rebuild.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
# ###################################################################################
# #
# This script rebuilds the Next.js app and restarts the PM2 process with the latest #
# changes. It also updates the Prisma scheme and seeds the database. #
# #
# ###################################################################################
# Exit immediately if any command exits with a non-zero status
set -e
# Parsing command-line options
while getopts ":v:" opt; do
case $opt in
v)
variable="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# Exit if variable is not provided
if [ -z "$variable" ]; then
echo "Error: App instances not provided. Use the -v option."
exit 1
fi
# Accessing the variable passed via the command line
echo "Run for app instances: $variable"
# Stopping PM2 process
echo "Stopping PM2 process: $variable"
pm2 stop $variable
# Git actions
echo "Git actions"
git fetch
git pull
# Rebuilding Next.js App
echo "Rebuilding Next.js App"
# Install dependencies
pnpm install
# Update Prisma scheme
pnpm prisma db push
# Seed DB
pnpm prisma db seed
# Build Next.js App
pnpm build
# Start PM2 process
echo "Start PM2 process: $variable"
pm2 start $variable
echo "Script completed successfully."