-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
80 lines (66 loc) · 2.18 KB
/
Copy pathdeploy.sh
File metadata and controls
80 lines (66 loc) · 2.18 KB
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
79
80
#!/usr/bin/env bash
# Deployment with zero downtime
# By default keeps 2 last deployments in KEEP_DEPLOYMENTS_DIR and current deployment
# Project domain
PROJECT_NAME=lynxmasters.com
# Project directory
PROJECT_DIR=/home/lynxmasters/lynxmasters.com
# Deployments directory
KEEP_DEPLOYMENTS_DIR=/home/lynxmasters/deployment_history
KEEP_DEPLOYMENTS=2
DEPLOY_DIR_NAME=$(date +'%d%m%Y_%H%M%S')
DEPLOY_DIR_PROJECT=${KEEP_DEPLOYMENTS_DIR}/${PROJECT_NAME}
DEPLOY_DIR=${DEPLOY_DIR_PROJECT}/${DEPLOY_DIR_NAME}
echo "Initialize deployment directory '"${DEPLOY_DIR}"'"
[ -d ${DEPLOY_DIR} ] || mkdir -p ${DEPLOY_DIR}
echo "Copying '"${PROJECT_DIR}/"' to '"${DEPLOY_DIR}"'"
rsync -a $PROJECT_DIR/ $DEPLOY_DIR
echo "Execute commands in deployment directory"
cd ${DEPLOY_DIR}
# Application Build
echo "Building Lynxmasters.com....."
echo "Create temporary image folder"
mkdir ./tmp
echo "Backing up Uploads"
cp -r ./lynxmasters-ui/dist/static/uploads ./tmp
cd lynxmasters-ui
echo "Pulling latest UI changes...."
git pull
echo "Building Lynxmasters UI...."
npm install --production
npm run build
cd ..
echo "Put images back"
cp -r ./tmp/. ./lynxmasters-ui/dist/static/
rm -r ./tmp
echo "Checking for SendGrid env...."
if [ ! -f ./lynxmasters-api/config/sendgrid.env ];
then
echo "SendGrid API keys not found!"
echo "Copying SendGrid env to config directory"
cp sendgrid.env ./lynxmasters-api/config/
else
echo "SendGrid env exists."
echo "Stepping into API directory...."
fi
cd lynxmasters-api
echo "Pulling latest API changes...."
git pull
echo "Building API"
cp PROD.env .env
npm install --production
echo "Starting API"
forever stopall
forever start ./bin/www
# Atomic, zero downtime
echo "Update symlink '"${DEPLOY_DIR}"' to '"${PROJECT_DIR}.tmp"'"
ln -s $DEPLOY_DIR ${PROJECT_DIR}.tmp
# Remove current project directory if not symlink
if [ ! -h $PROJECT_DIR ]; then
rm -rf $PROJECT_DIR
fi
echo "Update symlink '"${DEPLOY_DIR}.tmp"' to '"${PROJECT_DIR}"'"
mv -Tf $PROJECT_DIR.tmp $PROJECT_DIR
echo "Clear old deployments in '"${DEPLOY_DIR_PROJECT}" keep last '"${KEEP_DEPLOYMENTS}"'"
cd ${DEPLOY_DIR_PROJECT}
rm -rf $(ls ${DEPLOY_DIR_PROJECT} -t | grep -v ${DEPLOY_DIR_NAME} | tail -n +$((KEEP_DEPLOYMENTS+1)))