-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·43 lines (34 loc) · 1 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
#!/bin/sh -eu
# composer requires HOME to be available in environment.
export HOME="/home/$(whoami)"
PATH="$HOME/bin:$PATH"
PHP="/usr/bin/php"
COMPOSER="$PHP $HOME/bin/composer --working-dir=$PWD"
DIR="$(cd "$(dirname "$0")" && pwd)"
REQUEST_PATH="$DIR/var/deploy.request"
LOCK_PATH="$DIR/var/deploy.lock"
if [ ! -f "$REQUEST_PATH" ]; then
# If no request has been made, take no action. This is not an error.
exit 0
fi
if [ -f "$LOCK_PATH" ]; then
echo "Deployment is locked. Remove file ${LOCK_PATH} to release the lock."
exit 1
fi
echo "Deployment started at [$(date)]"
(
flock -x -n 9
# Commands to run
echo "Deployment runs git-pull at [$(date)]"
git pull
echo "Deployment runs 'composer install' at [$(date)]"
$COMPOSER install
echo "Deployment runs 'npm ci' at [$(date)]"
npm ci
echo "Deployment runs 'npm run build' at [$(date)]"
npm run build
) 9>"$LOCK_PATH"
rm -f "$LOCK_PATH"
rm -f "$REQUEST_PATH"
echo "'Deployment finished at ['$(date)'].'"
exit 0