-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·68 lines (53 loc) · 1.6 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
#!/usr/bin/env bash
user=$1
backup_path=$2
project_path=$3
if [[ $user == "" || $backup_path == "" || $project_path == "" ]]; then
echo "- [x] Args are required: (1) user (2) absolute script path (3) absolute project path"
exit 1
fi
# Find bin directory path for global npm packages using 'npm config get prefix'
PATH=$PATH:/home/$USER/.nvm/versions/node/lts/bin
# Stop portfolio service
pm2 delete nextjs-portfolio && pm2 save -f
if $?; then
echo "- [x] unable to delete existing project from pm2 list"
exit 1
fi
files_need_backup=(
"prisma/db.sqlite" # current database
".env" # .env file
"src/config/app.ts" # app configuration
)
# Take backups
for file in "${files_need_backup[@]}"; do
if [ -f "$project_path/$file" ]; then
filename=$(basename "$file")
cp -f "$project_path/$file" "$backup_path/$filename"
fi
done
# Remove Everything in base path
rm -rf "$project_path"
# Clone Repository
git clone ssh://[email protected]:AlanD20/aland20.com.git "$project_path/."
# Recover .env file if exists
if [ -f "$backup_path/.env" ]; then
cp -f "$backup_path/.env" "$project_path/.env"
fi
# Recover Backups
for file in "${files_need_backup[@]}"; do
filename=$(basename "$file")
if [ -f "$backup_path/$filename" ]; then
cp -f "$backup_path/$filename" "$project_path/$file"
echo "- [x] Successful restore: $file"
continue
fi
echo "- [x] Failed to restore: $file"
done
# Install dependencies
cd "$project_path" && pnpm && pnpm db:push && pnpm build && pnpm pm2 && pm2 save -f
if $?; then
echo "- [x] Failed to build project"
exit 1
fi
echo "- [x] Deployment successful!"