-
Notifications
You must be signed in to change notification settings - Fork 166
/
Copy pathbuild-site.sh
executable file
·61 lines (49 loc) · 1.4 KB
/
build-site.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
#!/bin/bash
set -e
site=$1
if [ "X$site" != "Xiojs" ] && [ "X$site" != "Xnodejs" ]; then
echo "Usage: build-site.sh < iojs | nodejs >"
exit 1
fi
pidof -s -o '%PPID' -x $(basename $0) > /dev/null 2>&1 && \
echo "$(basename $0) already running" && \
exit 1
clonedir=/home/www/github/${site}
if [ ! -d "${clonedir}" ]; then
repo="${site}.org"
git clone --depth 2 https://github.com/nodejs/${repo}.git $clonedir
fi
if [ "$site" == "nodejs" ]; then
build_cmd="npm run deploy"
rsync_from="build/"
else
build_cmd="node_modules/.bin/gulp build"
rsync_from="public/"
fi
cd $clonedir
git reset --hard
git clean -fdx
git fetch origin
git checkout origin/main
nodeuid=$(grep ^nodejs: /etc/passwd | awk -F: '{print $3}')
nodegid=$(grep ^nodejs: /etc/passwd | awk -F: '{print $4}')
docker pull node:lts-bullseye
docker run \
--rm \
-v ${clonedir}:/website/ \
-v /home/nodejs/.npm:/npm/ \
node:lts-bullseye \
bash -c " \
apt-get update && apt-get install -y rsync && \
addgroup nodejs --gid ${nodeuid} && \
adduser nodejs --uid ${nodeuid} --gid ${nodegid} --gecos nodejs --disabled-password && \
su nodejs -c ' \
npm config set loglevel http && \
npm config set cache /npm/ && \
cd /website/ && \
npm ci && \
$build_cmd \
' \
"
rsync -avz --delete --exclude .git ${clonedir}/${rsync_from} /home/www/${site}/
/home/nodejs/queue-cdn-purge.sh $site build-site