-
Notifications
You must be signed in to change notification settings - Fork 62
/
deploy.sh
90 lines (75 loc) · 1.89 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
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
81
82
83
84
85
86
87
88
89
#!/bin/bash
function printAction {
if [ "$DBG" != 1 ]; then
let DOTS=50-${#1}
echo -n "$1 " >&2
printf '%0.s.' $(seq ${DOTS}) >&2
echo -n " " >&2
fi
}
function printOk {
if [ "$DBG" != 1 ]; then
echo -e "\033[32mOK\033[0m" >&2
fi
}
Q='-q'
if [ "$DBG" = 1 ]; then
set -x # xtrace: print commands
Q=''
else
exec > /dev/null
fi
set -e # errexit: exit on error
PROJECT_HOME=/var/www/secretsantaorganizer.com
VERSION=`date +"%Y%m%d%H%M%S"`
cd ${PROJECT_HOME}
printAction "Get latest version from Git"
cd git
git pull ${Q} origin master
cd ..
printOk
printAction "Install latest version"
cp -R git releases/${VERSION}
cd releases/${VERSION}
cp ../../shared/env.local .env
cp ../../shared/client_secrets.json config
cp ../../shared/recaptcha_secrets.json config
printOk
printAction "Composer install"
../../shared/composer.phar install --no-dev --classmap-authoritative ${Q} 2>&1
../../shared/composer.phar dump-env prod ${Q} 2>&1
rm .env
printOk
printAction "Building frontend"
yarn 2>&1 && yarn build
printOk
printAction "Install assets"
cp ../../shared/yandex_* public
cp ../../shared/ads.txt public
cp ../../shared/GeoLite2-City.mmdb public
printOk
printAction "Cleanup files and setting permissions"
rm -rf .git .gitignore Vagrantfile shell_provisioner
rm -rf public/index_test.php
chmod -R ug=rwX,o=rX ../${VERSION}
chmod -R a+rwX var/log var/cache
printOk
printAction "Stopping FPM"
sudo systemctl stop php8.3-fpm
printOk
#printAction "Running doctrine schema update"
#bin/console doctrine:schema:update --force ${Q}
cd ../..
#printOk
printAction "Activate new version"
ln -sfn releases/${VERSION} current
printOk
printAction "Starting FPM"
sudo systemctl start php8.3-fpm
printOk
printAction "Cleanup old versions, keep last 2"
cd releases
ls -1 | sort -r | tail -n +3 | xargs rm -rf
cd ..
printOk
echo SecretSanta version ${VERSION} is deployed! >&2