-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathci.sh
executable file
·79 lines (63 loc) · 2.01 KB
/
ci.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
#!/bin/bash
# This is a helper script to set up a very simple CI dev/testing server. It can
# be used with `cron` in order to set up regular builds, e.g. for every 15 minutes:
#
# `crontab -e`
#
# @reboot /home/username/rethinkdb.sh > /home/username/rethinkdb.log
# */15 * * * * /home/username/master.sh > /home/username/master.log
#
# To use this script, create a script per server instance, e.g. `master.sh`:
#
# #!/bin/bash
#
# # Mandatory repo/branch conf
# export REPO=https://github.com/PathwayCommons/factoid.git
# export BRANCH=master
# export JOB_NAME=factoid-master
#
# # Project-specific env vars
# export PORT=3000
#
# ./ci.sh
echo "--"
echo "Starting $JOB_NAME build on"
date
WORKSPACE=/home/`whoami`/$JOB_NAME
WORKSPACE_TMP=/tmp/$JOB_NAME
rm -rf $WORKSPACE_TMP
mkdir -p $WORKSPACE_TMP
cd $WORKSPACE_TMP
# get the repo
git clone $REPO $WORKSPACE_TMP
git checkout $BRANCH
# build
npm install
npm run clean || echo "No clean script found"
export NODE_ENV=production
npm run build || echo "No build script found"
if [ $COMMAND ]
then
npm run $COMMAND
fi
# stop the old screen session
echo "Quitting old screen session..."
screen -S $JOB_NAME -X -p 0 stuff ^C && echo "Sent ^C" || echo "No screen session to ^C"
screen -S $JOB_NAME -X quit && echo "Quit old screen session" || echo "No screen session to stop"
#echo "Waiting a bit to let the old app exit..."
#sleep 30
# swap out old workspace with new one
echo "Replacing workspace..."
mkdir -p /tmp/rm
mv $WORKSPACE /tmp/rm/$JOB_NAME && echo "Moved old workspace to /tmp/rm" || echo "No old workspace to move"
mv $WORKSPACE_TMP $WORKSPACE
cd $WORKSPACE
echo "Replaced workspace"
# start the server in a screen session
echo "Starting new screen session..."
screen -d -m -S $JOB_NAME bash -c "npm run ${START_SCRIPT:-start} 2>&1 | tee ~/$JOB_NAME.screen.log"
echo "New screen session started"
# delete the old workspace files
echo "Deleting old workspace..."
rm -rf /tmp/rm/$JOB_NAME && echo "Old workspace deleted" || echo "No old workspace to delete"
echo "CI script complete"