-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.php
72 lines (55 loc) · 1.63 KB
/
deploy.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
<?php
namespace Deployer;
require 'recipe/laravel.php';
require 'contrib/npm.php';
// Config
set('repository', '[email protected]:nicklasos/tquiz.git');
add('shared_files', ['public/sitemap.xml']);
add('shared_dirs', []);
add('writable_dirs', []);
// Tasks
task('deploy', [
'deploy:prepare',
'deploy:vendors',
'artisan:storage:link',
'artisan:optimize:clear',
'artisan:migrate',
'deploy:php:reload',
'npm:install',
'npm:build',
'deploy:publish',
]);
desc('Build assets');
task('npm:build', function () {
run("cd {{release_path}} && {{bin/npm}} run build");
});
desc('Restart php-fpm service');
task('deploy:php:reload', function () {
run('for s in $( service --status-all | grep -o "\bphp.*fpm\b" ); do sudo service $s reload; done');
});
desc('Terminate horizon');
task('artisan:horizon:terminate', artisan('horizon:terminate'));
desc('Terminate horizon');
task('horizon:terminate', function () {
run('cd {{release_or_current_path}} && sudo {{bin/php}} artisan horizon:terminate');
});
try {
$env = explode("\n", file_get_contents(__DIR__.'/.env'));
$ipLine = array_values(array_filter($env, fn(string $line) => str_contains($line, 'DEPLOY_IP')))[0];
$ip = explode('=', str_replace(['"', "'"], '', $ipLine))[1];
} catch (\Exception) {
echo "Add DEPLOY_IP=0.0.0.0 to .env file\n";
exit(1);
}
// Hosts
host('prod')
->setHostname($ip)
->setLabels([
'env' => 'prod',
])
->setIdentityFile('~/.ssh/id_rsa')
->set('branch', 'main')
->set('remote_user', 'root')
->set('deploy_path', '/var/www/untrivial');
// Hooks
after('deploy:failed', 'deploy:unlock');