-
Notifications
You must be signed in to change notification settings - Fork 0
/
Envoy.blade.php
134 lines (103 loc) · 3.47 KB
/
Envoy.blade.php
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
@include('vendor/autoload.php')
@setup
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__, 'envoy');
try {
$dotenv->load();
$dotenv->required([
'TARGET_SERVER', 'TARGET_USER', 'TARGET_DIR',
'REPOSITORY',
'APP_NAME', 'APP_ENV', 'APP_DEBUG', 'APP_URL',
])->notEmpty();
} catch(Exception $e) {
echo "Something went wrong:\n\n";
echo "{$e->getMessage()} \n\n";
exit;
}
$server = $_ENV['TARGET_SERVER'];
$user = $_ENV['TARGET_USER'];
$dir = $_ENV['TARGET_DIR'];
$repository = $_ENV['REPOSITORY'];
$branch = $branch ?? 'main';
$app_name = $_ENV['APP_NAME'];
$app_env = $_ENV['APP_ENV'];
$app_debug = $_ENV['APP_DEBUG'];
$app_url = $_ENV['APP_URL'];
$destination = (new DateTime)->format('YmdHis');
$symlink = 'current';
@endsetup
@servers(['web' => "$user@$server"])
@task('deploy', ['confirm' => true])
echo "=> Install {{ $app_name }} into ~/{{ $dir }}/ at {{ $user }}"@"{{ $server }}..."
echo "Check ~/{{ $dir }}/"
if [ ! -d {{ $dir }} ]; then
mkdir -p {{ $dir }}
fi
cd {{ $dir }}
echo "Define variables"
export URL=`wget -qO- https://api.github.com/repos/CESNET/mfa/releases/latest | grep browser_download_url |
cut -d'"' -f4`
export FILE=`basename $URL`
export DIR=${FILE%.tar.gz}
echo "Download source code"
wget -q $URL
echo "Extract source code"
tar -xzf $FILE
echo "Backup existing ~/{{ $dir }}/.env"
if [ -f .env ]; then
mv .env .env-$DIR.bak
fi
echo "Prepare new ~/{{ $dir }}/.env"
if [ ! -f .env ]; then
cp $DIR/.env.example .env
fi
echo "Update ~/{{ $dir }}/.env"
sed -i "s%APP_NAME=.*%APP_NAME={{ $app_name }}%; \
s%APP_ENV=.*%APP_ENV={{ $app_env }}%; \
s%APP_DEBUG=.*%APP_DEBUG={{ $app_debug }}%; \
s%APP_URL=.*%APP_URL={{ $app_url }}%" .env
echo "Symlink ~/{{ $dir }}/.env"
ln -s ../.env ~/{{ $dir }}/$DIR/.env
echo "Check ~/{{ $dir }}/storage/ and fix permissions if necessary"
if [ ! -d storage ]; then
mv $DIR/storage .
setfacl -Rm g:www-data:rwx,d:g:www-data:rwx storage
else
rm -rf $DIR/storage
fi
echo "Fix permissions to ~/{{ $dir }}/bootstrap/cache"
setfacl -Rm g:www-data:rwx,d:g:www-data:rwx ~/{{ $dir }}/$DIR/bootstrap/cache
echo "Symlink ~/{{ $dir }}/storage/"
ln -s ../storage $DIR/storage
echo "Unlink ~/{{ $dir }}/{{ $symlink }}"
if [ -h {{ $symlink }} ]; then
rm {{ $symlink }}
fi
echo "Symlink ~/{{ $dir }}/$DIR to ~/{{ $dir }}/{{ $symlink }}"
ln -s $DIR {{ $symlink }}
echo "Install composer dependencies"
cd current
composer install -q --no-dev --optimize-autoloader --no-ansi --no-interaction --no-progress --prefer-dist
cd ..
echo "Generate key"
if [ `grep '^APP_KEY=' .env | grep 'base64:' | wc -l` -eq 0 ]; then
cd current
php artisan key:generate -q --no-ansi --no-interaction
cd ..
fi
cd $DIR
echo "Optimize"
php artisan optimize:clear -q --no-ansi --no-interaction
echo "Cache config"
php artisan config:cache -q --no-ansi --no-interaction
echo "Cache routes"
php artisan route:cache -q --no-ansi --no-interaction
echo "Cache views"
php artisan view:cache -q --no-ansi --no-interaction
echo "Reload PHP-FPM"
sudo systemctl reload php8.3-fpm
@endtask
@task('cleanup')
cd {{ $dir }}
find . -maxdepth 1 -name "mfa*" | sort | head -n -6 | xargs rm -rf
echo "Cleaned up all but the last 3 deployments."
@endtask