-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdeploy
executable file
·60 lines (47 loc) · 1.3 KB
/
deploy
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
#!/bin/bash
set -e
if [ -z "$SSH_USER" ] || [ -z "$SSH_HOST" ]; then
echo "Error: SSH_USER or SSH_HOST not set"
exit 1
fi
# the local directory where the site is built
src="./site/.vitepress/dist"
if [ ! -d "$src" ]; then
echo "Error: $src does not exist"
exit 1
fi
# the site's base directory on the server
site_dir="/var/www/www.popclip.app"
# check that the git repo is clean
if [ -n "$(git status --porcelain)" ]; then
echo "Error: git repo is not clean"
exit 1
fi
# we use the git commit hash to generate a unique folder name
id="g$(git rev-parse HEAD | cut -c 1-11)"
# the full destination path
dest="${SSH_USER}@${SSH_HOST}:$site_dir/${id}"
echo "Sending files to ${dest}"
rsync -avzc "${src}/" "${dest}"
# complete the deployment on the server
ssh ${SSH_USER}@${SSH_HOST} 'bash -s' <<END_SCRIPT
set -e
echo "In remote script"
cd ${site_dir}
echo "In \$(pwd)"
echo "Update modification date of new folder"
touch ${id}
echo "Updating symlink"
ln -sfn ${id} static
echo "Removing old deployments"
# Remove all but the newest n deployment directories
# (List directories sorted by modification time and skip to the (n+1)th)
for dir in \$(ls -dt g*/ | tail -n +11); do
echo "removing \$dir"
rm -rf "\$dir"
done
echo "Listing files:"
ls -lt
echo "Done remote script"
END_SCRIPT
echo "Done"