-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
59 lines (41 loc) · 1.32 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
# --------------------
# / Config /
# --------------------
PROJECT_PATH=[PATH_IN_SERVER_TO_YOUR_PROJECT]
SSH_REPOSITORY=[SSH_CLONE_URL_FOR_YOUR_REPOSITORY]
# --------------------
# / Deployment /
# --------------------
RELEASES_PATH=$PROJECT_PATH/releases
NEW_RELEASE_PATH=$RELEASES_PATH/$(date +%Y%m%d%H%M%S)
ENV_PATH=$PROJECT_PATH/.env
STORAGE_PATH=$PROJECT_PATH/storage
RELEASES_KEPT=3
printf "\n\nCloning Repository\n\n"
git clone $SSH_REPOSITORY $NEW_RELEASE_PATH
cd $NEW_RELEASE_PATH
printf "\n\nInstalling Composer dependences\n\n"
composer install --no-interaction --prefer-dist --optimize-autoloader
printf "\n\nBuilding Assets (Yarn)\n\n"
yarn install
yarn production
printf "\n\nRunning PHPUnit\n\n"
./vendor/bin/phpunit
printf "\n\nSymlinking .env and storage\n\n"
ln -s $ENV_PATH .env
rm -rf storage
ln -sn $STORAGE_PATH storage
if [ -f artisan ]; then
printf "\n\nRestarting Queue\n\n"
php artisan queue:restart
printf "\n\nRunning migrations\n\n"
php artisan migrate --force
fi
cd $PROJECT_PATH
printf "\n\nActivating new release\n\n"
ln -sfn $NEW_RELEASE_PATH current
( flock -w 10 9 || exit 1
printf "Restarting FPM..."; sudo -S service php7.4-fpm reload ) 9>/tmp/fpmlock
cd $RELEASES_PATH
printf "\n\nPurging old releases"
rm -rf `ls -1 | sort -r | tail -n +$(($RELEASES_KEPT+1))`