forked from rrze-mmz/Tides
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Envoy.blade.php
169 lines (129 loc) · 4.22 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
@setup
require __DIR__.'/vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
try {
$dotenv->load();
$dotenv->required(['DEPLOY_USER', 'DEPLOY_GROUP','DEPLOY_SERVER', 'DEPLOY_BASE_DIR', 'DEPLOY_REPO'])->notEmpty();
} catch ( Exception $e ) {
echo $e->getMessage();
}
$user = env('DEPLOY_USER');
$group = env('DEPLOY_GROUP');
$repo = env('DEPLOY_REPO');
$branch = env('DEPLOY_BRANCH');
if (!isset($baseDir)) {
$baseDir = env('DEPLOY_BASE_DIR');
}
if (!isset($branch)) {
$branch = 'main';
}
$releaseDir = $baseDir . '/releases';
$currentDir = $baseDir . '/current';
$release = date('YmdHis');
$currentReleaseDir = $releaseDir . '/' . $release;
function logMessage($message) {
return "echo '\033[32m" .$message. "\033[0m';\n";
}
@endsetup
@servers(['development' => env('DEPLOY_USER').'@'.env('DEPLOY_SERVER')])
@story('deploy-on-dev',['on'=>'development'])
git-develop
composer
npm_install
npm_run_prod
update_symlinks
clear-optimizer
rebuild-cache
fix-broken-links
clean_old_releases
{{--set_permissions--}}
@endstory
@task('git-develop')
{{ logMessage("Cloning repository in {$branch} branch") }}
git clone {{ $repo }} --branch={{ $branch }} --depth=1 -q {{ $currentReleaseDir }}
@endtask
@task('composer')
{{ logMessage("Running composer") }}
cd {{ $currentReleaseDir }}
~/composer.phar install --quiet --no-interaction --no-dev --prefer-dist --optimize-autoloader --ignore-platform-reqs
@endtask
@task('npm_install')
{{ logMessage("NPM install") }}
cd {{ $currentReleaseDir }}
npm install --silent --no-progress > /dev/null
@endtask
@task('npm_run_prod')
{{ logMessage("NPM run prod") }}
cd {{ $currentReleaseDir }}
npm run build --silent --no-progress > /dev/null
{{ logMessage("Deleting node_modules folder") }}
rm -rf node_modules
@endtask
@task('update_symlinks')
{{ logMessage("Updating symlinks") }}
# Remove the storage directory and replace with persistent data
{{ logMessage("Linking storage directory") }}
rm -rf {{ $currentReleaseDir }}/storage;
cd {{ $currentReleaseDir }};
ln -nfs {{ $baseDir }}/storage {{ $currentReleaseDir }}/storage;
ln -nfs {{ $baseDir }}/storage/app/public {{ $currentReleaseDir }}/public/storage
# Remove the public uploads directory and replace with persistent data
# {{ logMessage("Linking uploads directory") }}
# rm -rf {{ $currentReleaseDir }}/public/uploads
# cd {{ $currentReleaseDir }}/public
# ln -nfs {{ $baseDir }}/uploads {{ $currentReleaseDir }}/uploads;
# Import the environment config
{{ logMessage("Linking .env file") }}
cd {{ $currentReleaseDir }};
ln -nfs {{ $baseDir }}/.env .env;
# Symlink the latest release to the current directory
{{ logMessage("Linking current release") }}
ln -nfs {{ $currentReleaseDir }} {{ $currentDir }};
@endtask
@task('set_permissions')
# Set dir permissions
{{ logMessage("Set permissions") }}
sudo chown -R {{ $user }}:{{ $group }} {{ $baseDir }}
sudo chmod -R ug+rwx {{ $baseDir }}/storage
cd {{ $baseDir }}
sudo chown -R {{ $user }}:{{ $group }} current
sudo chmod -R ug+rwx current/storage current/bootstrap/cache
sudo chown -R {{ $user }}:{{ $group }} {{ $currentReleaseDir }}
@endtask
@task('reload_services', ['on' => 'prod'])
# Reload Services
{{ logMessage("Restarting service supervisor") }}
sudo supervisorctl restart all
{{ logMessage("Reloading php") }}
sudo systemctl reload php7.3-fpm
@endtask
@story('clear-cache')
clear-optimizer
rebuild-cache
@endstory
@task('clear-optimizer',['on'=>'development'])
{{ logMessage("Clearing optimizer") }}
php {{ $currentDir }}/artisan optimize:clear
@endtask
@task('rebuild-cache',['on'=>'development'])
{{ logMessage("Starting rebuilding cache...") }}
php {{ $currentDir }}/artisan view:cache
php {{ $currentDir }}/artisan route:cache
php {{ $currentDir }}/artisan config:cache
php {{ $currentDir }}/artisan icons:cache
@endtask
@task('fix-broken-links',['on'=>'development'])
cd {{ $currentReleaseDir }};
rm {{ $currentDir }}/public/links
rm {{ $currentDir }}/public/documents
php {{ $currentDir }}/artisan storage:link
@endtask
@task('clean_old_releases')
# Delete all but the 5 most recent releases
{{ logMessage("Cleaning old releases") }}
cd {{ $releaseDir }}
ls -dt {{ $releaseDir }}/* | tail -n +6 | xargs -d "\n" rm -rf;
@endtask
@finished
echo "Envoy deployment script finished.\r\n";
@endfinished